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)
| 5251 | // The trivial case of times being on the same day is: |
| 5252 | // 'time.Now().UTC().Hour() - time.Now().In(loc).Hour()' |
| 5253 | func 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 | |
| 5263 | func TimezoneOffsetHour(loc *time.Location) int { |
| 5264 | return TimezoneOffsetHourWithTime(time.Now(), loc) |
no outgoing calls