Skip to content

Instantly share code, notes, and snippets.

@matejb
Created May 8, 2018 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matejb/fa7195b5bf37014fe2a98f14d3aef7b6 to your computer and use it in GitHub Desktop.
Save matejb/fa7195b5bf37014fe2a98f14d3aef7b6 to your computer and use it in GitHub Desktop.
// normalizeLocalTime will normalize local time expressed in number of seconds
// from UNIX Epoch but not in UTC but counted in local location to the one
// counted correctly from UTC location.
func normalizeLocalTime(localNumOfSeconds int64, location *time.Location) time.Time {
t := time.Unix(localNumOfSeconds, 0).In(location)
_, offset := t.Zone()
// we apply offset in reverse to correct time
return t.Add(-1 * time.Duration(offset) * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment