vox-core
Version:
Runtime de aplicaciones multiplataforma
417 lines (322 loc) • 12.2 kB
JavaScript
var Util= core.VW.Util;
var SG= core.System.Globalization;
var DateTimeFormatInfo= module.exports= function(/*CultureData*/ data, /* Calendar */ calendar){
this.$data= data;
var info=this.$data.datetimeInfo;
for(var i=0;i<info.length;i++){
if(calendar.possibleIds().indexOf(info[i].calendarId)){
this.$calendardata= info[i];
break;
}
}
if(calendar==null){
throw new core.System.ArgumentNullException("Calendar es nulo");
}
this.$calendar=calendar;
if(!this.$calendardata){
throw new core.System.ArgumentException("El calendario no es válido para esta cultura");
}
}
DateTimeFormatInfo.get_currentInfo= function(){
return SG.CultureInfo.currentCulture.dateTimeFormat;
}
DateTimeFormatInfo.get_invariantInfo= function(){
return SG.CultureInfo.getCultureInfo("Invariant").dateTimeFormat;
}
DateTimeFormatInfo.prototype.get_abbreviatedDayNames= function(){
return this.$calendardata.AbbreviatedDayNames;
}
DateTimeFormatInfo.prototype.get_abbreviatedMonthGenitiveNames= function(){
return this.$calendardata.AbbreviatedMonthGenitiveNames;
}
DateTimeFormatInfo.prototype.get_abbreviatedEnglishEraNames= function(){
return this.$calendardata.AbbreviatedEnglishEraNames;
}
DateTimeFormatInfo.prototype.get_abbreviatedEraNames= function(){
return this.$calendardata.AbbreviatedEraNames;
}
DateTimeFormatInfo.prototype.get_abbreviatedMonthNames= function(){
return this.$calendardata.AbbreviatedMonthNames;
}
DateTimeFormatInfo.prototype.get_AMDesignator= function(){
return this.$calendardata.AMDesignator;
}
DateTimeFormatInfo.prototype.get_calendar= function(){
return this.$calendar;
}
DateTimeFormatInfo.prototype.get_calendarWeekRule= function(){
return SG.CalendarWeekRule.parse(this.$calendardata.CalendarWeekRule);
}
DateTimeFormatInfo.prototype.get_cultureName= function(){
return this.$calendardata.CultureName;
}
DateTimeFormatInfo.prototype.get_dateSeparator= function(){
return this.$calendardata.DateSeparator;
}
DateTimeFormatInfo.prototype.get_dateTimeOffsetPattern= function(){
return this.$calendardata.DateTimeOffsetPattern;
}
DateTimeFormatInfo.prototype.get_dayNames= function(){
return this.$calendardata.DayNames;
}
DateTimeFormatInfo.prototype.get_eraNames= function(){
return this.$calendardata.EraNames;
}
DateTimeFormatInfo.prototype.get_firstDayOfWeek= function(){
return core.System.DayOfWeek.parse(this.$calendardata.FirstDayOfWeek);
}
DateTimeFormatInfo.prototype.get_formatFlags= function(){
return this.$calendardata.FormatFlags;
}
DateTimeFormatInfo.prototype.get_fullDateTimePattern= function(){
return this.$calendardata.FullDateTimePattern;
}
DateTimeFormatInfo.prototype.get_fullTimeSpanNegativePattern= function(){
return this.$calendardata.FullTimeSpanNegativePattern;
}
DateTimeFormatInfo.prototype.get_fullTimeSpanPositivePattern= function(){
return this.$calendardata.FullTimeSpanPositivePattern;
}
DateTimeFormatInfo.prototype.get_generalLongTimePattern= function(){
return this.$calendardata.GeneralLongTimePattern;
}
DateTimeFormatInfo.prototype.get_generalShortTimePattern= function(){
return this.$calendardata.GeneralShortTimePattern;
}
DateTimeFormatInfo.prototype.get_hasForceTwoDigitYears= function(){
return this.$calendardata.HasForceTwoDigitYears;
}
DateTimeFormatInfo.prototype.get_hasSpacesInDayNames= function(){
return this.$calendardata.HasSpacesInDayNames;
}
DateTimeFormatInfo.prototype.get_hasSpacesInMonthNames= function(){
return this.$calendardata.HasSpacesInMonthNames;
}
DateTimeFormatInfo.prototype.get_hasYearMonthAdjustment= function(){
return this.$calendardata.HasYearMonthAdjustment;
}
DateTimeFormatInfo.prototype.get_languageName= function(){
return this.$calendardata.LanguageName;
}
DateTimeFormatInfo.prototype.get_longDatePattern= function(){
return this.$calendardata.LongDatePattern;
}
DateTimeFormatInfo.prototype.get_longTimePattern= function(){
return this.$calendardata.LongTimePattern;
}
DateTimeFormatInfo.prototype.get_monthDayPattern= function(){
return this.$calendardata.MonthDayPattern;
}
DateTimeFormatInfo.prototype.get_monthGenitiveNames= function(){
return this.$calendardata.MonthGenitiveNames;
}
DateTimeFormatInfo.prototype.get_monthNames= function(){
return this.$calendardata.MonthNames;
}
DateTimeFormatInfo.prototype.get_nativeCalendarName= function(){
return this.$calendardata.NativeCalendarName;
}
DateTimeFormatInfo.prototype.get_PMDesignator= function(){
return this.$calendardata.PMDesignator;
}
DateTimeFormatInfo.prototype.get_RFC1123Pattern= function(){
return this.$calendardata.RFC1123Pattern;
}
DateTimeFormatInfo.prototype.get_shortDatePattern= function(){
return this.$calendardata.ShortDatePattern;
}
DateTimeFormatInfo.prototype.get_shortestDayNames= function(){
return this.$calendardata.ShortestDayNames;
}
DateTimeFormatInfo.prototype.get_shortTimePattern= function(){
return this.$calendardata.ShortTimePattern;
}
DateTimeFormatInfo.prototype.get_sortableDateTimePattern= function(){
return this.$calendardata.SortableDateTimePattern;
}
DateTimeFormatInfo.prototype.get_timeSeparator= function(){
return this.$calendardata.TimeSeparator;
}
DateTimeFormatInfo.prototype.get_unclonedLongDatePatterns= function(){
return this.$calendardata.UnclonedLongDatePatterns;
}
DateTimeFormatInfo.prototype.get_unclonedLongTimePatterns= function(){
return this.$calendardata.UnclonedLongTimePatterns;
}
DateTimeFormatInfo.prototype.get_unclonedShortDatePatterns= function(){
return this.$calendardata.UnclonedShortDatePatterns;
}
DateTimeFormatInfo.prototype.get_unclonedShortTimePatterns= function(){
return this.$calendardata.UnclonedShortTimePatterns;
}
DateTimeFormatInfo.prototype.get_unclonedYearMonthPatterns= function(){
return this.$calendardata.UnclonedYearMonthPatterns;
}
DateTimeFormatInfo.prototype.get_universalSortableDateTimePattern= function(){
return this.$calendardata.UniversalSortableDateTimePattern;
}
DateTimeFormatInfo.prototype.get_yearMonthPattern= function(){
return this.$calendardata.YearMonthPattern;
}
/* Instance methods */
DateTimeFormatInfo.prototype.getAbbreviatedDayName= function(/* DayOfWeek*/ day){
return this.get_abbreviatedDayNames()[day|0];
}
DateTimeFormatInfo.prototype.getAbbreviatedEraName= function(/* int*/ era){
return this.get_abbreviatedEraNames()[Math.max((era|0)-1,0)];
}
DateTimeFormatInfo.prototype.getAbbreviatedMonthName= function(/* int*/ month){
return this.get_abbreviatedMonthNames()[month|0];
}
var DEFAULT_ALL_DATETIMES_SIZE=132;
DateTimeFormatInfo.prototype.getAllDateTimePatterns= function()
{
var results = new Array(DEFAULT_ALL_DATETIMES_SIZE); /*List<String>(DEFAULT_ALL_DATETIMES_SIZE);*/
for (var i = 0; i < core.System.DateTimeFormat.allStandardFormats.length; i++)
{
var strings = this.getAllDateTimePatterns(core.System.zzzzzzzzzzzzzzzzzzzDateTimeFormat.allStandardFormats[i]);
for (var j = 0; j < strings.length; j++)
{
results.push(strings[j]);
}
}
return results; //.ToArray();
}
DateTimeFormatInfo.prototype.getAllDateTimePatterns= function(/*char*/format ){
//Contract.Ensures(Contract.Result<String[]>() != null);
var result = null;
switch (format)
{
case 'd':
result = this.allShortDatePatterns;
break;
case 'D':
result = this.allLongDatePatterns;
break;
case 'f':
result = getCombinedPatterns(this.allLongDatePatterns, allShortTimePatterns, " ");
break;
case 'F':
case 'U':
result = getCombinedPatterns(this.allLongDatePatterns, this.allLongTimePatterns, " ");
break;
case 'g':
result = getCombinedPatterns(this.allShortDatePatterns, this.allShortTimePatterns, " ");
break;
case 'G':
result = getCombinedPatterns(this.allShortDatePatterns, this.allLongTimePatterns, " ");
break;
case 'm':
case 'M':
result = [this.monthDayPattern];
break;
case 'o':
case 'O':
result = [core.System.DateTimeFormat.roundtripFormat];
break;
case 'r':
case 'R':
result = [rfc1123Pattern];
break;
case 's':
result = [sortableDateTimePattern];
break;
case 't':
result = this.allShortTimePatterns;
break;
case 'T':
result = this.allLongTimePatterns;
break;
case 'u':
result = [this.universalSortableDateTimePattern];
break;
case 'y':
case 'Y':
result = this.allYearMonthPatterns;
break;
default:
throw new core.System.ArgumentException("Formato no válido");
}
return (result);
}
DateTimeFormatInfo.getCombinedPatterns= function(/*String[]*/ patterns1, /*String[]*/ patterns2, /*String*/ connectString)
{
//Contract.Requires(patterns1 != null);
//Contract.Requires(patterns2 != null);
// Get array size
var result = new Array[patterns1.length * patterns2.length];
// Counter of actual results
var k = 0;
for (var i = 0; i < patterns1.length; i++)
{
for (var j = 0; j < patterns2.length; j++)
{
// Can't combine if null or empty
result[k++] = patterns1[i] + connectString + patterns2[j];
}
}
// Return the combinations
return result;
}
DateTimeFormatInfo.prototype.getDayName= function(/* DayOfWeek*/ day){
return this.get_dayNames()[day|0];
}
DateTimeFormatInfo.prototype.getEraName= function(/* string*/ era){
var eras= this.get_eraNames();
var era= era.toUpperCase();
for(var i=0;i<eras.length;i++){
if(eras[i].toUpperCase()==era){
return i+1;
}
}
eras= this.get_abbreviatedEraNames();
for(var i=0;i<eras.length;i++){
if(eras[i].toUpperCase()==era){
return i+1;
}
}
eras= this.get_abbreviatedEnglishEraNames();
for(var i=0;i<eras.length;i++){
if(eras[i].toUpperCase()==era){
return i+1;
}
}
return -1;
}
DateTimeFormatInfo.prototype.getEraName= function(/* int*/ era){
return this.get_eraNames()[Math.max((era|0)-1,0)];
}
DateTimeFormatInfo.prototype.getInstance= function(){
return DateTimeFormatInfo.get_currentInfo();
}
DateTimeFormatInfo.prototype.getMonthName= function(/* int*/ month){
return this.get_monthNames()[month|0];
}
DateTimeFormatInfo.prototype.getShortestDayName= function(/* DayOfWeek*/ dayOfWeek){
return this.get_shortestDayNames()[dayOfWeek|0];
}
DateTimeFormatInfo.prototype.internalGetMonthName= function(/*int*/ month, /*MonthNameStyles*/ style, /*bool*/ abbreviated) {
//
// Right now, style is mutual exclusive, but I make the style to be flag so that
// maybe we can combine flag if there is such a need.
//
var monthNamesArray = null;
switch (style|0) {
case SG.MonthNameStyles.Genitive|0:
monthNamesArray = this.get_monthGenitiveNames(); // internalGetGenitiveMonthNames(abbreviated);
break;
case SG.MonthNameStyles.LeapYear|0:
monthNamesArray = this.$calendardata.LeapYearMonthNames; // internalGetLeapYearMonthNames(/*abbreviated*/);
break;
default:
monthNamesArray = (abbreviated ? this.get_abbreviatedMonthNames(): this.get_monthNames());
break;
}
// The month range is from 1 ~ this.m_monthNames.Length
// (actually is 13 right now for all cases)
if ((month < 1) || (month > monthNamesArray.length)) {
throw new core.System.ArgumentOutOfRangeException("month");
}
return (monthNamesArray[month-1]);
}
Util.createProperties(DateTimeFormatInfo,DateTimeFormatInfo.prototype);