{"id":15366908,"url":"https://github.com/cupcakearmy/uhrwerk","last_synced_at":"2026-02-04T02:36:46.736Z","repository":{"id":96683116,"uuid":"177317801","full_name":"cupcakearmy/uhrwerk","owner":"cupcakearmy","description":"Time utility","archived":false,"fork":false,"pushed_at":"2024-07-29T13:13:21.000Z","size":75,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T18:09:58.544Z","etag":null,"topics":["duration","human-readable","interval","time","typescript"],"latest_commit_sha":null,"homepage":"","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/cupcakearmy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"cupcakearmy"}},"created_at":"2019-03-23T17:14:00.000Z","updated_at":"2024-07-29T13:16:01.000Z","dependencies_parsed_at":"2024-10-16T08:40:58.470Z","dependency_job_id":null,"html_url":"https://github.com/cupcakearmy/uhrwerk","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":"0.46153846153846156","last_synced_commit":"c9514fa0aa5083dd44d0d1edbe544853b986d49a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fuhrwerk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fuhrwerk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fuhrwerk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cupcakearmy%2Fuhrwerk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cupcakearmy","download_url":"https://codeload.github.com/cupcakearmy/uhrwerk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246642157,"owners_count":20810554,"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":["duration","human-readable","interval","time","typescript"],"created_at":"2024-10-01T13:20:14.675Z","updated_at":"2026-02-04T02:36:46.694Z","avatar_url":"https://github.com/cupcakearmy.png","language":"TypeScript","funding_links":["https://github.com/sponsors/cupcakearmy"],"categories":[],"sub_categories":[],"readme":"# uhrwerk 🕰\n\n![package size](https://img.shields.io/bundlephobia/min/uhrwerk?style=flat)\n![downloads badge](https://img.shields.io/npm/dt/uhrwerk)\n![types badge](https://img.shields.io/npm/types/uhrwerk)\n![version badge](https://img.shields.io/npm/v/uhrwerk)\n\nMinimal time duration utility. Replacement for MomentJS Durations. If you are looking into the time component of MomentJS check out this awesome library [dayjs](https://github.com/iamkun/dayjs).\n\n📦 It's **tiny**: [2kB](https://bundlephobia.com/package/uhrwerk@latest) vs moment js [295kB](https://bundlephobia.com/result?p=moment@latest)\n\n🌈 No dependencies, types included.\n\n## Quickstart 🚀\n\n```typescript\nimport { Duration } from 'uhrwerk'\n\nconst d = new Duration(10, 'days')\nd.subtract(1, 'week')\nd.add(5, 'minutes')\n\nd.humanize() // '3 days'\nd.minutes() // 5\nd.asMinute() // 4325\n\nd.subtract(3, 'days')\nd.humanize() // 'a few minutes'\n```\n\n### Reference 📒\n\n#### `new Duration(amount, interval)`\n\n- amount: number\n- interval:\n  - millisecond, milliseconds, ms\n  - second, seconds, s\n  - minute, minutes, m\n  - hour, hours, h\n  - day, days, d\n  - week, weeks, w\n  - year, years, y\n\n###### Examples\n\n```javascript\nconst a = new Duration(1, 'day')\nconst b = new Duration(2, 'days')\nconst c = new Duration(0.5, 'year')\nconst d = new Duration(Date.now(), 'ms')\n```\n\n#### `.add(amount, interval)`\n\nAdds a specified amount to an existing duration\n\n###### Example\n\n```javascript\nconst a = new Duration(1, 'day')\na.add(12, 'hours')\na.asHour() // 36\n```\n\n#### `.subtract(amount, interval)`\n\nSubtracts a specified amount to an existing duration\n\n###### Example\n\n```javascript\nconst a = new Duration(1, 'day')\na.subtract(12, 'hours')\na.asHour() // 12\n```\n\n#### Getters\n\nGets the amount of time interval, not the total time\n\n- `.milliseconds()`\n- `.seconds()`\n- `.minutes()`\n- `.hours()`\n- `.days()`\n- `.weeks()`\n- `.years()`\n\n###### Example\n\n```javascript\nconst a = new Duration(1, 'day')\na.days() // 1\na.add(5, 'minutes')\na.days() // 1\na.add(1, 'year')\na.days() // 1\na.add(24, 'hours')\na.days() // 2\n```\n\n#### As interval\n\nCalculates the time duration as a time interval.\n\n- `.asMilliseconds()`\n- `.asSeconds()`\n- `.asMinutes()`\n- `.asHours()`\n- `.asDays()`\n- `.asWeeks()`\n- `.asYears()`\n\n###### Example\n\n```javascript\nconst a = new Duration(1, 'day')\na.asHours() // 24\n```\n\n#### `.humanize()`\n\nThis functions takes a duration and tries to make a human readable version out of it.\n\n###### Example\n\n```javascript\nconst a = new Duration(4, 'seconds')\na.humanize() // 'a moment'\na.add(5, 'minutes')\na.humanize() // 'a few minutes'\n```\n\n##### Own rules / i18n\n\nIf you want to pass a different humanize function you can.\nThe order of the array is important. The first match will return, like in a standard server router. The first argument is a function that takes the duration and returns a boolean. The second takes also matched duration and returns a string for the user.\n\n###### Example\n\n```javascript\nconst humanizer = [\n  [(d) =\u003e d.days() \u003e 1, (d) =\u003e `${d.days()} days`],\n  [(d) =\u003e d.days() \u003e 0, (d) =\u003e `1 day`],\n  [() =\u003e true, () =\u003e 'catch all, below 1 day'],\n]\n\nconst a = new Duration(2, 'days')\na.humanize(humanizer) // '2 days'\na.subtract(1, 'day')\na.humanize(humanizer) // '1 day'\na.subtract(12, 'hours')\na.humanize(humanizer) // 'catch all, below 1 day'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcupcakearmy%2Fuhrwerk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcupcakearmy%2Fuhrwerk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcupcakearmy%2Fuhrwerk/lists"}