Giter VIP home page Giter VIP logo

human-interval's Introduction

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

human-interval's People

Contributors

capacitorset avatar niftylettuce avatar omgimalexis avatar renovate-bot avatar renovate[bot] avatar rschmukler avatar sampathblam avatar simison avatar theabstractdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

human-interval's Issues

Add support for workdays?

Having support for "workdays" would be awesome, to skip the weekends. We can use this to trigger deadlines, without taking the weekends into account.

agenda.schedule('3 workdays');

Transfer to Agenda org?

I know this package is really low maintenance but what do you think about moving this under Agenda org? Since that package quite heavily relies on this, it would be good to have push rights among same devs.

does it work if I use like this?

instead of calling days gitlab api uses "d"
example

human_time = 1d

and I want convert that 1d to timestamp so I can use datefns to add to other date or something like that, can I do that? does it recognize if write d instead of days?

Use something like `node-numbered` to convert words in numbers

Hello @rschmukler ,

To support more word numbers, instead of adding more data, we could use something like node-numbered to do this and remove some code from the project while extending it's support. Would you be accepting such contribution? What do you think?

I suppose, to use that there needs to be a little bit of refactoring on how the code works. I'm thinking we could instead use the following algorithm:

  1. Find the units in the string and split the string using them.
  2. Pass the remaining strings to node-numbered which will convert them to numbers.
  3. Process it and calculate the total.

Days week

Can you pass the days of the week with the time?

Example:

Wednesday at 10:12AM

(potential) bug with agenda.schedule

when working with agenda I ran into the following issue:

// works perfectly fine
agneda.every('90 seconds')
agenda.every('1.5 minutes')
agenda.every('1 minute and 30 seconds')
// works perfectly fine
agenda.schedule('in 90 seconds')
// does not work
// no error is thrown, the time saved in the database is incorrect though
agenda.schedule('in 1.5 minutes')
agenda.schedule('in 1 minute and 30 seconds')

I am not sure whether this is an rather a missing feature than a bug, it's definitely not expected, unintuitive

thanks a lot @rschmukler for your work on agenda and human-interval - it is an pleasure to use!

Conflicting issues in running ava tests locally and in travis-ci

I recently cloned the repo, made some changes and tried to run the tests locally using the test script in package.json.

When I ran the test using npm run test locally, it gave me an error
. import should occur before import of ava import/order

Hence I changed the order of the import statements in test.js (Moved import off ava below import of .)

But when I submitted a PR, the travis-ci build failed stating the reason -
ava import should occur before import of .

Is there something we can do to make this uniform? Or am I missing something here?

EVERYDAY vs Every day

If I enter everyday as an interval in agenda, it schedules jobs every second.
Similar behavior is not seen with every day.
Not sure if I am doing something wrong here.

What about compact strings like '10s' ?

For config files it could be useful to have support for inputs like '10s' (for '10 seconds').

Currently it returns a TypeError: Cannot read property '1' of null.

Localize seconds/hours/and/etc.

It's useful that the numbers can be localized, however it would also be important to support localizing the names of the units and the separators.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.