Giter Club home page Giter Club logo

timerizerjs's Introduction

TimerizerJS Build Status

A neat little utility for working with relative times in JavaScript.

(2).days.ago(); // Sat Jan 03 2015 18:00:00 GMT+0000 (GMT)

Neat.

I stole the name from Timerizer, which is written in Ruby and based on Ruby on Rails' ActiveSupport, which is also what this was based on.

Installation

Either download the repo and just include timerizer.js or build/timerizer.min.js into your project (using AMD, CommonJS or just good old globals), or install through npm using npm install timerizer.

Usage

There are two main ways to call Timerizer; you can either use the Timerizer constructor function, or you can call one of the time methods directly on number objects.

Timerizer(4).weeks.ago();

// Or you can call it directly on numbers
(4).weeks.ago();

This does involve adding a load of properties to Number.prototypeโ€”if this concerns you, there will be a way to disable that behaviour soon.

Time methods

Time methods are the ones you call on the number, and are specifying the type of interval of time.

The available time methods are seconds, minutes, hours, days, weeks, and fortnights. There are also singular versions of all those methods.

(4).seconds.ago();
(10).hours.ago();
(1).fortnight.ago();

Calculation methods

(I don't like this name. Feel free to suggest better.)

The calculation methods are four methods used to get the actual Date object.

In the past

We've met one of these already, the .ago() method. The following will return a Date object for four hours ago:

(4).hours.ago();

Pretty simple. You can also give it an argument containing a time to generate the Date from: e.g., you can specify that you want the time two hours before a given time. That doesn't make much sense as the ago method, so there is an until method aliased to ago:

(4).hours.until(myTime);

In the future

The two methods for getting times in the future are called fromNow and since, and they behave in pretty much the same way that the methods for getting times in the past do.

(4).hours.fromNow();
(4).hours.since(myTime);

Developing

If you want to contribute (thank you!), you'll need to clone the repository and install the dependencies using npm install. Run the tests before sending a pull request (npm test), and try to avoid sending a pull request from the master branch.

License

This library is released under an MIT license.

timerizerjs's People

Contributors

callumacrae avatar

Stargazers

Stefan Keim avatar William Jacoby avatar Mohamed Meabed avatar  avatar Kfwebdev avatar Sebastian Schubotz avatar Daniel Grant avatar Dudley Storey avatar Stefan Bohacek avatar Cristian avatar Zach Wolfe avatar

Watchers

 avatar James Cloos avatar

timerizerjs's Issues

oldIE

  • Date.now()
  • Object.observe()

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.