This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from paulmach/time-utc
time marshals to iso8601 utc
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package osm | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestTimeOSMString(t *testing.T) { | ||
newYork, err := time.LoadLocation("America/New_York") | ||
if err != nil { | ||
t.Fatalf("invalid timezone: %v", err) | ||
} | ||
|
||
cases := []struct { | ||
name string | ||
time time.Time | ||
expected string | ||
}{ | ||
{ | ||
name: "iso 8601 format", | ||
time: time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), | ||
expected: "2012-01-01T00:00:00Z", | ||
}, | ||
{ | ||
name: "always UTC", | ||
time: time.Date(2012, 1, 1, 0, 0, 0, 0, newYork), | ||
expected: "2012-01-01T05:00:00Z", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tosm := TimeOSM(tc.time) | ||
if v := tosm.String(); v != tc.expected { | ||
t.Errorf("incorrect format: %v", v) | ||
} | ||
}) | ||
} | ||
} |