{"id":20428248,"url":"https://github.com/imranbarbhuiya/duration","last_synced_at":"2025-04-12T19:22:47.569Z","repository":{"id":37019664,"uuid":"451071159","full_name":"imranbarbhuiya/duration","owner":"imranbarbhuiya","description":"A small and fast utility to convert milliseconds to human-readable string or vice versa.","archived":false,"fork":false,"pushed_at":"2025-04-09T18:50:50.000Z","size":15134,"stargazers_count":4,"open_issues_count":5,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T19:43:38.491Z","etag":null,"topics":["date","duration","formatter","hacktoberfest","ms","parse","time"],"latest_commit_sha":null,"homepage":"https://duration.js.org","language":"TypeScript","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/imranbarbhuiya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["imranbarbhuiya"]}},"created_at":"2022-01-23T10:32:51.000Z","updated_at":"2025-03-09T05:48:57.000Z","dependencies_parsed_at":"2023-09-24T09:27:09.955Z","dependency_job_id":"1a83e702-5b56-46e8-ac60-b51e5553b757","html_url":"https://github.com/imranbarbhuiya/duration","commit_stats":{"total_commits":324,"total_committers":8,"mean_commits":40.5,"dds":0.5833333333333333,"last_synced_commit":"3de5d0d778a75bcdad7093d0b5e7e7db6b3909f1"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imranbarbhuiya%2Fduration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imranbarbhuiya%2Fduration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imranbarbhuiya%2Fduration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imranbarbhuiya%2Fduration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imranbarbhuiya","download_url":"https://codeload.github.com/imranbarbhuiya/duration/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248619102,"owners_count":21134347,"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","formatter","hacktoberfest","ms","parse","time"],"created_at":"2024-11-15T07:24:48.737Z","updated_at":"2025-04-12T19:22:47.539Z","avatar_url":"https://github.com/imranbarbhuiya.png","language":"TypeScript","funding_links":["https://github.com/sponsors/imranbarbhuiya","https://www.buymeacoffee.com/parbez","https://ko-fi.com/Y8Y1CBIJH'"],"categories":[],"sub_categories":[],"readme":"# Duration\n\n[![npm](https://img.shields.io/npm/dw/@imranbarbhuiya/duration)](https://www.npmjs.com/package/@imranbarbhuiya/duration)\n[![codecov](https://codecov.io/gh/imranbarbhuiya/duration/branch/main/graph/badge.svg)](https://codecov.io/gh/imranbarbhuiya/duration)\n[![npm](https://img.shields.io/npm/v/@imranbarbhuiya/duration?color=crimson\u0026logo=npm\u0026style=flat-square)](https://www.npmjs.com/package/@imranbarbhuiya/duration)\n\nA small and fast time utility which makes working with time, duration, date super easy. It contains a number of useful small utility methods to work with time and date.\n\n## Documentation\n\nRead Full Documentation [here](https://duration.js.org/).\n\n## Install\n\n```bash\n# npm\nnpm i @imranbarbhuiya/duration\n\n# yarn\nyarn add @imranbarbhuiya/duration\n\n```\n\n## Usage\n\n### esm or Typescript\n\n```ts\nimport { parse, format, prettyFormat, date, relativeTime, Formatter } from '@imranbarbhuiya/duration';\n```\n\n### CommonJS\n\n```js\nconst { parse, format, prettyFormat, date, relativeTime, Formatter } = require('@imranbarbhuiya/duration');\n```\n\n### parse\n\n```js\n// string =\u003e number\nparse('1s 1min 1h 1d 1w 1mo 1y'); // 34844461001\nparse('2 days'); //=\u003e 172800000\nparse('1d'); //=\u003e 86400000\nparse('-3 days'); //=\u003e -259200000\n```\n\n### format\n\n```js\n// number =\u003e string\nformat(2 * 60000); //=\u003e 2m\nformat(-3 * 60000, { long: true }); //=\u003e -3 minutes\nformat(parse('10 hours'), { long: true }); //=\u003e 10 hours\n```\n\n### prettyFormat\n\n```js\n// number to string (multiple units)\nprettyFormat(60000); //=\u003e 1 minute\nprettyFormat(121000); //=\u003e 2 minutes, 1 second\nprettyFormat(1000 * 60 * 60 * 60 * 24 * 30, { format: 'short' }); //=\u003e 1mo\nprettyFormat(86406010, {\n\tformat: 'short',\n\tpatterns: ['hour', 'minute', 'second', 'millisecond'],\n\tseparator: ' '\n}); //=\u003e 24h 6s 10ms\n```\n\nWriting these patterns every time is a pain. That's why there is a Formatter class which can be used to format multiple times without repeating yourself.\n\n### Formatter\n\n```js\nconst formatter = new Formatter({\n\tformat: 'short',\n\tpatterns: ['hour', 'minute', 'second', 'millisecond'],\n\tseparator: ' '\n});\n\nformatter.format(1000 * 60 * 60 * 24 * 30); //=\u003e 720h\nformatter.format(86406010); //=\u003e 24h 6s 10ms\n```\n\n### date\n\n```js\n// format a date\ndate('2022-01-01', 'YYYY-MMM-Do'); //=\u003e 2022-Jan-Saturday\ndate('2022-01-01T00:00:00.000Z', 'yyyy-MM-D HH:mm:ss.SS Z'); //=\u003e 2022-01-1 00:00:00.00 0\ndate('2022-01-01T00:00:00.000Z', 'yyyy-MMMM-DDD HH:mm:ss.SS'); //=\u003e 2022-January-Sat 00:00:00.00\n```\n\n### relativeTime\n\n```js\n// format a date as relative date\nrelativeTime(Date.now() + 1000); //=\u003e in a few seconds\nrelativeTime(Date.now() - 1000 * 60 * 60); //=\u003e an hour ago\n```\n\n## Buy me some doughnuts\n\nIf you want to support me by donating, you can do so by using any of the following methods. Thank you very much in advance!\n\n\u003ca href=\"https://www.buymeacoffee.com/parbez\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"41\" width=\"174\"\u003e\u003c/a\u003e\n\u003ca href='https://ko-fi.com/Y8Y1CBIJH' target='_blank'\u003e\u003cimg height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi4.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /\u003e\u003c/a\u003e\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/imranbarbhuiya\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/74945038?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eParbez\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/imranbarbhuiya/duration/commits?author=imranbarbhuiya\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#maintenance-imranbarbhuiya\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"#ideas-imranbarbhuiya\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://renovate.whitesourcesoftware.com\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/25180681?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eWhiteSource Renovate\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-renovate-bot\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimranbarbhuiya%2Fduration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimranbarbhuiya%2Fduration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimranbarbhuiya%2Fduration/lists"}