{"id":15697455,"url":"https://github.com/thk2b/time-convert","last_synced_at":"2025-08-07T21:06:29.390Z","repository":{"id":138601073,"uuid":"119921838","full_name":"thk2b/time-convert","owner":"thk2b","description":"Convert milliseconds to any format","archived":false,"fork":false,"pushed_at":"2018-02-03T04:15:48.000Z","size":22,"stargazers_count":7,"open_issues_count":2,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-09T01:06:29.074Z","etag":null,"topics":[],"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/thk2b.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-02T02:37:39.000Z","updated_at":"2024-12-06T01:25:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"162fcd80-ad48-4c82-825e-1100619bb6bc","html_url":"https://github.com/thk2b/time-convert","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thk2b%2Ftime-convert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thk2b%2Ftime-convert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thk2b%2Ftime-convert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thk2b%2Ftime-convert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thk2b","download_url":"https://codeload.github.com/thk2b/time-convert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253171254,"owners_count":21865292,"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-10-03T19:20:05.131Z","updated_at":"2025-05-09T01:06:34.137Z","avatar_url":"https://github.com/thk2b.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/time-convert.svg)](https://badge.fury.io/js/time-convert)\n[![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)\n\n# time-convert\n🕓 Convert durations to other time unit(s).\n\n# Usage\n`npm install time-convert`\n```js\nconst { ms, s, m, h, d } = require('time-convert')\n/* verbose equivalent */\nconst { milliseconds, seconds, minutes, hours, days } = require('time-convert') \n\n/* convert milliseconds to hours, minutes and seconds */\nms.to(h,m,s)(12345678) // [4, 2, 47]\n\n/* convert milliseconds to minutes and seconds */\nms.to(m,s)(12345678) // [242, 47]\n\n/* get milliseconds from 12 hours, 23 minutes, 45 seconds*/\nms.from(h,m,s)(12, 23, 45) // 44625000\n\n/* get hours from 123 minutes and 12 seconds */\nh.from(m,s)(123, 12) // 2.0533333333333332\n\n/* ⚠️ precision is lost */\nms.to(s)(1234) // [1] , not [1.234]\n```\n\nThe only restriction is that units must be in descending order of magnitude – avoid calling `ms.to(m, h, s)`.\n\n# Philosophy\n`time-convert` performs the convertion with the units you specify, but is agnostic as to what you want to do with the converted units.\n\nIt is encouraged that you create your own wrapper functions for you specific use-case. \nFor instance, to convert milliseconds to a `hh:mm:ss` format, you can write the following:\n\n```js\nconst msToHms = ms =\u003e (\n    ms.to(h,m,s)(ms)\n        .map(n =\u003e n \u003c 10? '0'+n : n.toString()) // zero-pad\n        .join(':')\n)\nmsToHms(12345678) // '04:02:47'\n```\n\n# Contributing\nContributions welcome.\n\nPossible additions:\n- Generalize to units other than time, such as distance, volume, or even currency using a 3rd party exchange-rate API.\nThis addition requires making sure that precision is not lost in operations. \n\n# Test\n`npm run test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthk2b%2Ftime-convert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthk2b%2Ftime-convert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthk2b%2Ftime-convert/lists"}