{"id":21241670,"url":"https://github.com/smhg/date-duration","last_synced_at":"2025-07-10T20:31:04.823Z","repository":{"id":35807818,"uuid":"40090057","full_name":"smhg/date-duration","owner":"smhg","description":"ISO 8601 durations","archived":false,"fork":false,"pushed_at":"2021-09-22T07:41:42.000Z","size":50,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-21T18:15:17.579Z","etag":null,"topics":["date","duration","iso8601","time"],"latest_commit_sha":null,"homepage":"","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/smhg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-02T19:17:58.000Z","updated_at":"2023-08-27T04:04:59.000Z","dependencies_parsed_at":"2022-08-26T09:31:28.070Z","dependency_job_id":null,"html_url":"https://github.com/smhg/date-duration","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/smhg/date-duration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-duration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-duration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-duration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-duration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smhg","download_url":"https://codeload.github.com/smhg/date-duration/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-duration/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261625042,"owners_count":23186132,"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","duration","iso8601","time"],"created_at":"2024-11-21T00:56:37.462Z","updated_at":"2025-07-10T20:31:04.246Z","avatar_url":"https://github.com/smhg.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"date-duration [![ci](https://github.com/smhg/date-duration/actions/workflows/node.js.yml/badge.svg)](https://github.com/smhg/date-duration/actions/workflows/node.js.yml)\n======\nManipulate Date objects with [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations)-formatted durations.\n\n## Installation\n```shell\n$ npm install date-duration\n```\n\n## Usage\n```javascript\nimport Duration from 'date-duration';\n\nlet duration = Duration('PT1H');\n// or\nlet duration = Duration({P: {T: {H: 1}}});\n```\n**Note:** keep in mind that working with time-only durations (hours, minutes, seconds) is _generally_ a better idea.\n\nA duration of `PT36H` is not the same as `P1DT12H`. The former will add/subtract _exactly_ 36 hours while the latter will add 12 hours + whatever 1 day means. e.g. if jumping across DST (Daylight saving time) and the difference is 1 hour, this totals to plus/minus 35 hours or 37 hours.\n\nThis is generally what you want as long as you take into account this happens _within the context of the timezone of your environment_. **This can become tricky when used in browsers** (where you don't have control over this).\n\n## API\n### Duration(ISOString)\nPass a string in ISO 8601 duration format to create a duration.\n\n### duration.addTo(Date)\nAdd the duration to a Date object and returns the new date. Objects with a `.toDate()` (like [Moment.js](http://momentjs.com/)) method are converted to a regular Date object.\n\n### duration.subtractFrom(Date)\nSubtract the duration from a Date object and returns the new date. Objects with a `.toDate()` method are converted to a regular Date object.\n\n### duration.add(Duration)\nAdd durations together returning a new duration which is the sum of both.\n\n### duration.multiply(number)\nMultiply individual parts of duration returning a new duration as the result.\n\n### duration.toString()\nConvert a duration to a string in ISO 8601 format.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmhg%2Fdate-duration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmhg%2Fdate-duration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmhg%2Fdate-duration/lists"}