diff options
author | Andrew Dolgov <[email protected]> | 2011-11-08 20:40:44 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2011-11-08 20:40:44 +0400 |
commit | 81bea17aefb26859f825b9293c7c99192874806e (patch) | |
tree | fb244408ca271affa2899adb634788802c9a89d8 /lib/dojo/date/locale.js | |
parent | 870a70e109ac9e80a88047044530de53d0404ec7 (diff) |
upgrade Dojo to 1.6.1
Diffstat (limited to 'lib/dojo/date/locale.js')
-rw-r--r-- | lib/dojo/date/locale.js | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/lib/dojo/date/locale.js b/lib/dojo/date/locale.js index c66da2331..9b6b4fa62 100644 --- a/lib/dojo/date/locale.js +++ b/lib/dojo/date/locale.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -8,18 +8,20 @@ if(!dojo._hasResource["dojo.date.locale"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. dojo._hasResource["dojo.date.locale"] = true; dojo.provide("dojo.date.locale"); - -// Localization methods for Date. Honor local customs using locale-dependent dojo.cldr data. - dojo.require("dojo.date"); dojo.require("dojo.cldr.supplemental"); dojo.require("dojo.regexp"); dojo.require("dojo.string"); dojo.require("dojo.i18n"); +dojo.requireLocalization("dojo.cldr", "gregorian", null, "ROOT,ar,ca,cs,da,de,el,en,en-au,en-ca,en-gb,es,fi,fr,fr-ch,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-hant,zh-hk,zh-tw"); + +dojo.getObject("date.locale", true, dojo); + +// Localization methods for Date. Honor local customs using locale-dependent dojo.cldr data. + // Load the bundles containing localization information for // names and formats -dojo.requireLocalization("dojo.cldr", "gregorian", null, "ROOT,ar,ca,cs,da,de,el,en,en-au,en-ca,en-gb,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ru,sk,sl,sv,th,tr,zh,zh-tw"); //NOTE: Everything in this module assumes Gregorian calendars. // Other calendars will be implemented in separate modules. @@ -91,7 +93,7 @@ dojo.requireLocalization("dojo.cldr", "gregorian", null, "ROOT,ar,ca,cs,da,de,el break; case 'a': var timePeriod = (dateObject.getHours() < 12) ? 'am' : 'pm'; - s = bundle['dayPeriods-format-wide-' + timePeriod]; + s = options[timePeriod] || bundle['dayPeriods-format-wide-' + timePeriod]; break; case 'h': case 'H': @@ -292,20 +294,23 @@ dojo.date.locale.parse = function(/*String*/value, /*dojo.date.locale.__FormatOp // formatting lengths may be chosen, with "full" used by default. // Custom patterns may be used or registered with translations using // the dojo.date.locale.addCustomFormats method. - // + // // Formatting patterns are implemented using [the syntax described at // unicode.org](http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns) - // When two digit years are used, a century is chosen according to a sliding + // When two digit years are used, a century is chosen according to a sliding // window of 80 years before and 20 years after present year, for both `yy` and `yyyy` patterns. // year < 100CE requires strict mode. // // value: // A string representation of a date - var info = dojo.date.locale._parseInfo(options), + // remove non-printing bidi control chars from input and pattern + var controlChars = /[\u200E\u200F\u202A\u202E]/g, + info = dojo.date.locale._parseInfo(options), tokens = info.tokens, bundle = info.bundle, - re = new RegExp("^" + info.regexp + "$", info.strict ? "" : "i"), - match = re.exec(value); + re = new RegExp("^" + info.regexp.replace(controlChars, "") + "$", + info.strict ? "" : "i"), + match = re.exec(value && value.replace(controlChars, "")); if(!match){ return null; } // null @@ -444,7 +449,7 @@ dojo.date.locale.parse = function(/*String*/value, /*dojo.date.locale.__FormatOp result[3] = 0; //12am -> 0 } - //TODO: implement a getWeekday() method in order to test + //TODO: implement a getWeekday() method in order to test //validity of input strings containing 'EEE' or 'EEEE'... var dateObject = new Date(result[0], result[1], result[2], result[3], result[4], result[5], result[6]); // Date @@ -484,7 +489,7 @@ function _processPattern(pattern, applyPattern, applyLiteral, applyAll){ applyLiteral = applyLiteral || identity; applyAll = applyAll || identity; - //split on single quotes (which escape literals in date format strings) + //split on single quotes (which escape literals in date format strings) //but preserve escaped single quotes (e.g., o''clock) var chunks = pattern.match(/(''|[^'])+/g), literal = pattern.charAt(0) == "'"; @@ -520,31 +525,31 @@ function _buildDateTimeRE(tokens, bundle, options, pattern){ s = '\\d{2,4}'; break; case 'M': - s = (l>2) ? '\\S+?' : p2+'[1-9]|1[0-2]'; + s = (l>2) ? '\\S+?' : '1[0-2]|'+p2+'[1-9]'; break; case 'D': - s = p2+'[1-9]|'+p3+'[1-9][0-9]|[12][0-9][0-9]|3[0-5][0-9]|36[0-6]'; + s = '[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|'+p3+'[1-9][0-9]|'+p2+'[1-9]'; break; case 'd': s = '3[01]|[12]\\d|'+p2+'[1-9]'; break; case 'w': - s = p2+'[1-9]|[1-4][0-9]|5[0-3]'; + s = '[1-4][0-9]|5[0-3]|'+p2+'[1-9]'; break; case 'E': s = '\\S+'; break; case 'h': //hour (1-12) - s = p2+'[1-9]|1[0-2]'; + s = '1[0-2]|'+p2+'[1-9]'; break; case 'k': //hour (0-11) - s = p2+'\\d|1[01]'; + s = '1[01]|'+p2+'\\d'; break; case 'H': //hour (0-23) - s = p2+'\\d|1\\d|2[0-3]'; + s = '1\\d|2[0-3]|'+p2+'\\d'; break; case 'K': //hour (1-24) - s = p2+'[1-9]|1\\d|2[0-4]'; + s = '1\\d|2[0-4]|'+p2+'[1-9]'; break; case 'm': case 's': @@ -556,10 +561,8 @@ function _buildDateTimeRE(tokens, bundle, options, pattern){ case 'a': var am = options.am || bundle['dayPeriods-format-wide-am'], pm = options.pm || bundle['dayPeriods-format-wide-pm']; - if(options.strict){ - s = am + '|' + pm; - }else{ - s = am + '|' + pm; + s = am + '|' + pm; + if(!options.strict){ if(am != am.toLowerCase()){ s += '|' + am.toLowerCase(); } if(pm != pm.toLowerCase()){ s += '|' + pm.toLowerCase(); } if(s.indexOf('.') != -1){ s += '|' + s.replace(/\./g, ""); } |