This commit is contained in:
rolux 2011-04-24 00:42:10 +02:00
parent 3672d7ee9c
commit dc1ec954fb

View file

@ -940,25 +940,33 @@ Ox.getDayOfTheYear = function(date, utc) {
})) + Ox.getDate(date, utc); })) + Ox.getDate(date, utc);
}; };
Ox.getDaysInMonth = function(year, month) { Ox.getDaysInMonth = function(year, month, utc) {
/* /*
>>> Ox.getDaysInMonth(2000, 2) >>> Ox.getDaysInMonth(2000, 2)
29 29
>>> Ox.getDaysInMonth("2002", "Feb") >>> Ox.getDaysInMonth("2002", "Feb")
28 28
>>> Ox.getDaysInMonth("2004", "February") >>> Ox.getDaysInMonth(new Date('01/01/2004'), "February")
29 29
*/ */
var year = parseInt(year), year = Ox.makeYear(year);
month = Ox.isNumber(month) ? month : month = Ox.isNumber(month) ? month :
Ox.map(Ox.MONTHS, function(v, i) { Ox.map(Ox.MONTHS, function(v, i) {
return v.substr(0, 3) == month.substr(0, 3) ? i + 1 : null; return v.substr(0, 3) == month.substr(0, 3) ? i + 1 : null;
})[0]; })[0];
return new Date(year, month, 0).getDate(); return new Date(year, month, 0).getDate();
} }
Ox.getDaysInYear = function(year) { Ox.getDaysInYear = function(year, utc) {
return 365 + Ox.isLeapYear(year); /*
>>> Ox.getDaysInYear(1900)
365
>>> Ox.getDaysInYear('2000')
366
>>> Ox.getDaysInYear(new Date('01/01/2004'))
366
*/
return 365 + Ox.isLeapYear(Ox.makeYear(year, utc));
}; };
Ox.getFirstDayOfTheYear = function(date, utc) { Ox.getFirstDayOfTheYear = function(date, utc) {
@ -1060,15 +1068,16 @@ Ox.getWeek = function(date, utc) {
Ox.getFirstDayOfTheYear(date, utc) - 1) / 7); Ox.getFirstDayOfTheYear(date, utc) - 1) / 7);
}; };
Ox.isLeapYear = function(year) { Ox.isLeapYear = function(year, utc) {
/* /*
>>> Ox.isLeapYear(1900) >>> Ox.isLeapYear(1900)
false false
>>> Ox.isLeapYear(2000) >>> Ox.isLeapYear('2000')
true true
>>> Ox.isLeapYear(2004) >>> Ox.isLeapYear(new Date('01/01/2004'))
true true
*/ */
year = Ox.makeYear(year, utc);
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}; };
@ -1077,24 +1086,26 @@ Ox.makeDate = function(date) {
Ox.isUndefined(date) ? new Date() : new Date(date); Ox.isUndefined(date) ? new Date() : new Date(date);
}; };
['get', 'set'].forEach(function(verb) { Ox.makeYear = function(date, utc) {
[ return Ox.isDate(date) ? Ox.getFullYear(date, utc) : parseInt(date);
'FullYear', 'Month', 'Date', 'Day', 'Hours', 'Minutes', 'Seconds' };
].forEach(function(noun) {
Ox['get' + noun] = function(date, utc) {
return Ox.makeDate(date)['get' + (utc ? 'UTC' : '') + noun]()
}
Ox['set' + noun] = function(date, num, utc) {
// new Date(date) makes a clone, so that
// setSomething() doesn't have side effects
return new Date(
Ox.makeDate(date)
)['set' + (utc ? 'UTC' : '') + noun](num);
}
});
[
'FullYear', 'Month', 'Date', 'Day', 'Hours', 'Minutes', 'Seconds'
].forEach(function(noun) {
Ox['get' + noun] = function(date, utc) {
return Ox.makeDate(date)['get' + (utc ? 'UTC' : '') + noun]()
}
Ox['set' + noun] = function(date, num, utc) {
// new Date(date) makes a clone, so that
// setSomething() doesn't have side effects
return new Date(
Ox.makeDate(date)
)['set' + (utc ? 'UTC' : '') + noun](num);
}
}); });
/* /*
================================================================================ ================================================================================
DOM functions DOM functions