@@ -15,7 +15,7 @@ var PARENT = dv.DataValue;
15
15
*
16
16
* @param {string } iso8601
17
17
* @param {Object } [options]
18
- * @param {string } [options.calendarModel=dataValues.TimeValue.CALENDARS.GREGORIAN.uri ]
18
+ * @param {string } [options.calendarModel=dataValues.TimeValue.CALENDARS.GREGORIAN]
19
19
* Wikidata URL of the calendar model.
20
20
* @param {number } [options.precision=dataValues.TimeValue.PRECISIONS.DAY]
21
21
* @param {number } [options.before=0]
@@ -40,7 +40,7 @@ var SELF = dv.TimeValue = util.inherit( 'DvTimeValue', PARENT, function( iso8601
40
40
}
41
41
42
42
this . _options = {
43
- calendarModel : SELF . CALENDARS . GREGORIAN . uri ,
43
+ calendarModel : SELF . CALENDARS . GREGORIAN ,
44
44
precision : SELF . getPrecisionById ( 'DAY' ) ,
45
45
before : 0 ,
46
46
after : 0 ,
@@ -74,7 +74,7 @@ var SELF = dv.TimeValue = util.inherit( 'DvTimeValue', PARENT, function( iso8601
74
74
* @throws {Error } if a value to set is not specified properly.
75
75
*/
76
76
_setOption : function ( key , value ) {
77
- if ( key === 'calendarModel' && SELF . getCalendarModelTextByUri ( value ) === null ) {
77
+ if ( key === 'calendarModel' && ! SELF . getCalendarModelKeyByUri ( value ) ) {
78
78
throw new Error ( 'Setting ' + key + ': No valid calendar model URI provided' ) ;
79
79
}
80
80
if ( $ . inArray ( key , [ 'precision' , 'before' , 'after' , 'timezone' ] ) !== - 1
@@ -250,41 +250,37 @@ SELF.TYPE = 'time';
250
250
251
251
// TODO: Inject configurations...
252
252
/**
253
- * Calendar configuration .
253
+ * Known calendar model URIs .
254
254
* @property {Object }
255
255
* @static
256
256
* @since 0.7
257
257
*/
258
258
SELF . CALENDARS = {
259
- GREGORIAN : {
260
- text : 'Gregorian' ,
261
- uri : 'http://www.wikidata.org/entity/Q1985727'
262
- } ,
263
- JULIAN : {
264
- text : 'Julian' ,
265
- uri : 'http://www.wikidata.org/entity/Q1985786'
266
- }
259
+ GREGORIAN : 'http://www.wikidata.org/entity/Q1985727' ,
260
+ JULIAN : 'http://www.wikidata.org/entity/Q1985786'
267
261
} ;
268
262
269
263
/**
270
- * Retrieves a calendar model text by its URI.
264
+ * Retrieves a lower-cased calendar model key string, e.g. "gregorian", by its URI.
271
265
* @static
272
266
* @since 0.7
273
267
*
274
268
* @param {string } uri
275
269
* @return {string|null }
276
270
*/
277
- SELF . getCalendarModelTextByUri = function ( uri ) {
278
- var text = null ;
271
+ SELF . getCalendarModelKeyByUri = function ( uri ) {
272
+ var key = null ;
279
273
280
- $ . each ( SELF . CALENDARS , function ( id , calendar ) {
281
- if ( calendar . uri === uri ) {
282
- text = calendar . text ;
274
+ $ . each ( SELF . CALENDARS , function ( knownKey , knownUri ) {
275
+ if ( uri === knownUri ) {
276
+ key = knownKey . toLowerCase ( ) ;
277
+ return false ;
283
278
}
284
- return text === null ;
279
+
280
+ return true ;
285
281
} ) ;
286
282
287
- return text ;
283
+ return key ;
288
284
} ;
289
285
290
286
/**
0 commit comments