Skip to content

Commit

Permalink
refactor: improve time units referencing
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed May 24, 2023
1 parent 679c55e commit 516bbe8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ const ALIASES = {
fri: 5,
sat: 6
};
const TIME_UNITS = [
'second',
'minute',
'hour',
'dayOfMonth',
'month',
'dayOfWeek'
];
const TIME_UNITS_MAP = {
SECOND: 'second',
MINUTE: 'minute',
HOUR: 'hour',
DAY_OF_MONTH: 'dayOfMonth',
MONTH: 'month',
DAY_OF_WEEK: 'dayOfWeek'
};
const TIME_UNITS = Object.values(TIME_UNITS_MAP);
const TIME_UNITS_LEN = TIME_UNITS.length;
const PRESETS = {
'@yearly': '0 0 0 1 1 *',
Expand Down Expand Up @@ -672,7 +673,10 @@ function CronTime(luxon) {
_hasAll: function (type) {
const constraints = CONSTRAINTS[TIME_UNITS.indexOf(type)];
const low = constraints[0];
const high = type === 'dayOfWeek' ? constraints[1] - 1 : constraints[1];
const high =
type === TIME_UNITS_MAP.DAY_OF_WEEK
? constraints[1] - 1
: constraints[1];

for (let i = low, n = high; i < n; i++) {
if (!(i in this[type])) {
Expand Down

0 comments on commit 516bbe8

Please sign in to comment.