Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

human-interval

agenda798.1kMIT2.0.1TypeScript support: included

Human readable time measurements

interval, time, date

readme

Human Interval

Human-readable interval parser for Javascript.

Converts words written in English to numbers by using node-numbered.

Originally inspired by matthewmueller/date.

Uses

Human Interval is used by job scheduling libraries such as Agenda and Bree. They are a job schedulers for Node.js with cron expression syntax, human-friendly times, Dates, and more!

Example usage

const humanInterval = require('human-interval');

setTimeout(() => {
  // Do something!
}, humanInterval('three minutes'));

More sophisticated examples

Human Interval understands all of the following examples:

humanInterval('minute');
humanInterval('one minute');
humanInterval('1.5 minutes');
humanInterval('3 days and 4 hours');
humanInterval('3 days, 4 hours and 36 seconds');
humanInterval('4 months, 3 days, 5 hours and forty-five seconds');

The full list

Units

Supports the following units in the plural and singular forms:

  • seconds
  • minutes
  • hours
  • days
  • weeks
  • months — assumes 30 days
  • years — assumes 365 days

Wordy numbers

Supports numbers being written out in English words.

humanInterval('five minutes');

Hyphenated numbers

Supports hyphenated numbers.

humanInterval('twenty-five seconds');

Negative numbers

Supports negative numbers if the time starts with a - symbol immediately followed by a number.

humanInterval('-2 minutes');

License

The MIT License

changelog

2.0.1 / 2021-01-16

  • Export types (#43)
  • Updated deve dependencies.

2.0.0 / 2020-10-16

  • Refactor human interval using numbered package. Thank you @sampathBlam and @alFReD-NSH for your contributions!
    • Supports all the formats as previously, and more!
    • Supports numbers written as English words (one, two hundred)
    • Supports time expressions in singular and plural (minute and minutes)
    • Supports negative numbers (-2)
    • Supports hyphenated words (twenty-five)
  • Updated dev dependencies.
  • Added more tests.

Breaking

  • Stopped testing Node.js 8 — might still work of course. We're now testing for Node.js v10, v12, and v14.

1.0.0 / 2019-11-24

Breaking

Internal development tooling

0.1.6 / 2016-05-11

  • Fix bug for invalid input strings.

0.1.5 / 2015-07-30

  • Fixed a bug with commas, all tests are now passing.

0.1.4 / 2014-04-06

  • Add support for number omission.

0.1.3 / 2014-01-04

  • Added support for months.

0.1.2 / 2014-01-03

  • Added support for 'week' unit.

0.1.1 / 2013-10-28

  • Added better undefined handling.

0.1.0 / 2013-10-25

  • Initial Release.