|
| 1 | +package p_time |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + "time" |
| 6 | +) |
| 7 | + |
| 8 | +const expectedCET = "CET-1CEST,M3.5.0/2,M10.5.0/3" |
| 9 | +const expectedEST = "EST5EDT,M3.2.0/2,M11.1.0" |
| 10 | +const zagrebZone = "Europe/Zagreb" |
| 11 | +const newyorkZone = "America/New_York" |
| 12 | + |
| 13 | +func TestFormatTimeZoneCET(t *testing.T) { |
| 14 | + loc, _ := time.LoadLocation(zagrebZone) |
| 15 | + testTime := time.Date(2022, 4, 12, 0, 0, 0, 0, loc) |
| 16 | + formatted := FormatTimeZone(testTime) |
| 17 | + if formatted != expectedCET { |
| 18 | + t.Fatalf("Time zone string for test time %s is not correct. Expected %s but got %s", testTime, expectedCET, formatted) |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +func TestFormatTimeZoneCETDSTFirst(t *testing.T) { |
| 23 | + loc, _ := time.LoadLocation(zagrebZone) |
| 24 | + testTime := time.Date(2022, 7, 12, 0, 0, 0, 0, loc) |
| 25 | + formatted := FormatTimeZone(testTime) |
| 26 | + if formatted != expectedCET { |
| 27 | + t.Fatalf("Time zone string for test time %s is not correct. Expected %s but got %s", testTime, expectedCET, formatted) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestFormatTimeZoneEST(t *testing.T) { |
| 32 | + loc, _ := time.LoadLocation(newyorkZone) |
| 33 | + testTime := time.Date(2022, 4, 12, 0, 0, 0, 0, loc) |
| 34 | + formatted := FormatTimeZone(testTime) |
| 35 | + if formatted != expectedEST { |
| 36 | + t.Fatalf("Time zone string for test time %s is not correct. Expected %s but got %s", testTime, expectedEST, formatted) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func TestFormatTimeZoneESTDSTFirst(t *testing.T) { |
| 41 | + loc, _ := time.LoadLocation(newyorkZone) |
| 42 | + testTime := time.Date(2022, 7, 12, 0, 0, 0, 0, loc) |
| 43 | + formatted := FormatTimeZone(testTime) |
| 44 | + if formatted != expectedEST { |
| 45 | + t.Fatalf("Time zone string for test time %s is not correct. Expected %s but got %s", testTime, expectedEST, formatted) |
| 46 | + } |
| 47 | +} |
0 commit comments