todate
v0.0.7
Published
Utility object for formatting dates and manipulating date objects in JavaScript.
Downloads
7
Readme
todate.js
todate.js is a utility module which provides methods for manipulating JavaScript date objects.
##Method
Initialize a date object.
- When the argument is empty, it will return the date object with current system time (for example today is May 9, 2013).
Example:
dateUtils.date().print('yyyy-mm-dd-day');
Result:
2013-4-9-4
- When the argument is not empty, it will return the data object with the time and format getting from the object. The data can come as any format as you like, as long as the month comes as an English Word(or first three letters) and it uses the same separator. If the format is not specified, the system will set the format to default (yyyy mm dd).
Example:
dateUtils.date({'format': 'mm dd yyyy', 'dateIn': 'May 13, 2013'}).print('');
dateUtils.date({'format': 'mm-yyyy', 'dateIn': 'May-2013'}).print('');
dateUtils.date({'format': 'dd/mm/yyyy', 'dateIn': '13/January/2013'}).print('');
dateUtils.date({'dateIn': '13/jan/2013'}).print('');
Result:
4 13 2013
4-2013
13/0/2013
2013 1 13
If the argument is empty, return the time string based on its original format. If the argument is not empty, return the time string based on the argument as the new format.
Example:
dateUtils.date({'format': 'mm yyyy', 'dateIn': 'December 2012'}).print();
dateUtils.date({'format': 'mm dd yyyy', 'dateIn': 'December 25, 2012'}).print('yyyy/dd/mm');
Result:
11 2012
2012/25/11
Take a integer number and return a string month.
Example:
dateUtils.date().n2m(); //return the month of current system time
dateUtils.date().n2m(7);
Result:
may
aug
Take a month string and return an integer value.
Example:
dateUtils.date().m2n('DEC')
Result:
11
Set the number as the new year of the date object.
Example:
var today = dateUtils.date();
today.setYear(2010).print();
Result:
2010-4-9
Set the number as the new month of the date object.
Example:
today.setMonth(10).print();
Result:
2010-10-9
Set the number as the new day of the date object.
Example:
today.setDate(23).print();
Result:
2010-10-23
Return the year of the date object.
Example:
today.getYear();
Result:
2010
Return the month of the date object.
Example:
today.getMonth();
Result:
10
Return the day of the date object.
Example:
today.getDate();
Result:
23
If the given date is greater than the new date, return true; otherwise return false.
Example:
dateUtils.date({ 'dateIn': 'september 18, 2012'}).gt(dateUtils.date({'dateIn': 'december 19, 2011'}))
Result:
true
If the given date is greater than the new date, return true; otherwise return false.
Example:
t.equal(dateUtils.date({ 'dateIn': 'september 18, 2012'}).lt(dateUtils.date({'dateIn': 'december 19, 2011'}))
Result:
false
If the given date is greater than the new date, return true; otherwise return false.
Example:
dateUtils.date({ 'dateIn': 'september 18, 2012'}).eq(dateUtils.date({'dateIn': 'september 18, 2012'}))
Result:
true
If the given date is greater than or equal to the new date, return true; otherwise return false.
If the given date is lower than or equal to the new date, return true; otherwise return false.
If the given date is in the range between the start date and the end date, return true; otherwise return false.
Example:
dateUtils.date({'dateIn': [2011]}).inRange(dateUtils.date({'dateIn': [2010]}), dateUtils.date({'dateIn': [ 2013 ]}))
Result:
true
##Install
The source code is available for download from GitHub. Besides that, you can also install using Node Package Manager (npm):
npm install dates
##License
MIT