{"_id":"node-schedule-tz","_rev":"10-6f1148921c1b1be9f20ba41564a91bf4","name":"node-schedule-tz","time":{"modified":"2022-06-21T21:24:18.192Z","created":"2017-05-17T09:46:46.000Z","1.2.1":"2017-05-17T09:46:46.000Z","1.2.1-1":"2017-05-17T09:52:02.315Z","1.2.1-2":"2017-05-17T10:40:40.519Z","1.2.1-3":"2017-05-17T11:00:02.962Z","1.2.1-4":"2017-05-17T11:14:38.581Z"},"maintainers":[{"name":"kqkq","email":"kqwd@163.com"}],"dist-tags":{"latest":"1.2.1-4"},"description":"A cron-like and not-cron-like job scheduler with timezone support for Node.","readme":"# Node Schedule with Timezone Support\n\n[![NPM version](http://img.shields.io/npm/v/node-schedule-tz.svg)](https://www.npmjs.com/package/node-schedule-tz)\n[![Downloads](https://img.shields.io/npm/dm/node-schedule-tz.svg)](https://www.npmjs.com/package/node-schedule-tz)\n[![Build Status](https://travis-ci.org/node-schedule-tz/node-schedule-tz.svg?branch=master)](https://travis-ci.org/node-schedule/node-schedule-tz)\n[![Join the chat at https://gitter.im/node-schedule-tz/node-schedule-tz](https://img.shields.io/badge/gitter-chat-green.svg)](https://gitter.im/node-schedule-tz/node-schedule-tz?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\n[![NPM](https://nodei.co/npm/node-schedule-tz.png?downloads=true)](https://nodei.co/npm/node-schedule-tz/)\n\nNode Schedule is a flexible cron-like and not-cron-like job scheduler with timezone support for Node.js.\nIt allows you to schedule jobs (arbitrary functions) for execution at\nspecific dates, with optional recurrence rules. It only uses a single timer\nat any given time (rather than reevaluating upcoming jobs every second/minute).\n\n## Usage\n\n### Installation\n\nYou can install using [npm](https://www.npmjs.com/package/node-schedule-tz).\n\n```\nnpm install node-schedule-tz\n```\n\n### Overview\n\nNode Schedule is for time-based scheduling, not interval-based scheduling.\nWhile you can easily bend it to your will, if you only want to do something like\n\"run this function every 5 minutes\", you'll find `setInterval` much easier to use,\nand far more appropriate. But if you want to, say, \"run this function at the :20\nand :50 of every hour on the third Tuesday of every month,\" you'll find that\nNode Schedule suits your needs better. Additionally, Node Schedule has Windows\nsupport unlike true cron since the node runtime is now fully supported.\n\nNote that Node Schedule is designed for in-process scheduling, i.e. scheduled jobs\nwill only fire as long as your script is running, and the schedule will disappear\nwhen execution completes. If you need to schedule jobs that will persist even when\nyour script *isn't* running, consider using actual [cron].\n\n### Jobs and Scheduling\n\nEvery scheduled job in Node Schedule is represented by a `Job` object. You can\ncreate jobs manually, then execute the `schedule()` method to apply a schedule,\nor use the convenience function `scheduleJob()` as demonstrated below.\n\n`Job` objects are `EventEmitter`'s, and emit a `run` event after each execution.\nThey also emit a `scheduled` event each time they're scheduled to run, and a\n`canceled` event when an invocation is canceled before it's executed (both events\nreceive a JavaScript date object as a parameter). Note that jobs are scheduled the\nfirst time immediately, so if you create a job using the `scheduleJob()`\nconvenience method, you'll miss the first `scheduled` event. Also note that\n`canceled` is the single-L American spelling.\n\n### Cron-style Scheduling\n\nThe cron format consists of:\n```\n*    *    *    *    *    *\n┬    ┬    ┬    ┬    ┬    ┬\n│    │    │    │    │    |\n│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)\n│    │    │    │    └───── month (1 - 12)\n│    │    │    └────────── day of month (1 - 31)\n│    │    └─────────────── hour (0 - 23)\n│    └──────────────────── minute (0 - 59)\n└───────────────────────── second (0 - 59, OPTIONAL)\n```\n\nExamples with the cron format:\n\n```js\nvar schedule = require('node-schedule-tz');\n\nvar j = schedule.scheduleJob('42 * * * *', function(){\n  console.log('The answer to life, the universe, and everything!');\n});\n```\n\nExecute a cron job when the minute is 42 (e.g. 19:42, 20:42, etc.).\n\nAnd:\n\n```js\nvar j = schedule.scheduleJob('0 17 ? * 0,4-6', function(){\n  console.log('Today is recognized by Rebecca Black!');\n});\n```\n\nExecute a cron job every 5 Minutes = */5 * * * *\n\nYou can specify a timezone as well:\n\n```js\nvar j = schedule.scheduleJob('0 14 * * *', 'Asia/Shanghai', function(){\n  console.log('Will execute on 14:00:00 GMT+8:00 (CST) everyday');\n});\n```\n\n#### Unsupported Cron Features\n\nCurrently, `W` (nearest weekday), `L` (last day of month/week), and `#` (nth weekday\nof the month) are not supported. Most other features supported by popular cron\nimplementations should work just fine.\n\n[cron-parser] is used to parse crontab instructions.\n\n### Date-based Scheduling\n\nSay you very specifically want a function to execute at 5:30am on December 21, 2012.\nRemember - in JavaScript - 0 - January, 11 - December.\n\n```js\nvar schedule = require('node-schedule-tz');\nvar date = new Date(2012, 11, 21, 5, 30, 0);\n\nvar j = schedule.scheduleJob(date, function(){\n  console.log('The world is going to end today.');\n});\n```\n\nYou can invalidate the job with the `cancel()` method:\n\n```js\nj.cancel();\n```\n\nTo use current data in the future you can use binding:\n\n```js\nvar schedule = require('node-schedule-tz');\nvar date = new Date(2012, 11, 21, 5, 30, 0);\nvar x = 'Tada!';\nvar j = schedule.scheduleJob(date, function(y){\n  console.log(y);\n}.bind(null,x));\nx = 'Changing Data';\n```\nThis will log 'Tada!' when the scheduled Job runs, rather than 'Changing Data',\nwhich x changes to immediately after scheduling.\n\n### Recurrence Rule Scheduling\n\nYou can build recurrence rules to specify when a job should recur. For instance,\nconsider this rule, which executes the function every hour at 42 minutes after the hour:\n\n```js\nvar schedule = require('node-schedule-tz');\n\nvar rule = new schedule.RecurrenceRule();\nrule.minute = 42;\n\nvar j = schedule.scheduleJob(rule, function(){\n  console.log('The answer to life, the universe, and everything!');\n});\n```\n\nYou can also use arrays to specify a list of acceptable values, and the `Range`\nobject to specify a range of start and end values, with an optional step parameter.\nFor instance, this will print a message on Thursday, Friday, Saturday, and Sunday at 5pm:\n\n```js\nvar rule = new schedule.RecurrenceRule();\nrule.dayOfWeek = [0, new schedule.Range(4, 6)];\nrule.hour = 17;\nrule.minute = 0;\nrule.tz = 'Asia/Shanghai'; // You can specify a timezone!\n\nvar j = schedule.scheduleJob(rule, function(){\n  console.log('Today is recognized by Rebecca Black!');\n});\n```\n\n#### RecurrenceRule properties\n\n- `second`\n- `minute`\n- `hour`\n- `date`\n- `month`\n- `year`\n- `dayOfWeek`\n- `tz`\n\n> **Note**: It's worth noting that the default value of a component of a recurrence rule is\n> `null` (except for second, which is 0 for familiarity with cron). *If we did not\n> explicitly set `minute` to 0 above, the message would have instead been logged at\n> 5:00pm, 5:01pm, 5:02pm, ..., 5:59pm.* Probably not what you want.\n\n#### Object Literal Syntax\n\nTo make things a little easier, an object literal syntax is also supported, like\nin this example which will log a message every Sunday at 2:30pm:\n\n```js\nvar j = schedule.scheduleJob({hour: 14, minute: 30, dayOfWeek: 0}, function(){\n  console.log('Time for tea!');\n});\n```\n\n#### Set StartTime and EndTime\n\nIt will run after 5 seconds and stop after 10 seconds in this example.\nThe ruledat supports the above.\n\n```js\nlet startTime = new Date(Date.now() + 5000);\nlet endTime = new Date(startTime.getTime() + 5000);\nvar j = schedule.scheduleJob({ start: startTime, end: endTime, rule: '*/1 * * * * *' }, function(){\n  console.log('Time for tea!');\n});\n```\n\n\n## Contributing\n\nThis module was originally developed by [Matt Patenaude], and is now maintained by\n[Tejas Manohar] and [other wonderful contributors].\n\nWe'd love to get your contributions. Individuals making significant and valuable\ncontributions are given commit-access to the project to contribute as they see fit.\n\nBefore jumping in, check out our [Contributing] page guide!\n\n## Copyright and license\n\nCopyright 2015 Matt Patenaude.\n\nLicensed under the **[MIT License] [license]**.\n\n\n[cron]: http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5\n[Contributing]: https://github.com/node-schedule/node-schedule/blob/master/CONTRIBUTING.md\n[Matt Patenaude]: https://github.com/mattpat\n[Tejas Manohar]: http://tejas.io\n[license]: https://github.com/node-schedule/node-schedule/blob/master/LICENSE\n[Tejas Manohar]: https://github.com/tejasmanohar\n[other wonderful contributors]: https://github.com/node-schedule/node-schedule/graphs/contributors\n[cron-parser]: https://github.com/harrisiirak/cron-parser\n","versions":{"1.2.1-4":{"name":"node-schedule-tz","version":"1.2.1-4","description":"A cron-like and not-cron-like job scheduler with timezone support for Node.","keywords":["schedule","task","job","cron","timezone"],"license":"MIT","main":"./lib/schedule.js","scripts":{"test":"nodeunit","lint":"eslint lib"},"author":{"name":"Matt Patenaude","email":"matt@mattpatenaude.com","url":"http://mattpatenaude.com"},"contributors":[{"name":"KUANG Qi","email":"kqwd@163.com"}],"repository":{"type":"git","url":"git+ssh://git@github.com/kqkq/node-schedule-tz.git"},"dependencies":{"cron-parser":"^2.4.0","long-timeout":"0.1.1","sorted-array-functions":"^1.0.0"},"devDependencies":{"coveralls":"^2.11.2","eslint":"^0.15.1","istanbul":"^0.4.5","nodeunit":"^0.10.2","sinon":"^1.14.1"},"gitHead":"2f02a2960cbc3a90e318660f4d0092287dfc5202","bugs":{"url":"https://github.com/kqkq/node-schedule-tz/issues"},"homepage":"https://github.com/kqkq/node-schedule-tz#readme","_id":"node-schedule-tz@1.2.1-4","_shasum":"6c971cb4628dadc5723a1169368a6ec273942f24","_from":".","_npmVersion":"4.2.0","_nodeVersion":"7.9.0","_npmUser":{"name":"kqkq","email":"kqwd@163.com"},"dist":{"shasum":"6c971cb4628dadc5723a1169368a6ec273942f24","tarball":"https://registry.npmjs.org/node-schedule-tz/-/node-schedule-tz-1.2.1-4.tgz","integrity":"sha512-dLiZTIlp73z6znFG9Src4lKvWH/7iaoM/25CxyQa3scrKPWX8LiV9ETEqnsNReytz4L7ofrz63grtLBWggcx3g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC2LFRNmoF3cwEijuzsoRU3AQeOhHv5hC4PHn2/Um7KcwIgE4DIRBeWezrtaQwtF7sIEmhCadmEPuoSl1VnoejUFP4="}]},"maintainers":[{"name":"kqkq","email":"kqwd@163.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/node-schedule-tz-1.2.1-4.tgz_1495019675671_0.8514370266348124"}}},"homepage":"https://github.com/kqkq/node-schedule-tz#readme","keywords":["schedule","task","job","cron","timezone"],"repository":{"type":"git","url":"git+ssh://git@github.com/kqkq/node-schedule-tz.git"},"contributors":[{"name":"KUANG Qi","email":"kqwd@163.com"}],"author":{"name":"Matt Patenaude","email":"matt@mattpatenaude.com","url":"http://mattpatenaude.com"},"bugs":{"url":"https://github.com/kqkq/node-schedule-tz/issues"},"license":"MIT","readmeFilename":"README.md"}