1
0
Fork 0
forked from 0x2620/oxjs

adding first Ox.Calendar demo

This commit is contained in:
rlx 2011-04-20 11:29:34 +00:00
commit 1c05a7945f
6 changed files with 620 additions and 15 deletions

View file

@ -43,6 +43,9 @@ Ox.MONTHS = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
Ox.SHORT_MONTHS = Ox.MONTHS.map(function(val) {
return val.substr(0, 3);
});
Ox.PREFIXES = ['K', 'M', 'G', 'T', 'P'];
Ox.SYMBOLS = {
DOLLAR: '\u0024',
@ -77,6 +80,9 @@ Ox.VERSION = '0.1.2';
Ox.WEEKDAYS = [
'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'
];
Ox.SHORT_WEEKDAYS = Ox.WEEKDAYS.map(function(val) {
return val.substr(0, 3);
});
/*
================================================================================
@ -491,9 +497,14 @@ Ox.len = function(obj) {
return Ox.isObject(obj) ? Ox.values(obj).length : obj.length;
};
Ox.loop = function(num, fn) {
var i;
for (i = 0; i < num; i++) {
Ox.loop = function() {
var length = arguments.length,
fn = arguments[length - 1],
step = length == 4 ? arguments[2] : 1,
stop = arguments[length > 2 ? 1 : 0],
start = length > 2 ? arguments[0] : 0,
i;
for (i = start; i < stop; i += step) {
fn(i);
}
};
@ -957,6 +968,10 @@ Ox.getDaysInMonth = function(year, month) {
//return Ox.DAYS[month - 1] + (month == 2 && Ox.isLeapYear(year));
}
Ox.getDaysInYear = function(year) {
return 365 + Ox.isLeapYear(year);
};
Ox.getFirstDayOfTheYear = function(date) {
/*
Decimal weekday of January 1 (0-6, Sunday as first day)
@ -1610,10 +1625,10 @@ Ox.formatDate = function() {
["v", function() {return "%e-%b-%Y";}],
["\\+", function() {return "%a %b %e %H:%M:%S %Z %Y";}],
["A", function(d) {return Ox.WEEKDAYS[(d.getDay() + 6) % 7];}],
["a", function(d) {return Ox.WEEKDAYS[(d.getDay() + 6) % 7].toString().substr(0, 3);}],
["a", function(d) {return Ox.SHORT_WEEKDAYS[(d.getDay() + 6) % 7];}],
["B", function(d) {return Ox.MONTHS[d.getMonth()];}],
["b", function(d) {return Ox.MONTHS[d.getMonth()].toString().substr(0, 3);}],
["C", function(d) {return d.getFullYear().toString().substr(0, 2);}],
["b", function(d) {return Ox.SHORT_MONTHS[d.getMonth()];}],
["C", function(d) {return (d.getFullYear() / 100).toString();}],
["d", function(d) {return Ox.pad(d.getDate(), 2);}],
["e", function(d) {return Ox.pad(d.getDate(), 2, " ");}],
["G", function(d) {return Ox.getISOYear(d);}],
@ -1737,6 +1752,38 @@ Ox.formatNumber = function(num, dec) {
return (num < 0 ? '-' : '') + spl.join('.');
};
Ox.formatOrdinal = function(num) {
/*
>>> Ox.formatOrdinal(1)
"1st"
>>> Ox.formatOrdinal(2)
"2nd"
>>> Ox.formatOrdinal(3)
"3rd"
>>> Ox.formatOrdinal(4)
"4th"
>>> Ox.formatOrdinal(11)
"11th"
>>> Ox.formatOrdinal(12)
"12th"
>>> Ox.formatOrdinal(13)
"13th"
*/
var str = num.toString(),
end = str[str.length - 1],
ten = str.length > 1 && str[str.length - 2] == '1';
if (end == '1' && !ten) {
str += 'st';
} else if (end == '2' && !ten) {
str += 'nd';
} else if (end == '3' && !ten) {
str += 'rd';
} else {
str += 'th';
}
return str;
};
Ox.formatPercent = function(num, total, dec) {
/*
>>> Ox.formatPercent(1, 1000, 2)
@ -2245,6 +2292,17 @@ Ox.log = function(num, base) {
return Math.log(num) / Math.log(base || Math.E);
};
Ox.mod = function(num, by) {
/*
>>> Ox.mod(11, 10)
1
>>> Ox.mod(-11, 10)
9
*/
var mod = num % by;
return mod >= 0 ? mod : mod + by;
};
Ox.rad = function(deg) {
/*
>>> Ox.rad(360)