pax_global_header00006660000000000000000000000064134577507100014523gustar00rootroot0000000000000052 comment=8b24b37312fcdbc45d3db2cc772bfefac33e5104 parse-ms-2.1.0/000077500000000000000000000000001345775071000132525ustar00rootroot00000000000000parse-ms-2.1.0/.editorconfig000066400000000000000000000002571345775071000157330ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 parse-ms-2.1.0/.gitattributes000066400000000000000000000000231345775071000161400ustar00rootroot00000000000000* text=auto eol=lf parse-ms-2.1.0/.gitignore000066400000000000000000000000271345775071000152410ustar00rootroot00000000000000node_modules yarn.lock parse-ms-2.1.0/.npmrc000066400000000000000000000000231345775071000143650ustar00rootroot00000000000000package-lock=false parse-ms-2.1.0/.travis.yml000066400000000000000000000000641345775071000153630ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' - '6' parse-ms-2.1.0/index.d.ts000066400000000000000000000011241345775071000151510ustar00rootroot00000000000000declare namespace parseMilliseconds { interface Parsed { days: number; hours: number; minutes: number; seconds: number; milliseconds: number; microseconds: number; nanoseconds: number; } } /** Parse milliseconds into an object. @example ``` import parseMilliseconds = require('parse-ms'); parseMilliseconds(1337000001); // { // days: 15, // hours: 11, // minutes: 23, // seconds: 20, // milliseconds: 1, // microseconds: 0, // nanoseconds: 0 // } ``` */ declare function parseMilliseconds( milliseconds: number ): parseMilliseconds.Parsed; export = parseMilliseconds; parse-ms-2.1.0/index.js000066400000000000000000000011531345775071000147170ustar00rootroot00000000000000'use strict'; module.exports = milliseconds => { if (typeof milliseconds !== 'number') { throw new TypeError('Expected a number'); } const roundTowardsZero = milliseconds > 0 ? Math.floor : Math.ceil; return { days: roundTowardsZero(milliseconds / 86400000), hours: roundTowardsZero(milliseconds / 3600000) % 24, minutes: roundTowardsZero(milliseconds / 60000) % 60, seconds: roundTowardsZero(milliseconds / 1000) % 60, milliseconds: roundTowardsZero(milliseconds) % 1000, microseconds: roundTowardsZero(milliseconds * 1000) % 1000, nanoseconds: roundTowardsZero(milliseconds * 1e6) % 1000 }; }; parse-ms-2.1.0/index.test-d.ts000066400000000000000000000006221345775071000161300ustar00rootroot00000000000000import {expectType} from 'tsd'; import parseMilliseconds = require('.'); const parsed: parseMilliseconds.Parsed = parseMilliseconds(3000); expectType(parsed.days); expectType(parsed.hours); expectType(parsed.minutes); expectType(parsed.seconds); expectType(parsed.milliseconds); expectType(parsed.microseconds); expectType(parsed.nanoseconds); parse-ms-2.1.0/license000066400000000000000000000021251345775071000146170ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. parse-ms-2.1.0/package.json000066400000000000000000000011761345775071000155450ustar00rootroot00000000000000{ "name": "parse-ms", "version": "2.1.0", "description": "Parse milliseconds into an object", "license": "MIT", "repository": "sindresorhus/parse-ms", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=6" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "browser", "parse", "time", "ms", "milliseconds", "microseconds", "nanoseconds", "duration", "period", "range", "interval" ], "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" } } parse-ms-2.1.0/readme.md000066400000000000000000000013131345775071000150270ustar00rootroot00000000000000# parse-ms [![Build Status](https://travis-ci.org/sindresorhus/parse-ms.svg?branch=master)](https://travis-ci.org/sindresorhus/parse-ms) > Parse milliseconds into an object ## Install ``` $ npm install parse-ms ``` ## Usage ```js const parseMilliseconds = require('parse-ms'); parseMilliseconds(1337000001); /* { days: 15, hours: 11, minutes: 23, seconds: 20, milliseconds: 1, microseconds: 0, nanoseconds: 0 } */ ``` ## Related - [to-milliseconds](https://github.com/sindresorhus/to-milliseconds) - The inverse of this module - [pretty-ms](https://github.com/sindresorhus/pretty-ms) - Convert milliseconds to a human readable string ## License MIT © [Sindre Sorhus](https://sindresorhus.com) parse-ms-2.1.0/test.js000066400000000000000000000043771345775071000146020ustar00rootroot00000000000000import test from 'ava'; import parseMilliseconds from '.'; test('parse milliseconds into an object', t => { t.deepEqual(parseMilliseconds(1000 + 400), { days: 0, hours: 0, minutes: 0, seconds: 1, milliseconds: 400, microseconds: 0, nanoseconds: 0 }); t.deepEqual(parseMilliseconds(1000 * 55), { days: 0, hours: 0, minutes: 0, seconds: 55, milliseconds: 0, microseconds: 0, nanoseconds: 0 }); t.deepEqual(parseMilliseconds(1000 * 67), { days: 0, hours: 0, minutes: 1, seconds: 7, milliseconds: 0, microseconds: 0, nanoseconds: 0 }); t.deepEqual(parseMilliseconds(1000 * 60 * 5), { days: 0, hours: 0, minutes: 5, seconds: 0, milliseconds: 0, microseconds: 0, nanoseconds: 0 }); t.deepEqual(parseMilliseconds(1000 * 60 * 67), { days: 0, hours: 1, minutes: 7, seconds: 0, milliseconds: 0, microseconds: 0, nanoseconds: 0 }); t.deepEqual(parseMilliseconds(1000 * 60 * 60 * 12), { days: 0, hours: 12, minutes: 0, seconds: 0, milliseconds: 0, microseconds: 0, nanoseconds: 0 }); t.deepEqual(parseMilliseconds(1000 * 60 * 60 * 40), { days: 1, hours: 16, minutes: 0, seconds: 0, milliseconds: 0, microseconds: 0, nanoseconds: 0 }); t.deepEqual(parseMilliseconds(1000 * 60 * 60 * 999), { days: 41, hours: 15, minutes: 0, seconds: 0, milliseconds: 0, microseconds: 0, nanoseconds: 0 }); t.deepEqual(parseMilliseconds((1000 * 60) + 500 + 0.345678), { days: 0, hours: 0, minutes: 1, seconds: 0, milliseconds: 500, microseconds: 345, nanoseconds: 678 }); t.deepEqual(parseMilliseconds(0.000543), { days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 0, microseconds: 0, nanoseconds: 543 }); }); test('handle negative millisecond values', t => { const types = [ 'days', 'hours', 'minutes', 'seconds', 'milliseconds' ]; const times = [ 0.000500, 0.300, 100 + 400, 1000 * 55, 1000 * 67, 1000 * 60 * 5, 1000 * 60 * 67, 1000 * 60 * 60 * 12, 1000 * 60 * 60 * 40, 1000 * 60 * 60 * 999 ]; for (const milliseconds of times) { const positive = parseMilliseconds(milliseconds); const negative = parseMilliseconds(-milliseconds); for (const key of types) { t.is(negative[key], -positive[key]); } } });