Skip to content

fix: strip timezone information from a date in dau response #11962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: timezone offset should be flipped
  • Loading branch information
Emyrk committed Jan 31, 2024
commit dab4394e1d14e64b0e0364628a1f49091ebccab0
8 changes: 6 additions & 2 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2186,14 +2186,18 @@ func (d DAURequest) asRequestOption() RequestOption {
}
}

// TimezoneOffsetHour 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()'
func TimezoneOffsetHour(loc *time.Location) int {
if loc == nil {
// Default to UTC time to be consistent across all callers.
loc = time.UTC
}
_, offsetSec := time.Now().In(loc).Zone()
// Convert to hours
return offsetSec / 60 / 60
// Convert to hours and flip the sign
return -1 * offsetSec / 60 / 60
}

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