Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cron-parser

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron-parser - npm Package Compare versions

Comparing version 2.18.0 to 3.0.0

.eslintrc.json

152

lib/date.js
'use strict';
var moment = require('moment-timezone');
var luxon = require('luxon');
CronDate.prototype.addYear = function() {
this._date.add(1, 'year');
this._date = this._date.plus({ years: 1 });
};
CronDate.prototype.addMonth = function() {
this._date.add(1, 'month').startOf('month');
this._date = this._date.plus({ months: 1 }).startOf('month');
};
CronDate.prototype.addDay = function() {
this._date.add(1, 'day').startOf('day');
this._date = this._date.plus({ days: 1 }).startOf('day');
};
CronDate.prototype.addHour = function() {
var prev = this.getTime();
this._date.add(1, 'hour').startOf('hour');
if (this.getTime() <= prev) {
this._date.add(1, 'hour');
var prev = this._date;
this._date = this._date.plus({ hours: 1 }).startOf('hour');
if (this._date <= prev) {
this._date = this._date.plus({ hours: 1 });
}

@@ -26,6 +26,6 @@ };

CronDate.prototype.addMinute = function() {
var prev = this.getTime();
this._date.add(1, 'minute').startOf('minute');
if (this.getTime() < prev) {
this._date.add(1, 'hour');
var prev = this._date;
this._date = this._date.plus({ minutes: 1 }).startOf('minute');
if (this._date < prev) {
this._date = this._date.plus({ hours: 1 });
}

@@ -35,6 +35,6 @@ };

CronDate.prototype.addSecond = function() {
var prev = this.getTime();
this._date.add(1, 'second').startOf('second');
if (this.getTime() < prev) {
this._date.add(1, 'hour');
var prev = this._date;
this._date = this._date.plus({ seconds: 1 }).startOf('second');
if (this._date < prev) {
this._date = this._date.plus({ hours: 1 });
}

@@ -44,18 +44,18 @@ };

CronDate.prototype.subtractYear = function() {
this._date.subtract(1, 'year');
this._date = this._date.minus({ years: 1 });
};
CronDate.prototype.subtractMonth = function() {
this._date.subtract(1, 'month').endOf('month');
this._date = this._date.minus({ months: 1 }).endOf('month');
};
CronDate.prototype.subtractDay = function() {
this._date.subtract(1, 'day').endOf('day');
this._date = this._date.minus({ days: 1 }).endOf('day');
};
CronDate.prototype.subtractHour = function() {
var prev = this.getTime();
this._date.subtract(1, 'hour').endOf('hour');
if (this.getTime() >= prev) {
this._date.subtract(1, 'hour');
var prev = this._date;
this._date = this._date.minus({ hours: 1 }).endOf('hour');
if (this._date >= prev) {
this._date = this._date.minus({ hours: 1 });
}

@@ -65,6 +65,6 @@ };

CronDate.prototype.subtractMinute = function() {
var prev = this.getTime();
this._date.subtract(1, 'minute').endOf('minute');
if (this.getTime() > prev) {
this._date.subtract(1, 'hour');
var prev = this._date;
this._date = this._date.minus({ minutes: 1 }).endOf('minute');
if (this._date > prev) {
this._date = this._date.minus({ hours: 1 });
}

@@ -74,6 +74,6 @@ };

CronDate.prototype.subtractSecond = function() {
var prev = this.getTime();
this._date.subtract(1, 'second').startOf('second');
if (this.getTime() > prev) {
this._date.subtract(1, 'hour');
var prev = this._date;
this._date = this._date.minus({ seconds: 1 }).startOf('second');
if (this._date > prev) {
this._date = this._date.minus({ hours: 1 });
}

@@ -83,31 +83,32 @@ };

CronDate.prototype.getDate = function() {
return this._date.date();
return this._date.day;
};
CronDate.prototype.getFullYear = function() {
return this._date.year();
return this._date.year;
};
CronDate.prototype.getDay = function() {
return this._date.day();
var weekday = this._date.weekday;
return weekday == 7 ? 0 : weekday;
};
CronDate.prototype.getMonth = function() {
return this._date.month();
return this._date.month - 1;
};
CronDate.prototype.getHours = function() {
return this._date.hours();
return this._date.hour;
};
CronDate.prototype.getMinutes = function() {
return this._date.minute();
return this._date.minute;
};
CronDate.prototype.getSeconds = function() {
return this._date.second();
return this._date.second;
};
CronDate.prototype.getMilliseconds = function() {
return this._date.millisecond();
return this._date.millisecond;
};

@@ -120,31 +121,32 @@

CronDate.prototype.getUTCDate = function() {
return this._getUTC().date();
return this._getUTC().day;
};
CronDate.prototype.getUTCFullYear = function() {
return this._getUTC().year();
return this._getUTC().year;
};
CronDate.prototype.getUTCDay = function() {
return this._getUTC().day();
var weekday = this._getUTC().weekday;
return weekday == 7 ? 0 : weekday;
};
CronDate.prototype.getUTCMonth = function() {
return this._getUTC().month();
return this._getUTC().month - 1;
};
CronDate.prototype.getUTCHours = function() {
return this._getUTC().hours();
return this._getUTC().hour;
};
CronDate.prototype.getUTCMinutes = function() {
return this._getUTC().minute();
return this._getUTC().minute;
};
CronDate.prototype.getUTCSeconds = function() {
return this._getUTC().second();
return this._getUTC().second;
};
CronDate.prototype.toISOString = function() {
return this._date.toISOString();
return this._date.toISO();
};

@@ -157,39 +159,35 @@

CronDate.prototype.setDate = function(d) {
return this._date.date(d);
this._date = this._date.set({ day: d });
};
CronDate.prototype.setFullYear = function(y) {
return this._date.year(y);
this._date = this._date.set({ year: y });
};
CronDate.prototype.setDay = function(d) {
return this._date.day(d);
this._date = this._date.set({ weekday: d });
};
CronDate.prototype.setMonth = function(m) {
return this._date.month(m);
this._date = this._date.set({ month: m + 1 });
};
CronDate.prototype.setHours = function(h) {
return this._date.hour(h);
this._date = this._date.set({ hour: h });
};
CronDate.prototype.setMinutes = function(m) {
return this._date.minute(m);
this._date = this._date.set({ minute: m });
};
CronDate.prototype.setSeconds = function(s) {
return this._date.second(s);
this._date = this._date.set({ second: s });
};
CronDate.prototype.setMilliseconds = function(s) {
return this._date.millisecond(s);
this._date = this._date.set({ millisecond: s });
};
CronDate.prototype.getTime = function() {
return this._date.valueOf();
};
CronDate.prototype._getUTC = function() {
return moment.utc(this._date);
return this._date.toUTC();
};

@@ -202,24 +200,38 @@

CronDate.prototype.toDate = function() {
return this._date.toDate();
return this._date.toJSDate();
};
CronDate.prototype.isLastDayOfMonth = function() {
var newDate = this._date.clone();
//next day
newDate.add(1, 'day').startOf('day');
return this._date.month() !== newDate.month();
var newDate = this._date.plus({ days: 1 }).startOf('day');
return this._date.month !== newDate.month;
};
function CronDate (timestamp, tz) {
if (timestamp instanceof CronDate) {
timestamp = timestamp._date;
var dateOpts = { zone: tz };
if (!timestamp) {
this._date = luxon.DateTime.local();
} else if (timestamp instanceof CronDate) {
this._date = timestamp._date;
} else if (timestamp instanceof Date) {
this._date = luxon.DateTime.fromJSDate(timestamp, dateOpts);
} else if (typeof timestamp === 'number') {
this._date = luxon.DateTime.fromMillis(timestamp, dateOpts);
} else if (typeof timestamp === 'string') {
this._date = luxon.DateTime.fromISO(timestamp, dateOpts);
this._date.isValid || (this._date = luxon.DateTime.fromRFC2822(timestamp, dateOpts));
this._date.isValid || (this._date = luxon.DateTime.fromSQL(timestamp, dateOpts));
// RFC2822-like format without the required timezone offset (used in tests)
this._date.isValid || (this._date = luxon.DateTime.fromFormat(timestamp, 'EEE, d MMM yyyy HH:mm:ss', dateOpts));
}
if (!tz) {
this._date = moment(timestamp);
} else {
this._date = moment.tz(timestamp, tz);
if (!this._date || !this._date.isValid) {
throw new Error('CronDate: unhandled timestamp: ' + JSON.stringify(timestamp));
}
if (tz && tz !== this._date.zoneName) {
this._date = this._date.setZone(tz);
}
}
module.exports = CronDate;

@@ -155,3 +155,3 @@ 'use strict';

dayOfWeek: CronExpression.dayOfWeekValidCharacters,
}
};

@@ -180,3 +180,3 @@ /**

} else {
throw new Error('Cannot resolve alias "' + match + '"')
throw new Error('Cannot resolve alias "' + match + '"');
}

@@ -189,3 +189,3 @@ });

if (!(CronExpression.validCharacters[field].test(value))) {
throw new Error('Invalid characters, got value: ' + value)
throw new Error('Invalid characters, got value: ' + value);
}

@@ -838,3 +838,3 @@

return -1;
})
});

@@ -841,0 +841,0 @@ }

{
"name": "cron-parser",
"version": "2.18.0",
"version": "3.0.0",
"description": "Node.js library for parsing crontab instructions",

@@ -11,3 +11,6 @@ "main": "lib/parser.js",

"scripts": {
"test": "tap ./test/*.js"
"test:unit": "tap ./test/*.js",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"test": "npm run lint && npm run test:unit"
},

@@ -42,3 +45,4 @@ "repository": {

"Charlie Fish <fishcharlie.code@gmail.com>",
"Ian Graves <ian+diskimage@iangrav.es>"
"Ian Graves <ian+diskimage@iangrav.es>",
"Andy Thompson <me@andytson.com>"
],

@@ -48,5 +52,6 @@ "license": "MIT",

"is-nan": "^1.3.0",
"moment-timezone": "^0.5.31"
"luxon": "^1.25.0"
},
"devDependencies": {
"eslint": "^7.17.0",
"sinon": "^9.2.1",

@@ -53,0 +58,0 @@ "tap": "^14.10.8"

@@ -22,2 +22,2 @@ // empty around comma

t.end();
});
});

@@ -583,3 +583,3 @@ var test = require('tap').test;

t.ok(next, 'Found next scheduled interval');
t.ok(day == 1 || day == 2, 'Day matches')
t.ok(day == 1 || day == 2, 'Day matches');
t.equal(next.getHours(), 10, 'Hour matches');

@@ -1173,3 +1173,3 @@ t.equal(next.getMinutes(), 15, 'Minute matches');

new CronDate('2019-05-12'),
new CronDate('2019-06-9'),
new CronDate('2019-06-09'),
new CronDate('2019-07-14'),

@@ -1191,4 +1191,4 @@ new CronDate('2019-08-11')

var expectedFifthDates = [
new CronDate('2019-6-30'),
new CronDate('2019-9-29'),
new CronDate('2019-06-30'),
new CronDate('2019-09-29'),
new CronDate('2019-12-29'),

@@ -1195,0 +1195,0 @@ new CronDate('2020-03-29')

@@ -216,3 +216,4 @@ var test = require('tap').test;

options.currentDate = '2016-10-30 00:00:01';
options.endDate = '2016-10-30 03:00:01';
// specify the DST offset via ISO 8601 format, as 3am is repeated
options.endDate = '2016-10-30T03:00:01+03';

@@ -219,0 +220,0 @@ interval = CronExpression.parse('0 * * * *', options);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc