Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions prettycron.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ if ((!moment || !later) && (typeof require !== 'undefined')) {
// hour or minute, print them in HH:MM format

var hm = [];
var hour = moment();
for (var i=0; i < schedule['h'].length; i++) {
for (var j=0; j < schedule['m'].length; j++) {
hm.push(zeroPad(schedule['h'][i]) + ':' + zeroPad(schedule['m'][j]));
hour.hour(schedule['h'][i]);
hour.minute(schedule['m'][j]);
hm.push(hour.format("hh:mm A"));
}
}
if (hm.length < 2) {
Expand Down Expand Up @@ -173,15 +176,23 @@ if ((!moment || !later) && (typeof require !== 'undefined')) {
*/
var getNextDate = function(cronspec, sixth) {
var schedule = later.parse.cron(cronspec, sixth);
return later.schedule(schedule).next();
return moment.utc(later.schedule(schedule).next()).format("ddd, MMM Do YYYY, h:mm:ss A");;
};

/*
* Given a cronspec, return the next run date as a moment
* (useful for the getNext
*/
var getNextMoment = function(cronspec, sixth) {
var schedule = later.parse.cron(cronspec, sixth);
return moment.utc(later.schedule(schedule).next());
};
/*
* Given a cronspec, return a friendly string for when it will next run.
* (This is just a wrapper for later.js and moment.js)
*/
var getNext = function(cronspec, sixth) {
return moment( getNextDate( cronspec, sixth ) ).calendar();
return getNextMoment(cronspec, sixth).calendar();
};

//----------------
Expand Down
10 changes: 5 additions & 5 deletions test/homepage-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ suite('homepage examples', function() {
[
{ cron: '0 * * * *', readable: 'Every hour, on the hour' },
{ cron: '30 * * * 1', readable: 'Every 30th minute past every hour on Mon' },
{ cron: '15,45 9,21 * * *', readable: '09:15, 09:45, 21:15 and 21:45 every day' },
{ cron: '18,19 7 5 * *', readable: '07:18 and 07:19 on the 5th of every month' },
{ cron: '15,45 9,21 * * *', readable: '09:15 AM, 09:45 AM, 09:15 PM and 09:45 PM every day' },
{ cron: '18,19 7 5 * *', readable: '07:18 AM and 07:19 AM on the 5th of every month' },
{ cron: '* * 25 12 *', readable: 'Every minute on the 25th in Dec' },
{ cron: '0 * 1,3 * *', readable: 'Every hour, on the hour on the 1 and 3rd of every month' },
{ cron: '0 17 * 1,4,7,10 *', readable: '17:00 every day in Jan, Apr, Jul and Oct' },
{ cron: '0 17 * 1,4,7,10 *', readable: '05:00 PM every day in Jan, Apr, Jul and Oct' },
{ cron: '15 * * * 1,2', readable: 'Every 15th minute past every hour on Mon and Tue' },
{ cron: '* 8,10,12,14,16,18,20 * * *', readable: 'Every minute of 8, 10, 12, 14, 16, 18 and 20th hour' },
{ cron: '0 12 15,16 1 3', readable: '12:00 on the 15 and 16th and every Wed in Jan' },
{ cron: '0 12 15,16 1 3', readable: '12:00 PM on the 15 and 16th and every Wed in Jan' },
{ cron: '0 4,8,12,4 * * 4,5,6', readable: 'Every 0th minute past the 4, 8 and 12th hour on Thu, Fri and Sat' },
{ cron: '0 2,16 1,8,15,22 * 1,2', readable: '02:00 and 16:00 on the 1, 8, 15 and 22nd of every month and every Mon and Tue' },
{ cron: '0 2,16 1,8,15,22 * 1,2', readable: '02:00 AM and 04:00 PM on the 1, 8, 15 and 22nd of every month and every Mon and Tue' },
{ cron: '15 3,8,10,12,14,16,18 16 * *', readable: 'Every 15th minute past the 3, 8, 10, 12, 14, 16 and 18th hour on the 16th of every month' },
{ cron: '2 8,10,12,14,16,18 * 8 0,3', readable: 'Every 2nd minute past the 8, 10, 12, 14, 16 and 18th hour on Sun and Wed in Aug' },
].forEach(function(item) {
Expand Down