Skip to content

Repository files navigation

Tiny Human Time

A tiny module for human readable timespans.

GitHub Actions Workflow Status

API

humanize(t1, t2 [, units])

What you get when you require('tiny-human-time').

t1 and t2 are instances of Date or integers whose value relative to one another is given in milliseconds. Their order doesn't matter.

If t2 is not given, t1 alone will be used as the timespan relative to 0.

Either argument can be an array of the form [seconds, nanoseconds], like that produced by process.hrtime().

An optional last argument, units has possible values short and long, defaulting to long. units can be given as the last argument even if t2 is not given.

Returns the converted value and the greatest matching unit without going over. For example, 23 hours will be followed by 1 day.

humanize.short(t1, t2)

A convenience method to use short units. The possible arguments for t1 and t2 are the same as humanize.

Supports:

  • nanoseconds
  • microseconds
  • milliseconds
  • seconds
  • minutes
  • hours
  • days
  • weeks
  • years

Usage

consthumanize=require('tiny-human-time');constnow=newDate(2016,3,5);constlater=newDate(2016,3,6);humanize(now,later);// => 1 day
consthumanize=require('tiny-human-time');conststart=process.hrtime()// and then a miracle occursconstelapsed=process.hrtime(start)humanize(elapsed)// => 23 microseconds
consthumanize=require('tiny-human-time').short;humanize(1)// => 1ms

About

A tiny module for human readable timespans.

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages