3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('datatype-date-math', function(Y) {
10
* Parse number submodule.
13
* @submodule datatype-date-parse
18
Y.mix(Y.namespace("DataType.Date"), {
21
* Checks whether a native JavaScript Date contains a valid value.
24
* @param oDate {Date} Date in the month for which the number of days is desired.
25
* @return {Boolean} True if the date argument contains a valid value.
27
isValidDate : function (oDate) {
28
if(LANG.isDate(oDate) && (isFinite(oDate)) && (oDate != "Invalid Date") && !isNaN(oDate) && (oDate != null)) {
32
Y.log("Could not validate data " + LANG.dump(oDate) + " as type Date", "warn", "date");
37
areEqual : function (aDate, bDate) {
38
return (this.isValidDate(aDate) && this.isValidDate(bDate) && (aDate.getTime() == bDate.getTime()));
41
isGreater : function (aDate, bDate) {
42
return (this.isValidDate(aDate) && this.isValidDate(bDate) && (aDate.getTime() > bDate.getTime()));
45
isGreaterOrEqual : function (aDate, bDate) {
46
return (this.isValidDate(aDate) && this.isValidDate(bDate) && (aDate.getTime() >= bDate.getTime()));
49
addMonths : function (oDate, numMonths) {
50
var newYear = oDate.getFullYear();
51
var newMonth = oDate.getMonth() + numMonths;
53
newYear = Math.floor(newYear + newMonth / 12);
54
newMonth = (newMonth % 12 + 12) % 12;
56
var newDate = new Date (oDate.getTime());
57
newDate.setYear(newYear);
58
newDate.setMonth(newMonth);
63
addYears : function (oDate, numYears) {
64
var newYear = oDate.getFullYear() + numYears;
65
var newDate = new Date(oDate.getTime());
67
newDate.setYear(newYear);
71
listOfDatesInMonth : function (oDate) {
72
if (!this.isValidDate(oDate)) {
76
var daysInMonth = this.daysInMonth(oDate),
77
year = oDate.getFullYear(),
78
month = oDate.getMonth(),
81
for (var day = 1; day <= daysInMonth; day++) {
82
output.push(new Date(year, month, day, 12, 0, 0));
89
* Takes a native JavaScript Date and returns the number of days in the month that the given date belongs to.
92
* @param oDate {Date} Date in the month for which the number of days is desired.
93
* @return {Number} A number (either 28, 29, 30 or 31) of days in the given month.
95
daysInMonth : function (oDate) {
96
if (!this.isValidDate(oDate)) {
100
var mon = oDate.getMonth();
101
var lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
108
var year = oDate.getFullYear();
109
if (year%400 === 0) {
112
else if (year%100 === 0) {
115
else if (year%4 === 0) {
127
}, '3.4.1' ,{requires:['yui-base']});