Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0 0 1-3,12 * * * good, 0 0 12,1-3 * * * bad #179

Closed
KevinWang15 opened this issue Jan 16, 2020 · 3 comments
Closed

0 0 1-3,12 * * * good, 0 0 12,1-3 * * * bad #179

KevinWang15 opened this issue Jan 16, 2020 · 3 comments
Assignees
Labels

Comments

@KevinWang15
Copy link

I think there is a bug here, both 0 1-3,12 * * * and 0 12,1-3 * * * should produce

Fri Jan 17 2020 01:00:00 GMT+0000
Fri Jan 17 2020 02:00:00 GMT+0000
Fri Jan 17 2020 03:00:00 GMT+0000
Fri Jan 17 2020 12:00:00 GMT+0000
Sat Jan 18 2020 01:00:00 GMT+0000
Sat Jan 18 2020 02:00:00 GMT+0000
Sat Jan 18 2020 03:00:00 GMT+0000

however, 0 12,1-3 * * * produces

Fri Jan 17 2020 12:00:00 GMT+0000
Sat Jan 18 2020 12:00:00 GMT+0000
Sun Jan 19 2020 12:00:00 GMT+0000
Mon Jan 20 2020 12:00:00 GMT+0000
Tue Jan 21 2020 12:00:00 GMT+0000
Wed Jan 22 2020 12:00:00 GMT+0000
Thu Jan 23 2020 12:00:00 GMT+0000
@KevinWang15
Copy link
Author

my quick & dirty fix:

Index: lib/expression.js
<+>UTF-8
===================================================================
--- lib/expression.js	(revision 6eae107aef5cb137858ae5a79e8385c36e257b6b)
+++ lib/expression.js	(date 1579182013534)
@@ -251,7 +251,16 @@
       }
     }
 
-    var atoms = val.split(',');
+    var atoms = val.split(',').sort((a, b) => {
+      const getFirstIfIsArray = (val) => {
+        if (Array.isArray(val)) {
+          return val[0];
+        }
+        return val;
+      };
+      return getFirstIfIsArray(parseRepeat(a)) - getFirstIfIsArray(parseRepeat(b));
+    });
+
     if (atoms.length > 1) {
       for (var i = 0, c = atoms.length; i < c; i++) {
         handleResult(parseRepeat(atoms[i]));

@harrisiirak harrisiirak self-assigned this Jan 26, 2020
@harrisiirak
Copy link
Owner

@KevinWang15 thanks for reporting this! Yeah, this looks like a bug. I'll look into this coming days.

@harrisiirak
Copy link
Owner

@KevinWang15 sorry about the delay. Pushed the fix in 110a823. I'm using localeCompare to sort atoms before processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants