cron-converter
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -14,3 +14,4 @@ { | ||
"moduleType": [ | ||
"globals" | ||
"globals", | ||
"amd" | ||
], | ||
@@ -25,5 +26,5 @@ "ignore": [ | ||
"dependencies": { | ||
"moment": "~2", | ||
"moment-timezone": "~0.5", | ||
"sprintf": "~1" | ||
} | ||
} |
@@ -68,3 +68,6 @@ var browserify = require('browserify'); | ||
entries: 'src/cron.js', | ||
standalone: 'Cron' | ||
standalone: 'Cron', | ||
transform: [ | ||
"browserify-shim" | ||
] | ||
}) | ||
@@ -71,0 +74,0 @@ .bundle() |
{ | ||
"name": "cron-converter", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Cron string converter", | ||
@@ -35,13 +35,9 @@ "main": "src/cron.js", | ||
"vinyl-buffer": "^1.0.0", | ||
"vinyl-source-stream": "^1.1.0" | ||
"vinyl-source-stream": "^1.1.0", | ||
"zuul": "^3.9.0" | ||
}, | ||
"dependencies": { | ||
"moment": "~2", | ||
"moment-timezone": "~0.5", | ||
"sprintf-js": "~1" | ||
}, | ||
"browserify": { | ||
"transform": [ | ||
"browserify-shim" | ||
] | ||
}, | ||
"browserify-shim": { | ||
@@ -48,0 +44,0 @@ "moment": "global:moment", |
@@ -6,5 +6,6 @@ # cron-converter | ||
[](https://github.com/roccivic/cron-converter/blob/master/LICENCE.txt) | ||
 | ||
[](https://www.npmjs.com/package/cron-converter) | ||
 | ||
[](https://travis-ci.org/roccivic/cron-converter) | ||
[](https://travis-ci.org/roccivic/cron-converter) | ||
[](https://coveralls.io/github/roccivic/cron-converter?branch=master) | ||
@@ -17,3 +18,6 @@ | ||
[](http://inch-ci.org/github/roccivic/cron-converter) | ||
[](https://todofy.org/r/roccivic/cron-converter) | ||
[](https://saucelabs.com/u/cron-converter) | ||
## Install | ||
@@ -80,37 +84,59 @@ | ||
var reference = new Date(2013, 2, 8, 9, 32); | ||
// or | ||
reference = moment([2013, 2, 8, 9, 32]); | ||
// or, if you need to support timezones (requires moment-timezone) | ||
reference = moment([2013, 2, 8, 9, 32]).tz("Europe/London"); | ||
// And pass the reference to .schedule() | ||
schedule = cronInstance.schedule(reference); | ||
// Prints: 'Fri Feb 08 2013 09:35:00 GMT+0000 (GMT Standard Time)' | ||
console.log(schedule.next()); | ||
// Prints: 'Fri Feb 08 2013 09:40:00 GMT+0000 (GMT Standard Time)' | ||
console.log(schedule.next()); | ||
// Calls to ```.next()``` and ```.prev()``` | ||
// return a Moment.js object | ||
// Prints: '2013-03-08T09:35:00+00:00'' | ||
console.log(schedule.next().format()); | ||
// Prints: '2013-03-08T09:40:00+00:00'' | ||
console.log(schedule.next().format()); | ||
// Reset | ||
schedule.reset(); | ||
// Prints: 'Fri Feb 08 2013 09:30:00 GMT+0000 (GMT Standard Time)' | ||
console.log(schedule.prev()); | ||
// Prints: 'Fri Feb 08 2013 09:25:00 GMT+0000 (GMT Standard Time)' | ||
console.log(schedule.prev()); | ||
// Prints: '2013-03-08T09:30:00+00:00'' | ||
console.log(schedule.prev().format()); | ||
// Prints: '2013-03-08T09:25:00+00:00'' | ||
console.log(schedule.prev().format()); | ||
``` | ||
### Constructor options | ||
All default to ```false``` | ||
#### outputWeekdayNames and outputMonthNames | ||
Default: false | ||
```js | ||
var cronInstance = new Cron({ | ||
outputWeekdayNames: true, | ||
outputMonthNames: true, | ||
outputMonthNames: true | ||
}); | ||
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5'); | ||
// Prints: '*/5 *(10-16)/2 * JAN-MAR MON-FRI' | ||
console.log(cronInstance.toString()); | ||
``` | ||
#### outputHashes | ||
Default: false | ||
```js | ||
var cronInstance = new Cron({ | ||
outputHashes: true | ||
}); | ||
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5'); | ||
// Prints: 'H/5 H(10-16)/2 H JAN-MAR MON-FRI' | ||
// Prints: 'H/5 H(10-16)/2 H 1-3 1-5' | ||
console.log(cronInstance.toString()); | ||
``` | ||
#### timezone | ||
Default: Local timezone | ||
```js | ||
var cronInstance = new Cron({ | ||
timezone: "Europe/London" | ||
}); | ||
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5'); | ||
// Finds the next execution time in the London timezone | ||
console.log(cronInstance.schedule().next()); | ||
``` | ||
## Test and build | ||
@@ -117,0 +143,0 @@ |
'use strict'; | ||
var moment = require('moment'); | ||
var Part = require('./part'); | ||
@@ -6,0 +4,0 @@ var Seeker = require('./seeker'); |
'use strict'; | ||
var moment = require('moment'); | ||
var moment = require('moment-timezone'); | ||
@@ -16,3 +16,8 @@ /** | ||
} | ||
var date = moment(now); | ||
var date; | ||
if (cron.options.timezone) { | ||
date = moment.tz(now, cron.options.timezone); | ||
} else { | ||
date = moment(now); | ||
} | ||
if (!date.isValid()) { | ||
@@ -73,3 +78,3 @@ throw new Error('Invalid date provided'); | ||
* @param {boolean} reverse Whether to find the previous value instead of next. | ||
* @return {Date} The date the schedule would have executed at. | ||
* @return {Moment} The date the schedule would have executed at. | ||
*/ | ||
@@ -102,4 +107,4 @@ var findDate = function(parts, date, reverse) { | ||
date.seconds(0).milliseconds(0); | ||
// Return JS Date object | ||
return date.toDate(); | ||
// Return new moment object | ||
return moment(date); | ||
}; | ||
@@ -106,0 +111,0 @@ |
@@ -83,3 +83,5 @@ 'use strict'; | ||
schedules.forEach(function(s) { | ||
var cron = new Cron(); | ||
var cron = new Cron({ | ||
timezone: 'Europe/London' | ||
}); | ||
cron.fromString(s.schedule); | ||
@@ -86,0 +88,0 @@ var schedule = cron.schedule(s.now); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47916
150
17
31
1693
+ Addedmoment-timezone@~0.5
+ Addedmoment-timezone@0.5.47(transitive)
- Removedmoment@~2