Giter Club home page Giter Club logo

milliseconds's Introduction

milliseconds

Insanely lightweight module for converting times to milliseconds.

Literally 9 lines of code, it's just to make writing time in a way that's more readable without having to remember how many milliseconds are in a day, week, month, year.

For those curious, the exact definition of "years" and "months" can vary slighly but these are based on the Julian Year which is 365.25 days of 86400 seconds (http://en.wikipedia.org/wiki/Year) and a month is simply 1/12th of that.

install

npm install milliseconds

example

var ms = require('milliseconds');

ms.seconds(2); // 2000
ms.minutes(2); // 120000
ms.hours(2);   // 7200000
ms.days(2);    // 172800000
ms.weeks(2);   // 1209600000
ms.months(2);  // 5259600000
ms.years(2);   // 63115200000

credits

If you like this follow @HenrikJoreteg on twitter.

license

MIT

milliseconds's People

Contributors

albemuth avatar henrikjoreteg 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

Watchers

 avatar  avatar

milliseconds's Issues

thank you, this script is awesome

I use this milliseconds package frequently like this,

import msfrom from 'milliseconds';

// ...later
await setTimeout( msfrom.seconds( 30 ) )

This package helps me to work with others who use units of time other than milliseconds. I don't create "custom code" that would annoy those people but instead import this package. Thank you :)

use chaining for additions

would you consider doing this :

ms.years(2)  // ms instance
  .months(6) // ms instance
  .valueOf() // 78894000000

?

Feature request: milliseconds.toSeconds

This library is great! The only thing I find myself missing is a milliseconds.toSeconds function that I could use to:

  • Convert a JS timestamp (milliseconds since epoch) into a unix timestamp (seconds since epoch)
  • Pass values to third-party-library functions which expect seconds instead of milliseconds.
// example usage
console.log({
  'a unix timestamp': milliseconds.toSeconds(Date.now()),
  'do this in 15 minutes': milliseconds.toSeconds(milliseconds.minutes(15)),
});

This function compliments this library nicely but is so small that it doesn't really warrant its own library. What do you think? Is it related enough to "mess with perfection" and add it to this library?

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.