@@ -163,8 +163,40 @@ runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() {
163
163
} ) ;
164
164
} ) ;
165
165
166
-
167
166
process . on ( 'exit' , function ( ) {
168
- console . log ( 'Tests run / ok:' , tests_run , '/' , tests_ok ) ;
169
167
assert . strictEqual ( tests_ok , tests_run ) ;
170
168
} ) ;
169
+
170
+
171
+ // Ref: https://github.com/nodejs/node/issues/13255
172
+ common . refreshTmpDir ( ) ;
173
+ const path = `${ common . tmpDir } /test-utimes-precision` ;
174
+ fs . writeFileSync ( path , '' ) ;
175
+
176
+ // test Y2K38 for all platforms [except 'arm', and 'SunOS']
177
+ if ( ! process . arch . includes ( 'arm' ) && ! common . isSunOS ) {
178
+ // because 2 ** 31 doesn't look right
179
+ // eslint-disable-next-line space-infix-ops
180
+ const Y2K38_mtime = 2 ** 31 ;
181
+ fs . utimesSync ( path , Y2K38_mtime , Y2K38_mtime ) ;
182
+ const Y2K38_stats = fs . statSync ( path ) ;
183
+ assert . strictEqual ( Y2K38_mtime , Y2K38_stats . mtime . getTime ( ) / 1000 ) ;
184
+ }
185
+
186
+ if ( common . isWindows ) {
187
+ // this value would get converted to (double)1713037251359.9998
188
+ const truncate_mtime = 1713037251360 ;
189
+ fs . utimesSync ( path , truncate_mtime / 1000 , truncate_mtime / 1000 ) ;
190
+ const truncate_stats = fs . statSync ( path ) ;
191
+ assert . strictEqual ( truncate_mtime , truncate_stats . mtime . getTime ( ) ) ;
192
+
193
+ // test Y2K38 for windows
194
+ // This value if treaded as a `signed long` gets converted to -2135622133469.
195
+ // POSIX systems stores timestamps in {long t_sec, long t_usec}.
196
+ // NTFS stores times in nanoseconds in a single `uint64_t`, so when libuv
197
+ // calculates (long)`uv_timespec_t.tv_sec` we get 2's complement.
198
+ const overflow_mtime = 2159345162531 ;
199
+ fs . utimesSync ( path , overflow_mtime / 1000 , overflow_mtime / 1000 ) ;
200
+ const overflow_stats = fs . statSync ( path ) ;
201
+ assert . strictEqual ( overflow_mtime , overflow_stats . mtime . getTime ( ) ) ;
202
+ }
0 commit comments