Skip to content

Commit dab4394

Browse files
committed
fix: timezone offset should be flipped
1 parent 033fd4e commit dab4394

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

codersdk/deployment.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,14 +2186,18 @@ func (d DAURequest) asRequestOption() RequestOption {
21862186
}
21872187
}
21882188

2189+
// TimezoneOffsetHour is implemented to match the javascript 'getTimezoneOffset()' function.
2190+
// This is the amount of time between this date evaluated in UTC and evaluated in the 'loc'
2191+
// The trivial case of times being on the same day is:
2192+
// 'time.Now().UTC().Hour() - time.Now().In(loc).Hour()'
21892193
func TimezoneOffsetHour(loc *time.Location) int {
21902194
if loc == nil {
21912195
// Default to UTC time to be consistent across all callers.
21922196
loc = time.UTC
21932197
}
21942198
_, offsetSec := time.Now().In(loc).Zone()
2195-
// Convert to hours
2196-
return offsetSec / 60 / 60
2199+
// Convert to hours and flip the sign
2200+
return -1 * offsetSec / 60 / 60
21972201
}
21982202

21992203
func (c *Client) DeploymentDAUsLocalTZ(ctx context.Context) (*DAUsResponse, error) {

0 commit comments

Comments
 (0)