(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func TestCalculateAutoStop(t *testing.T) { |
| 24 | t.Parallel() |
| 25 | |
| 26 | now := time.Now() |
| 27 | |
| 28 | chicago, err := time.LoadLocation("America/Chicago") |
| 29 | require.NoError(t, err, "loading chicago time location") |
| 30 | |
| 31 | // pastDateNight is 9:45pm on a wednesday |
| 32 | pastDateNight := time.Date(2024, 2, 14, 21, 45, 0, 0, chicago) |
| 33 | |
| 34 | // Wednesday the 8th of February 2023 at midnight. This date was |
| 35 | // specifically chosen as it doesn't fall on a applicable week for both |
| 36 | // fortnightly and triweekly autostop requirements. |
| 37 | wednesdayMidnightUTC := time.Date(2023, 2, 8, 0, 0, 0, 0, time.UTC) |
| 38 | |
| 39 | sydneyQuietHours := "CRON_TZ=Australia/Sydney 0 0 * * *" |
| 40 | sydneyLoc, err := time.LoadLocation("Australia/Sydney") |
| 41 | require.NoError(t, err) |
| 42 | // 10pm on Friday the 10th of February 2023 in Sydney. |
| 43 | fridayEveningSydney := time.Date(2023, 2, 10, 22, 0, 0, 0, sydneyLoc) |
| 44 | // 12am on Saturday the 11th of February2023 in Sydney. |
| 45 | saturdayMidnightSydney := time.Date(2023, 2, 11, 0, 0, 0, 0, sydneyLoc) |
| 46 | |
| 47 | t.Log("now", now) |
| 48 | t.Log("wednesdayMidnightUTC", wednesdayMidnightUTC) |
| 49 | t.Log("fridayEveningSydney", fridayEveningSydney) |
| 50 | t.Log("saturdayMidnightSydney", saturdayMidnightSydney) |
| 51 | |
| 52 | dstIn := time.Date(2023, 10, 1, 2, 0, 0, 0, sydneyLoc) // 1 hour backward |
| 53 | dstInQuietHours := "CRON_TZ=Australia/Sydney 30 2 * * *" // never |
| 54 | // The expected behavior is that we will pick the next time that falls on |
| 55 | // quiet hours after the DST transition. In this case, it will be the same |
| 56 | // time the next day. |
| 57 | dstInQuietHoursExpectedTime := time.Date(2023, 10, 2, 2, 30, 0, 0, sydneyLoc) |
| 58 | beforeDstIn := time.Date(2023, 10, 1, 0, 0, 0, 0, sydneyLoc) |
| 59 | saturdayMidnightAfterDstIn := time.Date(2023, 10, 7, 0, 0, 0, 0, sydneyLoc) |
| 60 | |
| 61 | // Wednesday after DST starts. |
| 62 | duringDst := time.Date(2023, 10, 4, 0, 0, 0, 0, sydneyLoc) |
| 63 | saturdayMidnightAfterDuringDst := saturdayMidnightAfterDstIn |
| 64 | |
| 65 | dstOut := time.Date(2024, 4, 7, 3, 0, 0, 0, sydneyLoc) // 1 hour forward |
| 66 | dstOutQuietHours := "CRON_TZ=Australia/Sydney 30 3 * * *" // twice |
| 67 | dstOutQuietHoursExpectedTime := time.Date(2024, 4, 7, 3, 30, 0, 0, sydneyLoc) // in reality, this is the first occurrence |
| 68 | beforeDstOut := time.Date(2024, 4, 7, 0, 0, 0, 0, sydneyLoc) |
| 69 | saturdayMidnightAfterDstOut := time.Date(2024, 4, 13, 0, 0, 0, 0, sydneyLoc) |
| 70 | |
| 71 | t.Log("dstIn", dstIn) |
| 72 | t.Log("beforeDstIn", beforeDstIn) |
| 73 | t.Log("saturdayMidnightAfterDstIn", saturdayMidnightAfterDstIn) |
| 74 | t.Log("dstOut", dstOut) |
| 75 | t.Log("beforeDstOut", beforeDstOut) |
| 76 | t.Log("saturdayMidnightAfterDstOut", saturdayMidnightAfterDstOut) |
| 77 | |
| 78 | cases := []struct { |
| 79 | name string |
| 80 | buildCompletedAt time.Time |
nothing calls this directly
no test coverage detected