{"id":19686643,"url":"https://github.com/s-taylor/time-walk","last_synced_at":"2025-04-29T06:31:29.863Z","repository":{"id":74865452,"uuid":"88152612","full_name":"s-taylor/time-walk","owner":"s-taylor","description":"A simple recurrence library","archived":false,"fork":false,"pushed_at":"2017-07-04T22:50:38.000Z","size":245,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T13:51:27.386Z","etag":null,"topics":["date","moment-timezone","momentjs","recurrance","rule","timezone"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s-taylor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-13T10:17:43.000Z","updated_at":"2023-03-04T06:11:42.000Z","dependencies_parsed_at":"2023-07-13T10:15:11.242Z","dependency_job_id":null,"html_url":"https://github.com/s-taylor/time-walk","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-taylor%2Ftime-walk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-taylor%2Ftime-walk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-taylor%2Ftime-walk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-taylor%2Ftime-walk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s-taylor","download_url":"https://codeload.github.com/s-taylor/time-walk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251450656,"owners_count":21591407,"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":["date","moment-timezone","momentjs","recurrance","rule","timezone"],"created_at":"2024-11-11T18:29:40.845Z","updated_at":"2025-04-29T06:31:29.857Z","avatar_url":"https://github.com/s-taylor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Time Walk [![CircleCI](https://circleci.com/gh/s-taylor/time-walk.svg?style=svg)](https://circleci.com/gh/s-taylor/time-walk)\n\n![time-walk](https://raw.githubusercontent.com/s-taylor/time-walk/master/docs/time-walk.jpg)\n\n## What is this?\n\n**Time Walk** is a simple library for generating date recurrance rules. I was inspired to write this after having previously used **Rrule** for a work project and found **Rrule** to have it's quirks.  This module heavily leverages the [moment-timezone](https://momentjs.com/timezone/) library and aims to keep this library as lightweight as possible.\n\nSee [Rrule library here](https://github.com/jakubroztocil/rrule)\n\nSee [differences to Rrule here](https://gist.github.com/s-taylor/f59e0cefc9c2e52d77271cebf021de01)\n\n## What would I use this for?\n\nThere are a number of potential use cases for this module, two better examples I can think of are...\n\n* Generating calendar appointments based on a defined pattern (rule).\n* Implementing a scheduled jobs service in your app, where timezone support is important. Cron doesn't support fortnightly intervals or multi-timezone.\n\n## Try it out\n\n[See runkit demo here](https://runkit.com/nizmox/time-walk-demo)\n\n## How do I use it?\n\n### Syntax\n\n#### Install\n\n`yarn add time-walk`\nOR\n`npm install --save time-walk`\n\n#### Creating a Rule\n\nArguments for a `new` rule are...\n* **start** a `moment-timezone` object where the date and timezone align to the first occurance you want the rule to generate. The timezone specified in the `moment-timezone` object will be used to generate all occurrences (dates) by **Time Walk**. See [moment-timezone](https://momentjs.com/timezone/) for more details.\n* an **interval**, starting from the start date, how far apart do we want occurrence (date) to be (must be in a format `moment.js` understands, see [moment docs here](https://momentjs.com/docs/#/manipulating/add/).\n\nFor example, if I want a rule that recurs on the 1st of every month according to the time in Sydney, Australia, and I wan't my rule to start from next month (July 2017), I would input...\n```js\nconst moment = require('moment-timezone');\nconst { TimeWalk } = require('time-walk');\n\nconst start = new moment.tz('2017-07-01', 'Australia/Sydney');\nconst rule = new TimeWalk(start, { months: 1 });\n```\n\nOR if I want a rule that recurs every second Monday (fortnightly), starting in July 2017 in UTC.\n```js\nconst moment = require('moment-timezone');\nconst { TimeWalk } = require('TimeWalk');\n\nconst start = new moment.tz('2017-07-03', 'UTC');\nconst rule = new TimeWalk(start, { weeks: 2 });\n```\nNote: the 3rd of July is the first Monday in July, so this needs to be the start date.\n\n#### Getting (n)th Occurance\n\nIf I want to get the 2nd occurance of my rule...\n```js\nconst start = new moment.tz('2017-07-01', 'Australia/Sydney');\nconst rule = new TimeWalk(start, { months: 1 });\n\nconst result = rule.occurance(2) // result === 2017-08-01 in Australia/Sydney Time\n```\nNote: The start date **counts** as the first occurence.\n\n#### Getting the first (x) Occurances\n\nIf I want to get the first three ooccurances of my rule...\n```js\nconst start = new moment.tz('2017-07-01', 'Australia/Sydney');\nconst rule = new TimeWalk(start, { months: 1 });\n\nconst result = rule.first(3)\n// result === [2017-07-01, 2017-08-01, 2017-09-01] in Australia/Sydney Time\n```\nNote: The start date **counts** as the first occurence.\n\n#### Getting Occurances within a Range\n\nIf I want to get ALL occurences for my rule that exist between two dates.\nFor example, to get all occurences in July I would do...\n\n```js\nconst start = new moment.tz('2017-07-01', 'Australia/Sydney');\nconst rule = new TimeWalk(start, { weeks: 1 });\n\nconst from = new moment.tz('2017-07-01', 'Australia/Sydney');\nconst to = new moment.tz('2017-08-01', 'Australia/Sydney');\nconst result = rule.between(from, to);\n\n// result === [2017-07-01, 2017-07-08, 2017-07-15, 2017-07-22, 2017-07-29]\n// in Australia/Sydney Time\n```\n\n#### Converting to a string\n\nThis is useful if you want to store rules in a database.\nYou may also need to store the last occurance generated via the rule, but that must be handled separately.\n\n```js\nconst start = new moment.tz('2017-07-01', 'Australia/Sydney');\nconst rule = new TimeWalk(start, { months: 1 });\n\nconst result = rule.toString();\n// result === \"START=2017-06-30T14:00:00.000Z;INTERVAL=M1;TZ=Australia/Sydney;\"\n```\n\n#### Parse a rule (convert from a string)\n\n```js\nconst { parse } = require('time-walk');\n\nconst rule = parse(\"START=2017-06-30T14:00:00.000Z;INTERVAL=M1;TZ=Australia/Sydney;\");\n// rule === new TimeWalk(new moment.tz('2017-07-01', 'Australia/Sydney'), { months: 1 });\n```\n\n## Why am I doing this?\n\nAt present I'm doing this purely as a personal challenge at this point, it's an interesting problem to solve but as I'm not doing this for work, and thus not spending work time on it, set expectations accordingly.\n\n## How can I help?\n\nSend me a pull request! Please don't send me a pull request without tests though.\n\n## What's changed?\n\n[View Changelog](https://github.com/s-taylor/time-walk/blob/master/CHANGELOG.md)\n\n## What still needs doing...\n\n* Allow setting a default output type in constructor\n* Add setter method (including setting default output type)\n* Test between from and to validations\n* Test interval is required (in constructor)\n* Limit how many occurances get returned to 100?\n* Document specifying output format\n\n* Add `.fromString` to create a rule with a date in string format + timezone.\n* remove use of decimals in calcs so more accurate?\n* compile to ES2015\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-taylor%2Ftime-walk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs-taylor%2Ftime-walk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-taylor%2Ftime-walk/lists"}