mirror of
https://github.com/acaloiaro/newsbox
synced 2026-07-21 10:12:26 +00:00
31 lines
800 B
Go
31 lines
800 B
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// TimeInZone returns the current time in the time zone represented as an offset from UTC
|
|
func TimeInZone(utcOffset int) time.Time {
|
|
loc := ZoneLocation(utcOffset)
|
|
t := time.Now()
|
|
|
|
return t.In(loc)
|
|
}
|
|
|
|
// ZoneName returns the name of the time zone represented as an offset from UTC
|
|
func ZoneName(utcOffset int) string {
|
|
direction := ""
|
|
if utcOffset >= 0 {
|
|
direction = "+"
|
|
}
|
|
|
|
return fmt.Sprintf("UTC%s%d", direction, utcOffset)
|
|
}
|
|
|
|
// ZoneLocation returns a Location that represents the time zone with the given offset from UTC
|
|
func ZoneLocation(utcOffset int) *time.Location {
|
|
// 60 * 60 are the number of minutes and seconds _east_ of UTC
|
|
// This number can be positive or negative
|
|
return time.FixedZone(ZoneName(utcOffset), utcOffset*60*60)
|
|
}
|