vox-core
Version:
Runtime de aplicaciones multiplataforma
254 lines (194 loc) • 7.55 kB
JavaScript
/**
@author James Suárez
System.Globalization.Calendar
*/
var Util= core.VW.Util;
var SG= core.System.Globalization;
var Calendar= module.exports= function(){
}
/* CONSTANTES */
Calendar.CAL_GREGORIAN = 1 ; // Gregorian (localized) calendar
Calendar.CAL_GREGORIAN_US = 2 ; // Gregorian (U.S.) calendar
Calendar.CAL_JAPAN = 3 ; // Japanese Emperor Era calendar
Calendar.CAL_TAIWAN = 4 ; // Taiwan Era calendar
Calendar.CAL_KOREA = 5 ; // Korean Tangun Era calendar
Calendar.CAL_HIJRI = 6 ; // Hijri (Arabic Lunar) calendar
Calendar.CAL_THAI = 7 ; // Thai calendar
Calendar.CAL_HEBREW = 8 ; // Hebrew (Lunar) calendar
Calendar.CAL_GREGORIAN_ME_FRENCH = 9 ; // Gregorian Middle East French calendar
Calendar.CAL_GREGORIAN_ARABIC = 10; // Gregorian Arabic calendar
Calendar.CAL_GREGORIAN_XLIT_ENGLISH = 11; // Gregorian Transliterated English calendar
Calendar.CAL_GREGORIAN_XLIT_FRENCH = 12;
Calendar.CAL_JULIAN = 13;
Calendar.CAL_JAPANESELUNISOLAR = 14;
Calendar.CAL_CHINESELUNISOLAR = 15;
Calendar.CAL_SAKA = 16; // reserved to match Office but not implemented in our code
Calendar.CAL_LUNAR_ETO_CHN = 17; // reserved to match Office but not implemented in our code
Calendar.CAL_LUNAR_ETO_KOR = 18; // reserved to match Office but not implemented in our code
Calendar.CAL_LUNAR_ETO_ROKUYOU = 19; // reserved to match Office but not implemented in our code
Calendar.CAL_KOREANLUNISOLAR = 20;
Calendar.CAL_TAIWANLUNISOLAR = 21;
Calendar.CAL_PERSIAN = 22;
Calendar.CAL_UMALQURA = 23;
Calendar.prototype.get_maxSupportedDateTime= function(){
return core.System.DateTime.maxValue;
}
Calendar.prototype.get_minSupportedDateTime= function(){
return core.System.DateTime.minValue;
}
Calendar.prototype.addDays= function(/* DateTime */date, /*int*/months){
return date.addDays(months);
}
Calendar.prototype.addHours= function(/* DateTime */date, /*int*/hours){
return date.addHours(hours);
}
Calendar.prototype.addMilliseconds= function(/* DateTime */date, /*int*/milliseconds){
return date.addMilliseconds(milliseconds);
}
Calendar.prototype.addMinutes= function(/* DateTime */date, /*int*/minutes){
return date.addMinutes(minutes);
}
Calendar.prototype.addMonths= function(/* DateTime */date, /*int*/months){
return date.addMonths(months);
}
Calendar.prototype.addYears= function(/* DateTime */date, /*int*/years){
return date.addYears(years);
}
Calendar.prototype.addSeconds= function(/* DateTime */date, /*int*/seconds){
return date.addSeconds(seconds);
}
Calendar.prototype.addWeeks= function(/* DateTime */date, /*int*/weeks){
return date.addDays(weeks*7);
}
Calendar.prototype.getDayOfMonth= function(/* DateTime */date){
return date.day;
}
Calendar.prototype.getDayOfWeek= function(/* DateTime */date){
return date.dayOfWeek;
}
Calendar.prototype.getDayOfYear= function(/*DateTime*/date){
return date.dayOfYear;
}
Calendar.prototype.getDaysInMonth= function(/*int*/year,/*int*/month){
return core.System.DateTime.daysInMonth(year,month);
}
Calendar.prototype.getDaysInYear= function(/*int*/year){
if (year < 1 || year > 9999)
{
throw new core.System.ArgumentOutOfRangeException("year debe estar entre 1 y 9999");
}
if (year % 4 != 0 || (year % 100 == 0 && year % 400 != 0))
{
return 365;
}
return 366;
}
Calendar.prototype.getHour= function(/*DateTime*/date){
return date.hour;
}
Calendar.prototype.getMonth= function(/*DateTime*/date){
return date.month;
}
Calendar.prototype.getMonthsInYear= function(/*int*/year){
return 12;
}
Calendar.prototype.getYear= function(/*DateTime*/date){
return date.year;
}
Calendar.prototype.getSecond= function(/*DateTime*/date){
return date.second;
}
Calendar.prototype.getWeekOfYear= function(/*DateTime*/ time, /*CalendarWeekRule*/ rule, /*DayOfWeek*/ firstDayOfWeek){
firstDayOfWeek=firstDayOfWeek|0;
CalendarWeekRule= SG.CalendarWeekRule;
switch (rule|0)
{
case CalendarWeekRule.FirstDay+0:
return this.getFirstDayWeekOfYear(time, firstDayOfWeek);
case CalendarWeekRule.FirstFullWeek+0:
return this.getWeekOfYearFullDays(time, firstDayOfWeek, 7);
case CalendarWeekRule.FirstFourDayWeek+0:
return this.getWeekOfYearFullDays(time, firstDayOfWeek, 4);
default:
throw new core.System.ArgumentOutOfRangeException("rule");
}
}
Calendar.prototype.getFirstDayWeekOfYear=function(/*DateTime*/ time, /*int*/ firstDayOfWeek)
{
var num = this.getDayOfYear(time) - 1;
var num2 = this.getDayOfWeek(time) - (num % 7);
var num3 = (num2 - firstDayOfWeek + 14) % 7;
return (num + num3) / 7 + 1;
}
Calendar.prototype.getWeekOfYearFullDays= function(/*DateTime*/ time, /*int*/ firstDayOfWeek, /*int*/ fullDays)
{
var num = this.getDayOfYear(time) - 1;
var num2 = this.getDayOfWeek(time) - (num % 7);
var num3 = (firstDayOfWeek - num2 + 14) % 7;
if (num3 != 0 && num3 >= fullDays)
{
num3 -= 7;
}
var num4 = num - num3;
if (num4 >= 0)
{
return num4 / 7 + 1;
}
if (time <= this.minSupportedDateTime.addDays(num))
{
return this.getWeekOfYearOfMinSupportedDateTime(firstDayOfWeek, fullDays);
}
return this.getWeekOfYearFullDays(time.addDays(-(num + 1), firstDayOfWeek, fullDays));
}
Calendar.prototype.getWeekOfYearOfMinSupportedDateTime=function(/*int*/ firstDayOfWeek, /*int*/ minimumDaysInFirstWeek)
{
var num = this.getDayOfYear(this.minSupportedDateTime) - 1;
var num2 = this.getDayOfWeek(this.minSupportedDateTime) - (num % 7);
var num3 = (firstDayOfWeek + 7 - num2) % 7;
if (num3 == 0 || num3 >= minimumDaysInFirstWeek)
{
return 1;
}
var num4 = /*this.daysInYearBeforeMinSupportedYear*/365 - 1;
var num5 = num2 - 1 - num4 % 7;
var num6 = (firstDayOfWeek - num5 + 14) % 7;
var num7 = num4 - num6;
if (num6 >= minimumDaysInFirstWeek)
{
num7 += 7;
}
return num7 / 7 + 1;
}
Calendar.prototype.isLeapDay= function(/*int*/year,/*int*/month, /*int*/day){
if (month < 1 || month > 12)
{
throw new core.System.ArgumentOutOfRangeException("month");
}
if (era != 0 && era != 1)
{
throw new core.System.ArgumentOutOfRangeException("era");
}
if (year < 1 || year > 9999)
{
throw new core.System.ArgumentOutOfRangeException("year");
}
if (day < 1 || day > this.getDaysInMonth(year, month))
{
throw new core.System.ArgumentOutOfRangeException("day");
}
return this.isLeapYear(year) && (month == 2 && day == 29);
}
Calendar.prototype.isLeapMonth= function(/*int*/year,/*int*/month){
return false;
}
Calendar.prototype.isLeapYear= function(/*int*/year){
if (year >= 1 && year <= 9999)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
throw new core.System.ArgumentOutOfRangeException("year");
}
Calendar.prototype.toDateTime= function(/*int*/ year, /*int*/ month, /*int*/ day, /*int*/ hour, /*int*/ minute, /*int*/ second, /*int*/ millisecond){
return new core.System.DateTime(year|0,month|0,day|0,hour|0,minute|0,second|0,millisecond|0);
}
Util.createProperties(Calendar,Calendar.prototype);