Skip to content

Commit

Permalink
Use AM PM time representation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpserra committed Jul 13, 2015
1 parent a164ae0 commit 445319d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
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 OM 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

0 comments on commit 445319d

Please sign in to comment.