Comments (8)
Oh, thanks! That is very interesting, will have a look asap
from croner.
@EricRamirezS I can not reproduce this behavior. As a first step, i Increased default number of iterations in the test to 365 days, so that the test always includes first days of september.
Can you share details about your setup - such as time zone, Node version, actual test code, failing initial dates etc. to help me reproduce it
from croner.
@Hexagon Taking a deeper look at what's going on... It's definitely a regional issue.
The day causing problems is the first Sunday of the month of September between the 2nd and the 8th...
Why is this information relevant?
My country has "Daylight saving time"... that is the institution which puts time forward 1 hour for a certain period in summer.
As soon as the first Saturday of September ends, the clock fasts forward 1 hour... that is: as soon as it is Sunday at (00:00) 12:00 a.m., we set our watches one hour ahead to (01:00) 01:00 a.m.
Moving from UTC -4 to UTC-3
That Sunday has 23 hours for us.
The opposite happens on the first Saturday of April. As soon as the clock hits 12:00 a.m. on Sunday, we turn the clock back 1 hour, returning to Saturday at 11:00 p.m. (although the library is not skipping that day, just when it's fast-forwarded)
My setup
OS | Microsoft Windows 10 Home Single Language |
npm | 8.11.0 |
NodeJS | v16.16.0 |
IDE | WebStorm 2022.2 |
Timezone | America/Santiago |
Time Offset: | UTC -4 | UTC -3 (Daylight saving time) |
Powershell Version | 5.1.19041.1682 |
OS CurrentCulture | es-CL | Spanish-Chile |
OS CurrentUICulture | es-MX | Spanish-Mexico |
The source code without any modification fails to me.
This added test to check what's going on also fails
test("0 0 0 * * * with 1460 iterations should return 1460 days from Sun Aug 01 2021 08:00:00", function () {
let scheduler = new Cron("0 0 0 * * *"),
prevRun = new Date(1627804800000),
nextRun,
iterations = 1460,
compareDay = new Date(1627804800000);
compareDay.setDate(compareDay.getDate() + iterations);
let i = 1;
while(iterations-->0) {
nextRun = scheduler.next(prevRun);
console.log( i++ + ' - '+ nextRun);
prevRun = nextRun;
}
// Set seconds, minutes and hours to 00:00:00
compareDay.setMilliseconds(0);
compareDay.setSeconds(0);
compareDay.setMinutes(0);
compareDay.setHours(0);
console.log(nextRun, ' - ', compareDay)
// Do comparison
assert.equal(nextRun.getTime(),compareDay.getTime());
});
Output:
The most remarkable thing is how it rotates between Chilean standard time (hora estándar de Chile) and Chilean daylight saving time (hora de verano de Chile), and every time it makes the change to daylight saving time, it skips 1 full day.
PS D:\Development\WebStorm\cronerRaw> npm run test
> [email protected] test
> uvu test test.croner.js
node\js\test.croner.js
• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •
1 - Mon Aug 02 2021 00:00:00 GMT-0400 (hora estándar de Chile)
2 - Tue Aug 03 2021 00:00:00 GMT-0400 (hora estándar de Chile)
3 - Wed Aug 04 2021 00:00:00 GMT-0400 (hora estándar de Chile)
4 - Thu Aug 05 2021 00:00:00 GMT-0400 (hora estándar de Chile)
5 - Fri Aug 06 2021 00:00:00 GMT-0400 (hora estándar de Chile)
6 - Sat Aug 07 2021 00:00:00 GMT-0400 (hora estándar de Chile)
7 - Sun Aug 08 2021 00:00:00 GMT-0400 (hora estándar de Chile)
8 - Mon Aug 09 2021 00:00:00 GMT-0400 (hora estándar de Chile)
9 - Tue Aug 10 2021 00:00:00 GMT-0400 (hora estándar de Chile)
10 - Wed Aug 11 2021 00:00:00 GMT-0400 (hora estándar de Chile)
11 - Thu Aug 12 2021 00:00:00 GMT-0400 (hora estándar de Chile)
12 - Fri Aug 13 2021 00:00:00 GMT-0400 (hora estándar de Chile)
13 - Sat Aug 14 2021 00:00:00 GMT-0400 (hora estándar de Chile)
14 - Sun Aug 15 2021 00:00:00 GMT-0400 (hora estándar de Chile)
15 - Mon Aug 16 2021 00:00:00 GMT-0400 (hora estándar de Chile)
16 - Tue Aug 17 2021 00:00:00 GMT-0400 (hora estándar de Chile)
17 - Wed Aug 18 2021 00:00:00 GMT-0400 (hora estándar de Chile)
18 - Thu Aug 19 2021 00:00:00 GMT-0400 (hora estándar de Chile)
19 - Fri Aug 20 2021 00:00:00 GMT-0400 (hora estándar de Chile)
20 - Sat Aug 21 2021 00:00:00 GMT-0400 (hora estándar de Chile)
21 - Sun Aug 22 2021 00:00:00 GMT-0400 (hora estándar de Chile)
22 - Mon Aug 23 2021 00:00:00 GMT-0400 (hora estándar de Chile)
23 - Tue Aug 24 2021 00:00:00 GMT-0400 (hora estándar de Chile)
24 - Wed Aug 25 2021 00:00:00 GMT-0400 (hora estándar de Chile)
25 - Thu Aug 26 2021 00:00:00 GMT-0400 (hora estándar de Chile)
26 - Fri Aug 27 2021 00:00:00 GMT-0400 (hora estándar de Chile)
27 - Sat Aug 28 2021 00:00:00 GMT-0400 (hora estándar de Chile)
28 - Sun Aug 29 2021 00:00:00 GMT-0400 (hora estándar de Chile)
29 - Mon Aug 30 2021 00:00:00 GMT-0400 (hora estándar de Chile)
30 - Tue Aug 31 2021 00:00:00 GMT-0400 (hora estándar de Chile)
31 - Wed Sep 01 2021 00:00:00 GMT-0400 (hora estándar de Chile)
32 - Thu Sep 02 2021 00:00:00 GMT-0400 (hora estándar de Chile)
33 - Fri Sep 03 2021 00:00:00 GMT-0400 (hora estándar de Chile)
34 - Sat Sep 04 2021 00:00:00 GMT-0400 (hora estándar de Chile)
--> Skipped
35 - Mon Sep 06 2021 00:00:00 GMT-0300 (hora de verano de Chile)
36 - Tue Sep 07 2021 00:00:00 GMT-0300 (hora de verano de Chile)
37 - Wed Sep 08 2021 00:00:00 GMT-0300 (hora de verano de Chile)
38 - Thu Sep 09 2021 00:00:00 GMT-0300 (hora de verano de Chile)
39 - Fri Sep 10 2021 00:00:00 GMT-0300 (hora de verano de Chile)
40 - Sat Sep 11 2021 00:00:00 GMT-0300 (hora de verano de Chile)
41 - Sun Sep 12 2021 00:00:00 GMT-0300 (hora de verano de Chile)
42 - Mon Sep 13 2021 00:00:00 GMT-0300 (hora de verano de Chile)
43 - Tue Sep 14 2021 00:00:00 GMT-0300 (hora de verano de Chile)
44 - Wed Sep 15 2021 00:00:00 GMT-0300 (hora de verano de Chile)
45 - Thu Sep 16 2021 00:00:00 GMT-0300 (hora de verano de Chile)
46 - Fri Sep 17 2021 00:00:00 GMT-0300 (hora de verano de Chile)
47 - Sat Sep 18 2021 00:00:00 GMT-0300 (hora de verano de Chile)
48 - Sun Sep 19 2021 00:00:00 GMT-0300 (hora de verano de Chile)
49 - Mon Sep 20 2021 00:00:00 GMT-0300 (hora de verano de Chile)
50 - Tue Sep 21 2021 00:00:00 GMT-0300 (hora de verano de Chile)
51 - Wed Sep 22 2021 00:00:00 GMT-0300 (hora de verano de Chile)
52 - Thu Sep 23 2021 00:00:00 GMT-0300 (hora de verano de Chile)
53 - Fri Sep 24 2021 00:00:00 GMT-0300 (hora de verano de Chile)
54 - Sat Sep 25 2021 00:00:00 GMT-0300 (hora de verano de Chile)
55 - Sun Sep 26 2021 00:00:00 GMT-0300 (hora de verano de Chile)
56 - Mon Sep 27 2021 00:00:00 GMT-0300 (hora de verano de Chile)
57 - Tue Sep 28 2021 00:00:00 GMT-0300 (hora de verano de Chile)
58 - Wed Sep 29 2021 00:00:00 GMT-0300 (hora de verano de Chile)
59 - Thu Sep 30 2021 00:00:00 GMT-0300 (hora de verano de Chile)
...
237 - Sun Mar 27 2022 00:00:00 GMT-0300 (hora de verano de Chile)
238 - Mon Mar 28 2022 00:00:00 GMT-0300 (hora de verano de Chile)
239 - Tue Mar 29 2022 00:00:00 GMT-0300 (hora de verano de Chile)
240 - Wed Mar 30 2022 00:00:00 GMT-0300 (hora de verano de Chile)
241 - Thu Mar 31 2022 00:00:00 GMT-0300 (hora de verano de Chile)
242 - Fri Apr 01 2022 00:00:00 GMT-0300 (hora de verano de Chile)
243 - Sat Apr 02 2022 00:00:00 GMT-0300 (hora de verano de Chile)
244 - Sun Apr 03 2022 00:00:00 GMT-0400 (hora estándar de Chile)
245 - Mon Apr 04 2022 00:00:00 GMT-0400 (hora estándar de Chile)
246 - Tue Apr 05 2022 00:00:00 GMT-0400 (hora estándar de Chile)
247 - Wed Apr 06 2022 00:00:00 GMT-0400 (hora estándar de Chile)
248 - Thu Apr 07 2022 00:00:00 GMT-0400 (hora estándar de Chile)
...
393 - Tue Aug 30 2022 00:00:00 GMT-0400 (hora estándar de Chile)
394 - Wed Aug 31 2022 00:00:00 GMT-0400 (hora estándar de Chile)
395 - Thu Sep 01 2022 00:00:00 GMT-0400 (hora estándar de Chile)
396 - Fri Sep 02 2022 00:00:00 GMT-0400 (hora estándar de Chile)
397 - Sat Sep 03 2022 00:00:00 GMT-0400 (hora estándar de Chile)
--> Skipped
398 - Mon Sep 05 2022 00:00:00 GMT-0300 (hora de verano de Chile)
399 - Tue Sep 06 2022 00:00:00 GMT-0300 (hora de verano de Chile)
400 - Wed Sep 07 2022 00:00:00 GMT-0300 (hora de verano de Chile)
401 - Thu Sep 08 2022 00:00:00 GMT-0300 (hora de verano de Chile)
402 - Fri Sep 09 2022 00:00:00 GMT-0300 (hora de verano de Chile)
403 - Sat Sep 10 2022 00:00:00 GMT-0300 (hora de verano de Chile)
404 - Sun Sep 11 2022 00:00:00 GMT-0300 (hora de verano de Chile)
405 - Mon Sep 12 2022 00:00:00 GMT-0300 (hora de verano de Chile)
...
599 - Sat Mar 25 2023 00:00:00 GMT-0300 (hora de verano de Chile)
600 - Sun Mar 26 2023 00:00:00 GMT-0300 (hora de verano de Chile)
601 - Mon Mar 27 2023 00:00:00 GMT-0300 (hora de verano de Chile)
602 - Tue Mar 28 2023 00:00:00 GMT-0300 (hora de verano de Chile)
603 - Wed Mar 29 2023 00:00:00 GMT-0300 (hora de verano de Chile)
604 - Thu Mar 30 2023 00:00:00 GMT-0300 (hora de verano de Chile)
605 - Fri Mar 31 2023 00:00:00 GMT-0300 (hora de verano de Chile)
606 - Sat Apr 01 2023 00:00:00 GMT-0300 (hora de verano de Chile)
607 - Sun Apr 02 2023 00:00:00 GMT-0400 (hora estándar de Chile)
608 - Mon Apr 03 2023 00:00:00 GMT-0400 (hora estándar de Chile)
609 - Tue Apr 04 2023 00:00:00 GMT-0400 (hora estándar de Chile)
610 - Wed Apr 05 2023 00:00:00 GMT-0400 (hora estándar de Chile)
611 - Thu Apr 06 2023 00:00:00 GMT-0400 (hora estándar de Chile)
612 - Fri Apr 07 2023 00:00:00 GMT-0400 (hora estándar de Chile)
613 - Sat Apr 08 2023 00:00:00 GMT-0400 (hora estándar de Chile)
614 - Sun Apr 09 2023 00:00:00 GMT-0400 (hora estándar de Chile)
...
753 - Sat Aug 26 2023 00:00:00 GMT-0400 (hora estándar de Chile)
754 - Sun Aug 27 2023 00:00:00 GMT-0400 (hora estándar de Chile)
755 - Mon Aug 28 2023 00:00:00 GMT-0400 (hora estándar de Chile)
756 - Tue Aug 29 2023 00:00:00 GMT-0400 (hora estándar de Chile)
757 - Wed Aug 30 2023 00:00:00 GMT-0400 (hora estándar de Chile)
758 - Thu Aug 31 2023 00:00:00 GMT-0400 (hora estándar de Chile)
759 - Fri Sep 01 2023 00:00:00 GMT-0400 (hora estándar de Chile)
760 - Sat Sep 02 2023 00:00:00 GMT-0400 (hora estándar de Chile)
--> Skipped
761 - Mon Sep 04 2023 00:00:00 GMT-0300 (hora de verano de Chile)
762 - Tue Sep 05 2023 00:00:00 GMT-0300 (hora de verano de Chile)
763 - Wed Sep 06 2023 00:00:00 GMT-0300 (hora de verano de Chile)
764 - Thu Sep 07 2023 00:00:00 GMT-0300 (hora de verano de Chile)
765 - Fri Sep 08 2023 00:00:00 GMT-0300 (hora de verano de Chile)
766 - Sat Sep 09 2023 00:00:00 GMT-0300 (hora de verano de Chile)
767 - Sun Sep 10 2023 00:00:00 GMT-0300 (hora de verano de Chile)
768 - Mon Sep 11 2023 00:00:00 GMT-0300 (hora de verano de Chile)
769 - Tue Sep 12 2023 00:00:00 GMT-0300 (hora de verano de Chile)
...
1124 - Sun Sep 01 2024 00:00:00 GMT-0400 (hora estándar de Chile)
1125 - Mon Sep 02 2024 00:00:00 GMT-0400 (hora estándar de Chile)
1126 - Tue Sep 03 2024 00:00:00 GMT-0400 (hora estándar de Chile)
1127 - Wed Sep 04 2024 00:00:00 GMT-0400 (hora estándar de Chile)
1128 - Thu Sep 05 2024 00:00:00 GMT-0400 (hora estándar de Chile)
1129 - Fri Sep 06 2024 00:00:00 GMT-0400 (hora estándar de Chile)
1130 - Sat Sep 07 2024 00:00:00 GMT-0400 (hora estándar de Chile)
--> Skipped
1131 - Mon Sep 09 2024 00:00:00 GMT-0300 (hora de verano de Chile)
1132 - Tue Sep 10 2024 00:00:00 GMT-0300 (hora de verano de Chile)
1133 - Wed Sep 11 2024 00:00:00 GMT-0300 (hora de verano de Chile)
1134 - Thu Sep 12 2024 00:00:00 GMT-0300 (hora de verano de Chile)
1135 - Fri Sep 13 2024 00:00:00 GMT-0300 (hora de verano de Chile)
1136 - Sat Sep 14 2024 00:00:00 GMT-0300 (hora de verano de Chile)
1137 - Sun Sep 15 2024 00:00:00 GMT-0300 (hora de verano de Chile)
...
1330 - Thu Mar 27 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1331 - Fri Mar 28 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1332 - Sat Mar 29 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1333 - Sun Mar 30 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1334 - Mon Mar 31 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1335 - Tue Apr 01 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1336 - Wed Apr 02 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1337 - Thu Apr 03 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1338 - Fri Apr 04 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1339 - Sat Apr 05 2025 00:00:00 GMT-0300 (hora de verano de Chile)
1340 - Sun Apr 06 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1341 - Mon Apr 07 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1342 - Tue Apr 08 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1343 - Wed Apr 09 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1344 - Thu Apr 10 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1345 - Fri Apr 11 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1346 - Sat Apr 12 2025 00:00:00 GMT-0400 (hora estándar de Chile)
...
1457 - Fri Aug 01 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1458 - Sat Aug 02 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1459 - Sun Aug 03 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1460 - Mon Aug 04 2025 00:00:00 GMT-0400 (hora estándar de Chile)
1461 - Tue Aug 05 2025 00:00:00 GMT-0400 (hora estándar de Chile)
2025-08-05T04:00:00.000Z - 2025-08-01T08:00:00.000Z
✘ • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • (159 / 160)
FAIL "0 0 0 * * * with 1461 iterations should return 1461 days from Aug 01 2025 08:00:00"
Expected values to be deeply equal: (equal)
++1754020800000 (Expected)
--1754366400000 (Actual)
at assert (D:/Development/WebStorm/cronerRaw/node_modules/uvu/assert/index.js:33:8)
at Object.equal (D:/Development/WebStorm/cronerRaw/node_modules/uvu/assert/index.js:45:2)
at Object.handler (D:/Development/WebStorm/cronerRaw/test/node/js/src/suites/basics.cjs:535:10)
at Number.runner (D:/Development/WebStorm/cronerRaw/node_modules/uvu/dist/index.js:78:16)
at async Module.exec (file:///D:/Development/WebStorm/cronerRaw/node_modules/uvu/dist/index.mjs:141:33)
at async Module.run (file:///D:/Development/WebStorm/cronerRaw/node_modules/uvu/run/index.mjs:12:2)
at async D:/Development/WebStorm/cronerRaw/node_modules/uvu/bin.js:26:5
Total: 160
Passed: 159
Skipped: 0
Duration: 28169.48ms
from croner.
Reviewing it again, it is correct that it skips that day.
0 0 0 * * *
The CRON expression should run at 12:00 a.m. (00:00:00), but due to Daylight saving time, that day starts at 01:00 a.m., So the clock never hits the requested time. (Saturday 11:59:59 p.m. jumps straight to Sunday 01:00:00 a.m.)
If the CRON expression is set to a different time like 0 0 1 * * *
, then that day is not skipped, so the test pass.
The test ignores the existence of summertime in some countries.
from croner.
Great work figuring this out! Spot on - the problem is that the clock never "is" 00:00:00 these days, it skips from 23:59:59 to 01:00:00. And when the timer runs out at "00:00:00" croner makes an additional check to make sure it isn't running too early. On that check next run time will show up as 01:00:00, which in turns doesn't match the pattern, and it will skip to next matching run (the next day). It could be solved by storing next expected run internally as an utc timestamp, and use that for the early-run check.
Edit: It was not that simple, a deep dive in the code is needed. I guess we need a special clause in the code for this.
from croner.
If anyone is working on this, base work on branch issue-132 which has a failing test enabled
from croner.
Issue now documented in readme at https://github.com/Hexagon/croner#pattern
from croner.
@EricRamirezS Please verify that the problem is solved in 4.4.0. Now the job will actually run at 01:00:00 at the day of dst switch, if clock skips directly from 23:59:59 to 01:00:00 and job is scheduled at 00:00:00.
from croner.
Related Issues (20)
- Syntax error is service wroker HOT 2
- Cron runs every second instead of every 5 minutes. HOT 1
- Cron Job doesn't run correctly HOT 3
- L5,6 Day of the Week is not working correctly - L is not a number HOT 5
- Croner returns different values in case of trailing whitespace HOT 2
- Race HOT 4
- Fix and add the examples links HOT 1
- Request: Last day minus X HOT 1
- Bug: Increment not work as I expected HOT 3
- Specifying timezone causes no trigger using croner <= 7.x HOT 9
- previousRun and currentRun return null all the time HOT 5
- Using */59 * * * * * make run function twice HOT 1
- Support for modulo operator
- Specific timezones cause high CPU load on UNIX systems using croner <= 7.x HOT 10
- Storing job constant in mongo Db results in error HOT 1
- [Feature Request]: A way to stop all scheduled jobs, but wait for running jobs to complete HOT 2
- Job won't run when scheduled with America/Anchorage time zone HOT 1
- Events Feature request HOT 1
- Allow update HOT 1
- using utcOffset throws error: Invalid time zone specified HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from croner.