Skip to content

Commit 5d044dd

Browse files
rxaviersfnagel
authored andcommitted
(fix) Datepicker: Use Globalize 1.0.0
- user cannot provide locale: {fn1: ..., fn2:...} with all the formatters and parsers
1 parent b6d7436 commit 5d044dd

File tree

3 files changed

+31
-44
lines changed

3 files changed

+31
-44
lines changed

ui/calendar.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ return $.widget( "ui.calendar", {
7171

7272
this._setLocale( this.options.locale );
7373

74-
this.date = new $.ui.calendarDate( this.options.value, this.options.locale );
75-
this.date = $.date( this.options.value, this.options.dateFormat );
74+
this.date = new $.ui.calendarDate( this.options.value, this._calendarDateOptions );
7675
this.viewDate = this.date.clone();
7776
this.viewDate.eachDay = this.options.eachDay;
7877

@@ -178,23 +177,17 @@ return $.widget( "ui.calendar", {
178177
},
179178

180179
_setLocale: function( locale ) {
181-
var globalize;
180+
var globalize = new Globalize( locale );
182181

183-
if ( typeof locale === "string" ) {
184-
globalize = new Globalize( locale );
185-
locale = {
186-
format: function( date ) {
182+
this._format = function( date ) {
187183
return globalize.formatDate( date, { date: "short" } );
188-
},
189-
parse: function( stringDate ) {
184+
};
185+
186+
this._parse = function( stringDate ) {
190187
return globalize.parseDate( stringDate, { date: "short" } );
191-
}
192188
};
193-
}
194189

195-
if ( !locale.firstDay ) {
196-
globalize = globalize || new Globalize( locale._locale );
197-
$.extend( locale, {
190+
this._calendarDateOptions = {
198191
firstDay: globalize.cldr.supplemental.weekData.firstDay(),
199192
formatWeekdayShort: function( date ) {
200193

@@ -212,11 +205,9 @@ return $.widget( "ui.calendar", {
212205
},
213206
formatWeekOfYear: function( date ) {
214207
return globalize.formatDate( date, { pattern: "w" } );
215-
}
216-
});
217-
}
218-
219-
this.options.locale = locale;
208+
},
209+
parse: this._parse
210+
};
220211
},
221212

222213
_createCalendar: function() {
@@ -562,11 +553,10 @@ return $.widget( "ui.calendar", {
562553
},
563554

564555
value: function( value ) {
565-
var locale = this.options.locale;
566556
if ( arguments.length ) {
567557
this.valueAsDate( locale.parse( value ) );
568558
} else {
569-
return locale.format( this.option( "value" ) );
559+
return this._format( this.option( "value" ) );
570560
}
571561
},
572562

@@ -658,7 +648,7 @@ return $.widget( "ui.calendar", {
658648

659649
if ( key === "locale" ) {
660650
this._setLocale( value );
661-
this.date.setAttributes( this.options.locale );
651+
this.date.setAttributes( this._calendarDateOptions );
662652
this.refresh();
663653
}
664654
}

ui/calendar/date.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var _Date,
3838

3939
_Date = function( date, attributes ) {
4040
if ( !( this instanceof _Date ) ) {
41-
return new _Date( date, options );
41+
return new _Date( date, attributes );
4242
}
4343

4444
this.setAttributes( attributes );

ui/datepicker.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ var widget = $.widget( "ui.datepicker", {
6161
this._setLocale( this.options.locale );
6262

6363
if ( $.type( this.options.max ) === "string" ) {
64-
this.options.max = this.options.locale.parseYMD( this.options.max );
64+
this.options.max = this._parseYMD( this.options.max );
6565
}
6666
if ( $.type( this.options.min ) === "string" ) {
67-
this.options.min = this.options.locale.parseYMD( this.options.min );
67+
this.options.min = this._parseYMD( this.options.min );
6868
}
6969

7070
this._createCalendar();
@@ -282,22 +282,19 @@ var widget = $.widget( "ui.datepicker", {
282282
},
283283

284284
_setLocale: function( locale ) {
285-
if ( typeof locale === "string" ) {
286-
globalize = new Globalize( locale );
287-
locale = {
288-
_locale: locale,
289-
format: function( date ) {
290-
return globalize.formatDate( date, { date: "short" } );
291-
},
292-
parse: function( stringDate ) {
293-
return globalize.parseDate( stringDate, { date: "short" } );
294-
},
295-
parseYMD: function( stringDate ) {
296-
return globalize.parseDate( stringDate, { pattern: "yyyy-MM-dd" } );
297-
}
298-
};
299-
}
300-
this.options.locale = locale;
285+
var globalize = new Globalize( locale );
286+
287+
this._format = function( date ) {
288+
return globalize.formatDate( date, { date: "short" } );
289+
};
290+
291+
this._parse = function( stringDate ) {
292+
return globalize.parseDate( stringDate, { date: "short" } );
293+
};
294+
295+
this._parseYMD = function( stringDate ) {
296+
return globalize.parseDate( stringDate, { pattern: "yyyy-MM-dd" } );
297+
};
301298
},
302299

303300
_buildPosition: function() {
@@ -306,7 +303,7 @@ var widget = $.widget( "ui.datepicker", {
306303

307304
value: function( value ) {
308305
if ( arguments.length ) {
309-
this.valueAsDate( this.options.locale.parse( value ) );
306+
this.valueAsDate( this._parse( value ) );
310307
} else {
311308
return this._getParsedValue() ? this.element.val() : null;
312309
}
@@ -316,7 +313,7 @@ var widget = $.widget( "ui.datepicker", {
316313
if ( arguments.length ) {
317314
if ( this.calendarInstance._isValid( value ) ) {
318315
this.calendarInstance.valueAsDate( value );
319-
this.element.val( this.options.locale.format( value ) );
316+
this.element.val( this._format( value ) );
320317
}
321318
} else {
322319
return this._getParsedValue();
@@ -338,7 +335,7 @@ var widget = $.widget( "ui.datepicker", {
338335
},
339336

340337
_getParsedValue: function() {
341-
return this.options.locale.parse( this.element.val() );
338+
return this._parse( this.element.val() );
342339
},
343340

344341
_setOption: function( key, value ) {

0 commit comments

Comments
 (0)