This class provides a rails like syntax for stating times - such as 4..days().ago() - for creating dates.
- _self_/_current_: core/1.2.4 : [Class, Object]
How to use
The package contains 3 tools - Time - a generic class for creating dates. Usage is as follows:
var time = new Time(4); time.days().ago(); //4 days ago time.years().from_now(); //4 years from now
The class also accepts a second argument - a date. If supplied, it will use it as it's origin (see more at the Docs). For changing the count, you can supply it as an argument for the range method -
time.days(20).ago(); //20 days ago
The available ranges are:
Note that all rage methods return Date instances.
The package adds the range methods to the Number prototype, like it works on rails. So you can do
Notice the double dot notation - it is required so that JS will know you aren't using the decimal point
Lastly, the package adds it's syntax to the date prototype. In order for it to work you must supply a counter for the range methods:
var d = new Date(); d.days(3).ago(); //3 days from that date 5..days().ago().weeks(3).from_now(); //3 weeks from 5 days ago
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.blog comments powered by Disqus