this._setLocale( this.options.locale );
- this.date = new $.ui.calendarDate( this.options.value, this.options.locale );
- this.date = $.date( this.options.value, this.options.dateFormat );
+ this.date = new $.ui.calendarDate( this.options.value, this._calendarDateOptions );
this.viewDate = this.date.clone();
this.viewDate.eachDay = this.options.eachDay;
},
_setLocale: function( locale ) {
- var globalize;
+ var globalize = new Globalize( locale );
- if ( typeof locale === "string" ) {
- globalize = new Globalize( locale );
- locale = {
- format: function( date ) {
+ this._format = function( date ) {
return globalize.formatDate( date, { date: "short" } );
- },
- parse: function( stringDate ) {
+ };
+
+ this._parse = function( stringDate ) {
return globalize.parseDate( stringDate, { date: "short" } );
- }
};
- }
- if ( !locale.firstDay ) {
- globalize = globalize || new Globalize( locale._locale );
- $.extend( locale, {
+ this._calendarDateOptions = {
firstDay: globalize.cldr.supplemental.weekData.firstDay(),
formatWeekdayShort: function( date ) {
},
formatWeekOfYear: function( date ) {
return globalize.formatDate( date, { pattern: "w" } );
- }
- });
- }
-
- this.options.locale = locale;
+ },
+ parse: this._parse
+ };
},
_createCalendar: function() {
},
value: function( value ) {
- var locale = this.options.locale;
if ( arguments.length ) {
this.valueAsDate( locale.parse( value ) );
} else {
- return locale.format( this.option( "value" ) );
+ return this._format( this.option( "value" ) );
}
},
if ( key === "locale" ) {
this._setLocale( value );
- this.date.setAttributes( this.options.locale );
+ this.date.setAttributes( this._calendarDateOptions );
this.refresh();
}
}
this._setLocale( this.options.locale );
if ( $.type( this.options.max ) === "string" ) {
- this.options.max = this.options.locale.parseYMD( this.options.max );
+ this.options.max = this._parseYMD( this.options.max );
}
if ( $.type( this.options.min ) === "string" ) {
- this.options.min = this.options.locale.parseYMD( this.options.min );
+ this.options.min = this._parseYMD( this.options.min );
}
this._createCalendar();
},
_setLocale: function( locale ) {
- if ( typeof locale === "string" ) {
- globalize = new Globalize( locale );
- locale = {
- _locale: locale,
- format: function( date ) {
- return globalize.formatDate( date, { date: "short" } );
- },
- parse: function( stringDate ) {
- return globalize.parseDate( stringDate, { date: "short" } );
- },
- parseYMD: function( stringDate ) {
- return globalize.parseDate( stringDate, { pattern: "yyyy-MM-dd" } );
- }
- };
- }
- this.options.locale = locale;
+ var globalize = new Globalize( locale );
+
+ this._format = function( date ) {
+ return globalize.formatDate( date, { date: "short" } );
+ };
+
+ this._parse = function( stringDate ) {
+ return globalize.parseDate( stringDate, { date: "short" } );
+ };
+
+ this._parseYMD = function( stringDate ) {
+ return globalize.parseDate( stringDate, { pattern: "yyyy-MM-dd" } );
+ };
},
_buildPosition: function() {
value: function( value ) {
if ( arguments.length ) {
- this.valueAsDate( this.options.locale.parse( value ) );
+ this.valueAsDate( this._parse( value ) );
} else {
return this._getParsedValue() ? this.element.val() : null;
}
if ( arguments.length ) {
if ( this.calendarInstance._isValid( value ) ) {
this.calendarInstance.valueAsDate( value );
- this.element.val( this.options.locale.format( value ) );
+ this.element.val( this._format( value ) );
}
} else {
return this._getParsedValue();
},
_getParsedValue: function() {
- return this.options.locale.parse( this.element.val() );
+ return this._parse( this.element.val() );
},
_setOption: function( key, value ) {