{"id":16658839,"url":"https://github.com/danielrbradley/cron-fns","last_synced_at":"2025-04-09T18:33:44.492Z","repository":{"id":57210739,"uuid":"310658631","full_name":"danielrbradley/cron-fns","owner":"danielrbradley","description":"Functions for working with CRON schedules","archived":false,"fork":false,"pushed_at":"2020-11-26T22:49:02.000Z","size":712,"stargazers_count":5,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T20:37:11.017Z","etag":null,"topics":["cron","date-time","javascript-library","npm-package","typescript-library"],"latest_commit_sha":null,"homepage":"https://www.danielbradley.net/cron-fns/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielrbradley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-06T17:08:40.000Z","updated_at":"2023-02-28T13:04:34.000Z","dependencies_parsed_at":"2022-08-31T05:02:04.905Z","dependency_job_id":null,"html_url":"https://github.com/danielrbradley/cron-fns","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielrbradley%2Fcron-fns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielrbradley%2Fcron-fns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielrbradley%2Fcron-fns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielrbradley%2Fcron-fns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielrbradley","download_url":"https://codeload.github.com/danielrbradley/cron-fns/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247852353,"owners_count":21006930,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cron","date-time","javascript-library","npm-package","typescript-library"],"created_at":"2024-10-12T10:06:55.441Z","updated_at":"2025-04-09T18:33:44.470Z","avatar_url":"https://github.com/danielrbradley.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cron-fns\n\nA simple, zero dependency implementation of cron schedule functions. Runs in the browser, in Node.js, in Deno, anywhere with `setTimeout`.\n\n[![npm version](https://badge.fury.io/js/cron-fns.svg)](https://www.npmjs.com/package/cron-fns)\n[![GitHub issues](https://img.shields.io/github/issues/danielrbradley/cron-fns.svg)](https://github.com/danielrbradley/cron-fns/issues)\n[![TypeDoc docs](https://img.shields.io/badge/TypeDoc-docs-green.svg)](https://www.danielbradley.net/cron-fns/)\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/danielrbradley/cron-fns/Release)](https://github.com/danielrbradley/cron-fns/actions?query=workflow%3ARelease)\n\n## Quick Start\n\n```bash\nnpm install cron-fns --save\n# or with yarn\nyarn add cron-fns\n```\n\n## Usage\n\n### `CronDaemon`\n\nExecutes a callback on a given schedule.\n\n_Note: This should be stopped if no longer in use in the application_\n\n```ts\nimport { CronDaemon } from \"cron-fns\";\n\nconst daemon = new CronDaemon(\"0,30 9-17 * * MON\", () =\u003e {\n  console.log(\"do some work\");\n});\n\n// Check when it's going to run next\nconsole.log(daemon.next());\n\n// Stop the daemon\ndaemon.stop();\n\n// Start it again\ndaemon.start();\n\n// Check if it's running\nconsole.log(daemon.state()); // \"running\"\n```\n\n### `nextCronOccurrence(schedule, from?) =\u003e Date | undefined`\n\nFetches the next date that matches the schedule, or undefined if no other time is available.\n\n```ts\nimport { nextCronOccurrence } from \"cron-fns\";\n\nnextCronOccurrence(\"0,30 9-17 * * MON\", new Date(\"2020-01-01T00:00:00\"));\n// Returns 2020-01-06T09:00:00\n\n// `from` defaults to the current date if not specified.\nnextCronOccurrence(\"0,30 9-17 * * MON 1987\");\n// Returns undefined if no more possible dates\n```\n\n### `nextCronOccurrences(schedule, from?)`\n\nReturns a generator which iterates through each sequential date in order from the specified start point. The generator will only stop iterating if there is no more possible dates.\n\n```ts\nimport { nextCronOccurrences } from \"cron-fns\";\n\nnextCronOccurrences(\"0,30 9-10 * * MON\", new Date(\"2020-01-01T00:00:00\"));\n// Returns a generator with the sequence:\n// 2020-01-06T09:00:00\n// 2020-01-06T09:30:00\n// 2020-01-06T10:00:00\n// ...\n```\n\n### `Cron`\n\n```ts\nimport { Cron } from \"cron-fns\";\nconst cron = new Cron(\"0,30 9-17 * * MON\");\ncron.next(); // Returns the next date from now\ncron.next(new Date(\"2020-01-01T00:00:00\")); // Returns 2020-01-06T09:00:00\n```\n\n## Cron syntax rules\n\n```ts\n//                    ┌───────────── minute (0 - 59)\n//                    │    ┌───────────── hour (0 - 23)\n//                    │    │  ┌───────────── day of the month (1 - 31)\n//                    │    │  │ ┌───────────── month (1 - 12)\n//                    │    │  │ │  ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n//                    │    │  │ │  │\n//                    │    │  │ │  │\nnextCronOccurrence(\"0,30 9-17 * * MON\");\n```\n\n- Use a single space to separate fields.\n- Enumerate multiple values for a field by separating by a comma (`,`).\n- Specify a range of values with a hyphen (`-`).\n- Ranges and enumeration cannot be mixed.\n\n## Cron variations \u0026 notes\n\n### Optional years\n\nIf you specify 6 fields then the last field is the year. If not specifed it doesn't limit by year.\n\n### Optional seconds\n\nIf you specify 7 fields then the first field is the second. If not specified it chooses the zeroth second of each minute.\n\n### Timezones\n\nAll times and dates are based on the system (or browser's) local timezone.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielrbradley%2Fcron-fns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielrbradley%2Fcron-fns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielrbradley%2Fcron-fns/lists"}