{"id":21177455,"url":"https://github.com/betsol/time-delta","last_synced_at":"2025-07-09T22:30:44.920Z","repository":{"id":29926239,"uuid":"33472311","full_name":"betsol/time-delta","owner":"betsol","description":"Formats difference between two dates as a human-readable string in almost any language","archived":false,"fork":false,"pushed_at":"2023-09-24T18:05:39.000Z","size":441,"stargazers_count":12,"open_issues_count":11,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-28T20:19:31.495Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/betsol.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2015-04-06T07:56:01.000Z","updated_at":"2024-10-25T10:58:49.000Z","dependencies_parsed_at":"2024-06-19T04:24:33.854Z","dependency_job_id":null,"html_url":"https://github.com/betsol/time-delta","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/betsol/time-delta","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Ftime-delta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Ftime-delta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Ftime-delta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Ftime-delta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/betsol","download_url":"https://codeload.github.com/betsol/time-delta/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betsol%2Ftime-delta/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263758056,"owners_count":23506807,"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":[],"created_at":"2024-11-20T17:16:10.687Z","updated_at":"2025-07-09T22:30:44.360Z","avatar_url":"https://github.com/betsol.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Time Delta\n\n[![npm version](https://badge.fury.io/js/time-delta.svg)][repo-npm]\n[![Build Status](https://api.travis-ci.com/betsol/time-delta.svg?branch=master)][travis]\n[![CodeClimate maintainability](https://api.codeclimate.com/v1/badges/cbfb83afc478ed41797a/maintainability)][code-climate]\n\nFormats difference between two dates as a human-readable string in almost any language.\n\n## Example Output\n\n- 2 hours, 17 minutes\n- 2 hr, 17 min, 10 sec\n- 2h 17m 10s\n- 1 yr, 4 mths\n- 1 year, 4 months, 2 weeks, 5 days, 17 hours, 10 minutes, 10 seconds\n- 2 часа; 17 минут; 10 секунд\n\n\n## Features\n\n- Supports 789 locales by means of [CLDR][lib-cldr] (built-in). See the [full list][locales]\n- Provides three different time unit formats for each locale: `long`, `short`, `narrow`\n  (when supported by specific CLDR locale)\n- Falls back to another unit type format if preferred one is not present in the target locale\n- Supports both Node.js and browser environments\n- All formatting aspects are customizable\n- TypeScript support out of the box\n- Minimal possible production dependencies\n\n\n## Install\n\n`npm install --save time-delta`\n\n\n## Usage\n\n### Node.js\n\nIn Node.js environment library will load requested locales automatically.\n\n```js\nconst timeDelta = require('time-delta');\n\nconst instance = timeDelta.create({\n  locale: 'en', // default\n});\n\nconst date1 = new Date('2015-04-01T21:00:00');\nconst date2 = new Date('2015-04-01T23:17:10');\n\n// Outputs: \"2 hours, 17 minutes\".\nconsole.log(instance.format(date1, date2));\n\n```\n\n### Browser\n\nIn Browser environment you will need to load each locale manually.\nThis ensures minimal size of your application bundle.\n\n```js\n// Importing the library\nimport * as timeDelta from 'time-delta';\n\n// Importing locales that you want to use\nimport enLocale from 'time-delta/locales/en';\nimport ruLocale from 'time-delta/locales/ru';\n\n// Registering locale\ntimeDelta.addLocale(enLocale);\n\n// You can register multiple locales\ntimeDelta.addLocale([enLocale, ruLocale]);\n\n// Creating an instance\nconst instance = timeDelta.create({\n  locale: 'en', // default\n});\n\nconst date1 = new Date('2015-04-01T21:00:00');\nconst date2 = new Date('2015-04-01T23:17:10');\n\n// Outputs: \"2 hours, 17 minutes\".\nconsole.log(instance.format(date1, date2));\n\n```\n\n\n## Configuration\n\nThe library accepts the following [configuration object][config]:\n\n| Option              | Type      | Default                       | Description\n|---------------------|-----------|-------------------------------|-------------\n| locale              | `string`  | `'en'`                        | Locale to use. See the [full list][locales]\n| span                | `integer` | `2`                           | How much time units to include in the result\n| delimiter           | `string`  | `', '`                        | Delimiter to use between time units\n| unitType            | `string`  | `'long'`                      | Unit type format. One of `long`, `short` or `narrow`\n| unitTypeLookupOrder | `array`   | `['long', 'short', 'narrow']` | Unit type lookup order (used for fallback)\n| autoloadLocales     | `boolean` | `true`                        | Whether to auto-load locales in Node.js environment (doesn't work in browsers)\n\nYou can pass config to factory method during instantiation:\n\n```js\nconst instance = timeDelta.create(config);\n```\n\nYou can also specify it when calling the `format()` function:\n\n```js\ninstance.format(date1, date2, config);\n```\n\nInstance-level config is automatically inherited when calling `format()`,\nso you can customize the defaults.\n\n\n## Changelog\n\nPlease see the [complete changelog][changelog] for list of changes.\n\n\n## Contributors\n\n- [Slava Fomin II](https://github.com/slavafomin) (author)\n\n\n## Contributing\n\nFork, clone, `npm install`.\n\n- Use `npm run build-locales` to download and build CLDR locales\n- Use `npm run test` to test the library\n\nIf you do a PR, make sure to cover it with [tests][tests].\n\n\n## Feedback\n\nIf you have found a bug or have another issue with the library —\nplease [create an issue][new-issue].\n\nIf you have a question regarding the library or it's integration with your project —\nconsider asking a question at [StackOverflow][so-ask] and sending me a\nlink via [E-Mail][email]. I will be glad to help.\n\nHave any ideas or propositions? Feel free to contact me by [E-Mail][email].\n\nCheers!\n\n\n## Support\n\nIf you like this library, consider to add star on [GitHub repository][repo-gh]\nand on [NPM][repo-npm].\n\nThank you!\n\n\n## License\n\nThe MIT License (MIT)\n\nⓒ 2015—2021 Slava Fomin II\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n\n  [changelog]: CHANGELOG.md\n  [contributors]: https://github.com/betsol/time-delta/graphs/contributors\n  [so-ask]: http://stackoverflow.com/questions/ask?tags=javascript,node.js,time,datediff\n  [email]: mailto:slava@fomin.io\n  [new-issue]: https://github.com/betsol/time-delta/issues/new\n  [locales]: docs/locales.md\n  [config]: https://github.com/betsol/time-delta/blob/master/lib/time-delta.js#L23\n  [tests]: test/tests.js\n  [lib-cldr]: https://github.com/papandreou/node-cldr\n  [repo-gh]: https://github.com/betsol/time-delta\n  [repo-npm]: https://www.npmjs.com/package/time-delta\n  [travis]: https://travis-ci.com/github/betsol/time-delta\n  [code-climate]: https://codeclimate.com/github/betsol/time-delta/maintainability\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetsol%2Ftime-delta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbetsol%2Ftime-delta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetsol%2Ftime-delta/lists"}