@coderosh/string-time

Convert time string into seconds, minutes, hour, array or object and vice versa


Keywords
seconds, hours, minutes, string to time, time from string, human time, human time string
License
MIT
Install
npm install @coderosh/string-time@1.1.0

Documentation

string-time

Convert time string into seconds, minutes, hour, array or object and vice versa.

NPM MIT CI PRs welcome! Typescript

Installation

Install via npm

npm install @coderosh/string-time

Or via yarn

yarn add @coderosh/string-time

Usage

import stringTime, { reverse } from '@coderosh/string-time'

stringTime

const time = stringTime('1:59:60')

time.array // [ 2, 0, 0 ]
time.string // 02:00:00
time.object // { hour: 2, minute: 0, second: 0 }
time.totalHours // 2
time.totalMinutes // 120
time.totalSeconds // 7200

stringTime('').string // 00:00:00
stringTime(':1:').string // 00:01:00
stringTime('1').string // 01:00:00
stringTime('::1').string // 00:00:01

reverse

reverse({ second: 7200 }) // 02:00:00
reverse({ hour: 2 }) // 02:00:00
reverse({ minute: 120 }) // 02:00:00
reverse({ hour: 2, minute: 1, second: 0 }) // 02:01:00
reverse([2, 0, 1]) // 02:00:01