Skip to content

Instantly share code, notes, and snippets.

@matejb
Created May 8, 2018 07:13
Show Gist options
  • Select an option

  • Save matejb/fa7195b5bf37014fe2a98f14d3aef7b6 to your computer and use it in GitHub Desktop.

Select an option

Save matejb/fa7195b5bf37014fe2a98f14d3aef7b6 to your computer and use it in GitHub Desktop.

Revisions

  1. matejb created this gist May 8, 2018.
    10 changes: 10 additions & 0 deletions normalizeLocalTime.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@

    // 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)
    }