1.5.0 • Published 7 years ago

timeto v1.5.0

Weekly downloads
5
License
ISC
Repository
github
Last release
7 years ago

timeTo

A tiny utility to convert time to another unit

Installation

$ npm install timeto

Usage

Supported time units:

  • y - Year (defined as 365.25 days)
  • d - Day
  • h - Hours
  • m - Minutes
  • s - Seconds
  • ms - Milliseconds
timeTo(
  '1d12h', // a string for the input time
  'ms'     // output value for the time period (defaults to ms)
)

It can also take an object of shape { /* time unit */ h: 12 /* amount */ }

timeTo(
  { d: 1, h: 12 }, // an object specifying the duration
  'm'              // output value for the time period (defaults to ms)
)

Alternatively you can pass a number as the input specified as a time period in milliseconds and return it in another duration

timeTo(
  86400000, // a number in milliseconds for the input time
  'm'       // output value for the time period (defaults to ms)
)

Returns a number that is the input time duration in terms of the output time unit specified

Example

const timeTo = require('timeto')

const msValue = timeTo('1d12h' /* 1 day 12 hours */, 'ms')

console.log(msValue) // 129600000

Additional notes

  • Time units must be lowercase
  • Months are not supported since they fluctuate in duration
1.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago