todate

0.0.7 • Public • Published

todate.js

todate.js is a utility module which provides methods for manipulating JavaScript date objects.

Method

### date(argument)

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
### print(argument)

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
### n2m(number)

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
### m2n(string)

Take a month string and return an integer value.

Example:

dateUtils.date().m2n('DEC')

Result:

11
### setYear(number)

Set the number as the new year of the date object.

Example:

var today = dateUtils.date();
today.setYear(2010).print();

Result:

2010-4-9
### setMonth(number)

Set the number as the new month of the date object.

Example:

today.setMonth(10).print();

Result:

2010-10-9
### setMonth(number)

Set the number as the new day of the date object.

Example:

today.setDate(23).print();

Result:

2010-10-23
### getYear()

Return the year of the date object.

Example:

today.getYear();

Result:

2010
### getMonth()

Return the month of the date object.

Example:

today.getMonth();

Result:

10
### getDate()

Return the day of the date object.

Example:

today.getDate();

Result:

23
### gt(newDateObject)

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
### lt(newDateObject)

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
### eq(newDateObject)

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
### ge(newDateObject)

If the given date is greater than or equal to the new date, return true; otherwise return false.

### ge(newDateObject)

If the given date is lower than or equal to the new date, return true; otherwise return false.

### inRange(startDateObject, endDateObject)

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

Readme

Keywords

Package Sidebar

Install

npm i todate

Weekly Downloads

0

Version

0.0.7

License

MIT

Last publish

Collaborators

  • rranauro