/** * @fileOverview
Array
holds the abbreviated name,
* the second one the long name.
* @type {Array}
*/
WEEKDAYS: [
["Sun", "Sunday"], ["Mon", "Monday"], ["Tue", "Tuesday"],
["Wed", "Wednesday"], ["Thu", "Thursday"], ["Fri", "Friday"],
["Sat", "Saturday"]
],
/**
* Month names, where the elements are {@link Array}s of
* {@link Array}s of {@link String}. The first element of the
* inner Array
holds the abbreviated name,
* the second one the long name.
*/
MONTHS: [
["Jan", "January"], ["Feb", "February"], ["Mar", "March"],
["Apr", "April"], ["May", "May"], ["Jun", "June"],
["Jul", "July"], ["Aug", "August"], ["Sep", "September"],
["Oct", "October"], ["Nov", "November"], ["Dec", "December"]
],
/**
* Daytimes for the 12-hour format
*/
DAYTIMES: {am: "am", pm: "pm"},
/**
* Time zone names, where the keys are the offsets to UTC in
* minutes, and the values are {@link Array}s of {@link String}.
*/
TIMEZONES: {
"540": ["Alaska Standard Time (AKST)"],
"480": ["Alaska Daylight Time (AKDT)"],
"240": ["Atlantic Standard Time (AST)"],
"180": ["Atlantic Daylight Time (ADT)",
"Argentina Time (ART)"],
"0": ["Greenwich Mean Time (GMT)"],
"-60": ["Central European Time (CET)"],
"-120": ["Central European Summer Time (CEST)"],
"-180": ["Arabia Standard Time (AST)"],
"-240": ["Armenia Time (AMT)"],
"-270": ["Afghanistan Time (AFT)"],
"-480": ["Australian Western Standard Time (AWST)",
"ASEAN Common Time (ACT)"],
"-570": ["Australian Central Standard Time (ACST)"],
"-600": ["Australian Eastern Standard Time (AEST)"],
"-630": ["Australian Central Daylight Time (ACDT)"],
"-660": ["Australian Eastern Daylight Time (AEDT)"]
},
/**
* Returns the number of day within a year
*
* @param {Date} date
* @return {number}
* @see http://en.wikipedia.org/wiki/Ordinal_date
*/
dayOfYear: function (date) {
var month = date.getMonth();
var dayOfMonth = date.getDate();
switch (month)
{
/* January */
case 0:
return dayOfMonth;
/* February */
case 1:
return dayOfMonth + 31;
default:
return Math.floor(30.6 * (month + 1) - 91.4) + dayOfMonth
+ (jsx.date.isLeapYear(date.getFullYear()) ? 60 : 59);
}
},
/**
* Determines if the arguments define a valid date-time.
*
* @param {Number} year
* Year argument for the {@link Date} constructor. Possible
* implementation-dependent correction of two-digit years is
* not supported.
* @param {Number} month
* @param {Number} date (optional)
* Day of month
* @param {Number} minutes (optional)
* @param {Number} seconds (optional)
* @param {Number} ms (optional)
* Milliseconds
* @return {boolean}
* true
if the arguments would produce a
* corresponding time value when passed to the {@link Date}
* constructor, false
otherwise.
* @see Date
*/
isValid: function (year, month, date, hours, minutes, seconds, ms) {
if (arguments.length < 3)
{
return jsx.throwThis(jsx.InvalidArgumentError,
["Not enough arguments", [].slice.call(arguments),
"at least (year : int, month : int)"]);
}
var d = Date.construct(arguments);
return (d.getFullYear() == year
&& (typeof month == "undefined" || d.getMonth() == month)
&& (typeof hours == "undefined" || d.getHours() == hours)
&& (typeof minutes == "undefined" || d.getMinutes() == minutes)
&& (typeof seconds == "undefined" || d.getSeconds() == seconds));
},
/**
* Determines if a year is a leap year.
*
* @param {Number} year
* @return {boolean}
* Returns true
if year is a leap year.
*/
isLeapYear: function (year) {
return jsx.date.isValid(year, 1, 29);
},
/**
* Calculate the ISO 8601 weekday number of a Date
.
*
* The ISO 8601 weekday number differs from the ECMAScript
* weekday number in that Sunday is 7
instead of
* 0
.
*
* @param {Date} date
* @return {number}
*/
isoWeekday: function (date) {
return (date.getDay() % 7) || 7;
},
/**
* Calculates the ISO 8601 week number of a Date
.
*
* @param {Date} date
* @return {number}
* @see http://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date
*/
isoWeekNumber: function jsx_date_isoWeekNumber (date) {
var result = Math.floor(
(jsx.date.dayOfYear(date) - jsx.date.isoWeekday(date)
+ 10) / 7);
switch (result)
{
case 0:
result = jsx_date_isoWeekNumber(new Date(date.getFullYear() - 1, 11, 31));
break;
case 53:
/* TODO */
}
return result;
},
/**
* Returns the time zone offset of a {@link Date}
* in hours and minutes
*/
tzOffsetHours: (function () {
var _leadingZero = jsx.string.leadingZero;
/**
* @param {Date} date
* @param {TimeOptions} options
* delimiter | *Delimiter between hours and minutes | *
---|---|
leadingZero | *If true , hours always have two digits. |
*
zeroMinutes | *If true minutes are returned even
* if they are zero. |
*
Date
.
*
* @function
* @memberOf Date.prototype
* @see jsx.date.isoWeekNumber(Date)
* @return {number}
*/
getISOWeekday: (function () {
var _isoWeekday = jsx.date.isoWeekday;
return function () {
return _isoWeekday(this);
};
}()),
/**
* Returns the ISO week number of this Date
.
*
* @function
* @see jsx.date.isoWeekNumber(Date)
* @return {number}
*/
getISOWeekNumber: (function () {
var _isoWeekNumber = jsx.date.isoWeekNumber;
return function () {
return _isoWeekNumber(this);
};
}()),
/**
* Returns the number of day within a year
*
* @function
* @see jsx.date.dayOfYear(Date)
* @return {number}
*/
getDayOfYear: (function () {
var _dayOfYear = jsx.date.dayOfYear;
return function () {
return _dayOfYear(this);
};
}()),
/**
* @function
* @see jsx.date#format(Date, String)
* @return {string}
*/
format: (function () {
var _format = jsx.date.format;
/**
* @param {String} format
*/
return function (format) {
return _format(this, format);
};
}()),
/**
* @function
* @see jsx.date#strftime(Date, String)
* @return {string}
*/
strftime: (function () {
var _strftime = jsx.date.strftime;
/**
* @param {String} format
*/
return function (format) {
return _strftime(this, format);
};
}())
});
}
}