An open API service indexing awesome lists of open source software.

https://github.com/coderosh/string-time

Convert time string into seconds, minutes, hour, array or object
https://github.com/coderosh/string-time

Last synced: 7 months ago
JSON representation

Convert time string into seconds, minutes, hour, array or object

Awesome Lists containing this project

README

          

# 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

```sh
npm install @coderosh/string-time
```

Or via yarn

```sh
yarn add @coderosh/string-time
```

## Usage

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

### stringTime

```js
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

```js
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
```