-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package timeutils | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
var testData = []struct{ in, out string }{ | ||
{"2014-12-05 09:51:20.939152 -0500", "2014-12-05 14:51:20.939152 +0000 UTC"}, | ||
{"2014-12-05 09:51:20.939152 -0500 EST", "2014-12-05 14:51:20.939152 +0000 UTC"}, | ||
{"2014-12-05 09:51:20.939152", "2014-12-05 09:51:20.939152 +0000 UTC"}, | ||
{"2014/12/05 09:51:20.939152", "2014-12-05 09:51:20.939152 +0000 UTC"}, | ||
{"2014.12.05 09:51:20.939152", "2014-12-05 09:51:20.939152 +0000 UTC"}, | ||
{"09:51:20.939152 2014-31-12", "2014-12-31 09:51:20.939152 +0000 UTC"}, | ||
{"09:51:20.939152am 2014-31-12", "2014-12-31 09:51:20.939152 +0000 UTC"}, | ||
{"09:51:20.939152pm 2014-31-12", "2014-12-31 21:51:20.939152 +0000 UTC"}, | ||
} | ||
|
||
func TestParseDateString(t *testing.T) { | ||
defer os.Setenv("TZ", os.Getenv("TZ")) | ||
os.Setenv("TZ", "UTC") | ||
|
||
for i, elem := range testData { | ||
if tt, err := ParseDateString(elem.in); err != nil { | ||
t.Error(err) | ||
} else if elem.out != tt.String() { | ||
t.Errorf("[%d] Unexpected parsed time.\nExpect:\t%s\nGot:\t%s\n", i, elem.out, tt) | ||
} | ||
} | ||
} |