Time 0.1
This class provides a rails like syntax for stating times - such as 4..days().ago() - for creating dates.
Details
- Author
- Arieh Glazer
- Current version
- 0.1
- GitHub
- arieh/Time
- Downloads
- 849
- Category
- Utilities
- Tags
- Report
- GitHub Issues
How to use
Time
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:
- seconds
- minutes
- hours
- days
- weeks
- months
- years
Note that all rage methods return Date instances.
Number.Time
The package adds the range methods to the Number prototype, like it works on rails. So you can do
4..days().from_now(); 20..months().ago();
Notice the double dot notation - it is required so that JS will know you aren't using the decimal point
Date.time
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
Options
Events
Discuss
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