@@ -5,6 +5,7 @@ const { writeFile, rm, stat, readlink, symlink } = require('fs/promises')
5
5
const { join } = require ( 'path' )
6
6
const { test } = require ( 'tap' )
7
7
const { format } = require ( 'date-fns' )
8
+ const MockDate = require ( 'mockdate' )
8
9
9
10
const {
10
11
buildFileName,
@@ -69,6 +70,66 @@ test('getNext()', async ({ same }) => {
69
70
same ( getNext ( custom ) , Date . now ( ) + custom , 'supports custom frequency and does not return start' )
70
71
} )
71
72
73
+ test ( 'getNext() on dates transitioning from DST to Standard Time' , async ( { same } ) => {
74
+ // on these days the time rolls back 1 hour so there "are" 25 hours in the day
75
+ // genNext() should account for variable number of hours in the day
76
+
77
+ // test two different timezones
78
+ const data = [
79
+ {
80
+ tz : 'Europe/Berlin' ,
81
+ mockDate : '27 Oct 2024 00:00:00 GMT+0100'
82
+ } ,
83
+ {
84
+ tz : 'America/New_York' ,
85
+ mockDate : '03 Nov 2024 00:00:00 GMT-0500'
86
+ }
87
+ ]
88
+
89
+ for ( const d of data ) {
90
+ MockDate . set ( d . mockDate )
91
+ process . env . TZ = d . tz
92
+ const today = new Date ( )
93
+
94
+ same ( getNext ( 'daily' ) , startOfDay ( addDays ( today , 1 ) ) . getTime ( ) , 'supports daily frequency' )
95
+ same ( getNext ( 'hourly' ) , startOfHour ( addHours ( today , 1 ) ) . getTime ( ) , 'supports hourly frequency' )
96
+ const custom = 3000
97
+ same ( getNext ( custom ) , Date . now ( ) + custom , 'supports custom frequency and does not return start' )
98
+ MockDate . reset ( )
99
+ process . env . TZ = undefined
100
+ }
101
+ } )
102
+
103
+ test ( 'getNext() on dates transitioning from Standard Time to DST' , async ( { same } ) => {
104
+ // on these days the time rolls forward 1 hour so there "are" 23 hours in the day
105
+ // genNext() should account for variable number of hours in the day
106
+
107
+ // test two different timezones
108
+ const data = [
109
+ {
110
+ tz : 'Europe/Berlin' ,
111
+ mockDate : '31 March 2024 01:00:00 GMT+0100'
112
+ } ,
113
+ {
114
+ tz : 'America/New_York' ,
115
+ mockDate : '10 Nov 2024 01:00:00 GMT-0500'
116
+ }
117
+ ]
118
+
119
+ for ( const d of data ) {
120
+ MockDate . set ( d . mockDate )
121
+ process . env . TZ = d . tz
122
+ const today = new Date ( )
123
+
124
+ same ( getNext ( 'daily' ) , startOfDay ( addDays ( today , 1 ) ) . getTime ( ) , 'supports daily frequency' )
125
+ same ( getNext ( 'hourly' ) , startOfHour ( addHours ( today , 1 ) ) . getTime ( ) , 'supports hourly frequency' )
126
+ const custom = 3000
127
+ same ( getNext ( custom ) , Date . now ( ) + custom , 'supports custom frequency and does not return start' )
128
+ MockDate . reset ( )
129
+ process . env . TZ = undefined
130
+ }
131
+ } )
132
+
72
133
test ( 'getFileName()' , async ( { equal, throws } ) => {
73
134
const strFunc = ( ) => 'my-func'
74
135
throws ( getFileName , 'throws on empty input' )
0 commit comments