Skip to content
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

Incorrect time formatting #302

Closed
jspri opened this issue May 31, 2021 · 0 comments · Fixed by #307
Closed

Incorrect time formatting #302

jspri opened this issue May 31, 2021 · 0 comments · Fixed by #307

Comments

@jspri
Copy link

jspri commented May 31, 2021

FormatDateTime is unsafe!

It uses the formatting string dateTimeFormat = "2006-01-02T15:04:05.99Z" which essentially just appends the Z character onto the user's local time.

Possible fixes:

  • Swap the format string to "2006-01-02T15:04:05.99Z07:00" or maybe even time.RFC3339 (probably breaking)
  • Explicitly cast to UTC time (maybe breaking - but probably just bug fixing)
func FormatDateTime(value time.Time) string {
      return value.UTC().Format(dateTimeFormat)
 }
  • Document that the function should be called with a UTC time (probably too conservative)

Not sure what your original intentions were so I'll leave this to you.

I originally found this after spending an hour or so debugging why calls to cloudwatch.GetMetricData weren't returning any data in the v2 aws SDK.

jasdel added a commit that referenced this issue Jun 16, 2021
Updates the parsing of HTTPDate and DateTime time formats to not be as
strict, and allow more variants of the time format. Including UTC
offsets for DateTime.

Fixes #302 by changing time to UTC before formatting so no local offset time is lost.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant