MCPcopy Index your code
hub / github.com/coder/coder / TimezoneOffsetHourWithTime

Function TimezoneOffsetHourWithTime

codersdk/deployment.go:5253–5261  ·  view source on GitHub ↗

TimezoneOffsetHourWithTime is implemented to match the javascript 'getTimezoneOffset()' function. This is the amount of time between this date evaluated in UTC and evaluated in the 'loc' The trivial case of times being on the same day is: 'time.Now().UTC().Hour() - time.Now().In(loc).Hour()'

(now time.Time, loc *time.Location)

Source from the content-addressed store, hash-verified

5251// The trivial case of times being on the same day is:
5252// 'time.Now().UTC().Hour() - time.Now().In(loc).Hour()'
5253func TimezoneOffsetHourWithTime(now time.Time, loc *time.Location) int {
5254 if loc == nil {
5255 // Default to UTC time to be consistent across all callers.
5256 loc = time.UTC
5257 }
5258 _, offsetSec := now.In(loc).Zone()
5259 // Convert to hours and flip the sign
5260 return -1 * offsetSec / 60 / 60
5261}
5262
5263func TimezoneOffsetHour(loc *time.Location) int {
5264 return TimezoneOffsetHourWithTime(time.Now(), loc)

Callers 2

TestTimezoneOffsetsFunction · 0.92
TimezoneOffsetHourFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestTimezoneOffsetsFunction · 0.74