[483] | 1 | define(["doh", "dojo/_base/array", "dojo/i18n", "dojo/_base/kernel", "dojo/date", "dojo/date/locale"], |
---|
| 2 | function(doh, array, i18n, kernel, date, locale){ |
---|
| 3 | |
---|
| 4 | doh.register("tests.date.locale", [ |
---|
| 5 | { |
---|
| 6 | // Test formatting and parsing of dates in various locales pre-built in dojo.cldr |
---|
| 7 | // NOTE: we can't set djConfig.extraLocale before bootstrapping unit tests, so directly |
---|
| 8 | // load resources here for specific locales: |
---|
| 9 | |
---|
| 10 | name: "date.locale", |
---|
| 11 | runTest: function(t){ |
---|
| 12 | var partLocaleList = ["en-us", "fr-fr", "es", "de-at", "ja-jp", "zh-cn"]; |
---|
| 13 | if(kernel.isAsync){ |
---|
| 14 | var def = new doh.Deferred(), |
---|
| 15 | deps = array.map(partLocaleList, function(locale){ |
---|
| 16 | return i18n.getL10nName("dojo/cldr", "gregorian", locale); |
---|
| 17 | }); |
---|
| 18 | require(deps, function(){ |
---|
| 19 | def.callback(true); |
---|
| 20 | }); |
---|
| 21 | return def; |
---|
| 22 | }else{ // tests for the v1.x loader/i18n machinery |
---|
| 23 | array.forEach(partLocaleList, function(locale){ |
---|
| 24 | dojo.requireLocalization("dojo.cldr", "gregorian", locale); |
---|
| 25 | }); |
---|
| 26 | } |
---|
| 27 | }, |
---|
| 28 | tearDown: function(){ |
---|
| 29 | //Clean up bundles that should not exist if |
---|
| 30 | //the test is re-run. |
---|
| 31 | //delete dojo.cldr.nls.gregorian; |
---|
| 32 | } |
---|
| 33 | }, |
---|
| 34 | { |
---|
| 35 | name: "isWeekend", |
---|
| 36 | runTest: function(t){ |
---|
| 37 | var thursday = new Date(2006, 8, 21); |
---|
| 38 | var friday = new Date(2006, 8, 22); |
---|
| 39 | var saturday = new Date(2006, 8, 23); |
---|
| 40 | var sunday = new Date(2006, 8, 24); |
---|
| 41 | var monday = new Date(2006, 8, 25); |
---|
| 42 | t.f(locale.isWeekend(thursday, 'en-us')); |
---|
| 43 | t.t(locale.isWeekend(saturday, 'en-us')); |
---|
| 44 | t.t(locale.isWeekend(sunday, 'en-us')); |
---|
| 45 | t.f(locale.isWeekend(monday, 'en-us')); |
---|
| 46 | // t.f(locale.isWeekend(saturday, 'en-in')); |
---|
| 47 | // t.t(locale.isWeekend(sunday, 'en-in')); |
---|
| 48 | // t.f(locale.isWeekend(monday, 'en-in')); |
---|
| 49 | // t.t(locale.isWeekend(friday, 'he-il')); |
---|
| 50 | // t.f(locale.isWeekend(sunday, 'he-il')); |
---|
| 51 | } |
---|
| 52 | }, |
---|
| 53 | { |
---|
| 54 | name: "format", |
---|
| 55 | runTest: function(t){ |
---|
| 56 | |
---|
| 57 | var date = new Date(2006, 7, 11, 0, 55, 12, 345); |
---|
| 58 | |
---|
| 59 | t.is("Friday, August 11, 2006", locale.format(date, {formatLength:'full',selector:'date', locale:'en-us'})); |
---|
| 60 | t.is("vendredi 11 ao\xFBt 2006", locale.format(date, {formatLength:'full',selector:'date', locale:'fr-fr'})); |
---|
| 61 | t.is("Freitag, 11. August 2006", locale.format(date, {formatLength:'full',selector:'date', locale:'de-at'})); |
---|
| 62 | t.is("2006\u5E748\u670811\u65E5\u91D1\u66DC\u65E5", locale.format(date, {formatLength:'full',selector:'date', locale:'ja-jp'})); |
---|
| 63 | |
---|
| 64 | t.is("8/11/06", locale.format(date, {formatLength:'short',selector:'date', locale:'en-us'})); |
---|
| 65 | t.is("11/08/2006", locale.format(date, {formatLength:'short',selector:'date', locale:'fr-fr'})); |
---|
| 66 | t.is("11.08.06", locale.format(date, {formatLength:'short',selector:'date', locale:'de-at'})); |
---|
| 67 | t.is("2006/08/11", locale.format(date, {formatLength:'short',selector:'date', locale:'ja-jp'})); |
---|
| 68 | |
---|
| 69 | t.is("6", locale.format(date, {datePattern:'E', selector:'date'})); |
---|
| 70 | |
---|
| 71 | t.is("12:55 AM", locale.format(date, {formatLength:'short',selector:'time', locale:'en-us'})); |
---|
| 72 | t.is("12:55:12", locale.format(date, {timePattern:'h:m:s',selector:'time'})); |
---|
| 73 | t.is("12:55:12.35", locale.format(date, {timePattern:'h:m:s.SS',selector:'time'})); |
---|
| 74 | t.is("24:55:12.35", locale.format(date, {timePattern:'k:m:s.SS',selector:'time'})); |
---|
| 75 | t.is("0:55:12.35", locale.format(date, {timePattern:'H:m:s.SS',selector:'time'})); |
---|
| 76 | t.is("0:55:12.35", locale.format(date, {timePattern:'K:m:s.SS',selector:'time'})); |
---|
| 77 | |
---|
| 78 | t.is("11082006", locale.format(date, {datePattern:"ddMMyyyy", selector:"date"})); |
---|
| 79 | |
---|
| 80 | t.is("12 o'clock AM", locale.format(date, {datePattern:"hh 'o''clock' a", selector:"date", locale: 'en'})); |
---|
| 81 | |
---|
| 82 | t.is("11/08/2006, 12:55am", locale.format(date, {datePattern:"dd/MM/yyyy", timePattern:"hh:mma", locale: 'en', am:"am", pm:"pm"})); |
---|
| 83 | |
---|
| 84 | // compare without timezone |
---|
| 85 | t.is("\u4e0a\u534812:55:12", locale.format(date, {formatLength:'full',selector:'time', locale:'zh-cn'}).replace(/^.*(\u4e0a\u5348.*)/,"$1")); |
---|
| 86 | } |
---|
| 87 | }, |
---|
| 88 | { |
---|
| 89 | name: "parse_dates", |
---|
| 90 | runTest: function(t){ |
---|
| 91 | |
---|
| 92 | var aug_11_2006 = new Date(2006, 7, 11, 0); |
---|
| 93 | |
---|
| 94 | //en: 'short' fmt: M/d/yy |
---|
| 95 | // Tolerate either 8 or 08 for month part. |
---|
| 96 | t.is( aug_11_2006, locale.parse("08/11/06", {formatLength:'short', selector:'date', locale:'en'})); |
---|
| 97 | t.is( aug_11_2006, locale.parse("8/11/06", {formatLength:'short', selector:'date', locale:'en'})); |
---|
| 98 | // Tolerate yyyy input in yy part... |
---|
| 99 | t.is( aug_11_2006, locale.parse("8/11/2006", {formatLength:'short', selector:'date', locale:'en'})); |
---|
| 100 | // ...but not in strict mode |
---|
| 101 | t.f( Boolean(locale.parse("8/11/2006", {formatLength:'short', selector:'date', locale:'en', strict:true}))); |
---|
| 102 | |
---|
| 103 | // test dates with no spaces |
---|
| 104 | t.is( aug_11_2006, locale.parse("11Aug2006", {selector: 'date', datePattern: 'ddMMMyyyy', locale: 'en'})); |
---|
| 105 | t.is( new Date(2006, 7, 1), locale.parse("Aug2006", {selector: 'date', datePattern: 'MMMyyyy', locale: 'en'})); |
---|
| 106 | t.is( new Date(2010, 10, 19), locale.parse("111910", {fullyear: false, datePattern: "MMddyy", selector: "date"})); |
---|
| 107 | |
---|
| 108 | //en: 'medium' fmt: MMM d, yyyy |
---|
| 109 | // Tolerate either 8 or 08 for month part. |
---|
| 110 | t.is( aug_11_2006, locale.parse("Aug 11, 2006", {formatLength:'medium', selector:'date', locale:'en'})); |
---|
| 111 | t.is( aug_11_2006, locale.parse("Aug 11, 2006", {formatLength:'medium', selector:'date', locale:'en'})); |
---|
| 112 | // Tolerate abbreviating period in month part... |
---|
| 113 | t.is( aug_11_2006, locale.parse("Aug. 11, 2006", {formatLength:'medium', selector:'date', locale:'en'})); |
---|
| 114 | // ...but not in strict mode |
---|
| 115 | t.f( Boolean(locale.parse("Aug. 11, 2006", {formatLength:'medium', selector:'date', locale:'en', strict:true}))); |
---|
| 116 | |
---|
| 117 | // Note: 06 for year part will be translated literally as the year 6 C.E. |
---|
| 118 | var aug_11_06CE = new Date(2006, 7, 11, 0); |
---|
| 119 | aug_11_06CE.setFullYear(6); //literally the year 6 C.E. |
---|
| 120 | t.is( aug_11_06CE, locale.parse("Aug 11, 06", {selector:'date', datePattern:'MMM dd, yyyy', locale: 'en', strict:true})); |
---|
| 121 | |
---|
| 122 | //en: 'long' fmt: MMMM d, yyyy |
---|
| 123 | t.is( aug_11_2006, locale.parse("August 11, 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
| 124 | |
---|
| 125 | //en: 'full' fmt: EEEE, MMMM d, yyyy |
---|
| 126 | t.is( aug_11_2006, locale.parse("Friday, August 11, 2006", {formatLength:'full', selector:'date', locale:'en'})); |
---|
| 127 | //TODO: wrong day-of-week should fail |
---|
| 128 | //t.f( Boolean(locale.parse("Thursday, August 11, 2006", {formatLength:'full', selector:'date', locale:'en'}))); |
---|
| 129 | //TODO: Whitespace tolerance |
---|
| 130 | // t.is( aug_11_2006, locale.parse(" August 11, 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
| 131 | // t.is( aug_11_2006, locale.parse("August 11, 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
| 132 | // t.is( aug_11_2006, locale.parse("August 11 , 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
| 133 | // t.is( aug_11_2006, locale.parse("August 11, 2006", {formatLength:'long', selector:'date', locale:'en'})); |
---|
| 134 | // t.is( aug_11_2006, locale.parse("August 11, 2006 ", {formatLength:'long', selector:'date', locale:'en'})); |
---|
| 135 | |
---|
| 136 | //Simple Validation Tests |
---|
| 137 | //catch "month" > 12 (note: month/day reversals are common when user expectation isn't met wrt european versus US formats) |
---|
| 138 | t.f( Boolean(locale.parse("15/1/2005", {formatLength:'short', selector:'date', locale:'en'}))); |
---|
| 139 | //day of month typo rolls over to the next month |
---|
| 140 | t.f( Boolean(locale.parse("Aug 32, 2006", {formatLength:'medium', selector:'date', locale:'en'}))); |
---|
| 141 | |
---|
| 142 | //German (de) |
---|
| 143 | t.is( aug_11_2006, locale.parse("11.08.06", {formatLength:'short', selector:'date', locale:'de'})); |
---|
| 144 | t.f( Boolean(locale.parse("11.8/06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
| 145 | t.f( Boolean(locale.parse("11.8x06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
| 146 | t.f( Boolean(locale.parse("11.13.06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
| 147 | t.f( Boolean(locale.parse("11.0.06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
| 148 | t.f( Boolean(locale.parse("32.08.06", {formatLength:'short', selector:'date', locale:'de'}))); |
---|
| 149 | |
---|
| 150 | //Spanish (es) |
---|
| 151 | //es: 'short' fmt: d/MM/yy |
---|
| 152 | t.is( aug_11_2006, locale.parse("11/08/06", {formatLength:'short', selector:'date', locale:'es'})); |
---|
| 153 | t.is( aug_11_2006, locale.parse("11/8/06", {formatLength:'short', selector:'date', locale:'es'})); |
---|
| 154 | // Tolerate yyyy input in yy part... |
---|
| 155 | t.is( aug_11_2006, locale.parse("11/8/2006", {formatLength:'short', selector:'date', locale:'es'})); |
---|
| 156 | // ...but not in strict mode |
---|
| 157 | t.f( Boolean(locale.parse("11/8/2006", {formatLength:'short', selector:'date', locale:'es', strict:true}))); |
---|
| 158 | //es: 'medium' fmt: dd-MMM-yy (not anymore as of CLDR 1.5.1) |
---|
| 159 | // t.is( aug_11_2006, locale.parse("11-ago-06", {formatLength:'medium', selector:'date', locale:'es'})); |
---|
| 160 | // t.is( aug_11_2006, locale.parse("11-ago-2006", {formatLength:'medium', selector:'date', locale:'es'})); |
---|
| 161 | // Tolerate abbreviating period in month part... |
---|
| 162 | // t.is( aug_11_2006, locale.parse("11-ago.-2006", {formatLength:'medium', selector:'date', locale:'es'})); |
---|
| 163 | // ...but not in strict mode |
---|
| 164 | // t.f( Boolean(locale.parse("11-ago.-2006", {formatLength:'medium', selector:'date', locale:'es', strict:true}))); |
---|
| 165 | //es: 'long' fmt: d' de 'MMMM' de 'yyyy |
---|
| 166 | t.is( aug_11_2006, locale.parse("11 de agosto de 2006", {formatLength:'long', selector:'date', locale:'es'})); |
---|
| 167 | //case-insensitive month... |
---|
| 168 | t.is( aug_11_2006, locale.parse("11 de Agosto de 2006", {formatLength:'long', selector:'date', locale:'es'})); |
---|
| 169 | //...but not in strict mode |
---|
| 170 | t.f( Boolean(locale.parse("11 de Agosto de 2006", {formatLength:'long', selector:'date', locale:'es', strict:true}))); |
---|
| 171 | //es 'full' fmt: EEEE d' de 'MMMM' de 'yyyy |
---|
| 172 | t.is( aug_11_2006, locale.parse("viernes, 11 de agosto de 2006", {formatLength:'full', selector:'date', locale:'es'})); |
---|
| 173 | //case-insensitive day-of-week... |
---|
| 174 | t.is( aug_11_2006, locale.parse("Viernes, 11 de agosto de 2006", {formatLength:'full', selector:'date', locale:'es'})); |
---|
| 175 | //...but not in strict mode |
---|
| 176 | t.f( Boolean(locale.parse("Viernes, 11 de agosto de 2006", {formatLength:'full', selector:'date', locale:'es', strict:true}))); |
---|
| 177 | |
---|
| 178 | //Japanese (ja) |
---|
| 179 | //note: to avoid garbling from non-utf8-aware editors that may touch this file, using the \uNNNN format |
---|
| 180 | //for expressing double-byte chars. |
---|
| 181 | //toshi (year): \u5e74 |
---|
| 182 | //getsu (month): \u6708 |
---|
| 183 | //nichi (day): \u65e5 |
---|
| 184 | //kinyoubi (Friday): \u91d1\u66dc\u65e5 |
---|
| 185 | //zenkaku space: \u3000 |
---|
| 186 | |
---|
| 187 | //ja: 'short' fmt: yy/MM/dd (note: the "short" fmt isn't actually defined in the CLDR data...) |
---|
| 188 | t.is( aug_11_2006, locale.parse("06/08/11", {formatLength:'short', selector:'date', locale:'ja'})); |
---|
| 189 | t.is( aug_11_2006, locale.parse("06/8/11", {formatLength:'short', selector:'date', locale:'ja'})); |
---|
| 190 | // Tolerate yyyy input in yy part... |
---|
| 191 | t.is( aug_11_2006, locale.parse("2006/8/11", {formatLength:'short', selector:'date', locale:'ja'})); |
---|
| 192 | // ...but not in strict mode |
---|
| 193 | t.f( Boolean(locale.parse("2006/8/11", {formatLength:'short', selector:'date', locale:'ja', strict:true}))); |
---|
| 194 | //ja: 'medium' fmt: yyyy/MM/dd |
---|
| 195 | t.is( aug_11_2006, locale.parse("2006/08/11", {formatLength:'medium', selector:'date', locale:'ja'})); |
---|
| 196 | t.is( aug_11_2006, locale.parse("2006/8/11", {formatLength:'medium', selector:'date', locale:'ja'})); |
---|
| 197 | //ja: 'long' fmt: yyyy'\u5e74'\u6708'd'\u65e5' |
---|
| 198 | t.is( aug_11_2006, locale.parse("2006\u5e748\u670811\u65e5", {formatLength:'long', selector:'date', locale:'ja'})); |
---|
| 199 | //ja 'full' fmt: yyyy'\u5e74'M'\u6708'd'\u65e5'EEEE |
---|
| 200 | t.is( aug_11_2006, locale.parse("2006\u5e748\u670811\u65e5\u91d1\u66dc\u65e5", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
| 201 | |
---|
| 202 | //TODO: Whitespace tolerance |
---|
| 203 | //tolerate ascii space |
---|
| 204 | // t.is( aug_11_2006, locale.parse(" 2006\u5e748\u670811\u65e5\u91d1\u66dc\u65e5 ", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
| 205 | // t.is( aug_11_2006, locale.parse("2006\u5e74 8\u670811\u65e5 \u91d1\u66dc\u65e5", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
| 206 | //tolerate zenkaku space |
---|
| 207 | // t.is( aug_11_2006, locale.parse("\u30002006\u5e748\u670811\u65e5\u91d1\u66dc\u65e5\u3000", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
| 208 | // t.is( aug_11_2006, locale.parse("2006\u5e74\u30008\u670811\u65e5\u3000\u91d1\u66dc\u65e5", {formatLength:'full', selector:'date', locale:'ja'})); |
---|
| 209 | |
---|
| 210 | var apr_11_2006 = new Date(2006, 3, 11, 0); |
---|
| 211 | //Roundtrip |
---|
| 212 | var options={formatLength:'medium',selector:'date', locale:'fr-fr'}; |
---|
| 213 | t.is(0, date.compare(apr_11_2006, locale.parse(locale.format(apr_11_2006, options), options))); |
---|
| 214 | |
---|
| 215 | //Tolerance for abbreviations |
---|
| 216 | t.is(0, date.compare(apr_11_2006, locale.parse("11 avr 06", options))); |
---|
| 217 | } |
---|
| 218 | }, |
---|
| 219 | { |
---|
| 220 | name: "parse_dates_neg", |
---|
| 221 | runTest: function(t){ |
---|
| 222 | t.f(Boolean(locale.parse("2/29/2007", {formatLength: 'short', selector: 'date', locale: 'en'}))); |
---|
| 223 | t.f(Boolean(locale.parse("4/31/2007", {formatLength: 'short', selector: 'date', locale: 'en'}))); |
---|
| 224 | t.f(Boolean(locale.parse("Decemb 30, 2007", {formatLength: 'long', selector: 'date', locale: 'en'}))); |
---|
| 225 | } |
---|
| 226 | }, |
---|
| 227 | { |
---|
| 228 | name: "parse_datetimes", |
---|
| 229 | runTest: function(t){ |
---|
| 230 | |
---|
| 231 | var aug_11_2006_12_30_am = new Date(2006, 7, 11, 0, 30); |
---|
| 232 | var aug_11_2006_12_30_pm = new Date(2006, 7, 11, 12, 30); |
---|
| 233 | |
---|
| 234 | //en: 'short' datetime fmt: M/d/yy h:mm a |
---|
| 235 | //note: this is concatenation of dateFormat-short and timeFormat-short, |
---|
| 236 | //cldr provisionally defines datetime fmts as well, but we're not using them at the moment |
---|
| 237 | t.is( aug_11_2006_12_30_pm, locale.parse("08/11/06, 12:30 PM", {formatLength:'short', locale:'en'}), 'PM'); |
---|
| 238 | //case-insensitive |
---|
| 239 | t.is( aug_11_2006_12_30_pm, locale.parse("08/11/06, 12:30 pm", {formatLength:'short', locale:'en'}), 'pm'); |
---|
| 240 | //...but not in strict mode |
---|
| 241 | t.f( Boolean(locale.parse("8/11/06, 12:30 pm", {formatLength:'short', locale:'en', strict:true})), 'strict fail'); |
---|
| 242 | t.t( Boolean(locale.parse("8/11/06, 12:30 PM", {formatLength:'short', locale:'en', strict:true})), 'strict pass'); |
---|
| 243 | |
---|
| 244 | t.is( aug_11_2006_12_30_am, locale.parse("08/11/06, 12:30 AM", {formatLength:'short', locale:'en'}), 'AM'); |
---|
| 245 | |
---|
| 246 | t.is( new Date(2006, 7, 11), locale.parse("11082006", {datePattern:"ddMMyyyy", selector:"date"})); |
---|
| 247 | |
---|
| 248 | t.is( new Date(2006, 7, 31), locale.parse("31Aug2006", {datePattern:"ddMMMyyyy", selector:"date", locale:'en'})); |
---|
| 249 | |
---|
| 250 | t.is(new Date(1970,0,7), locale.parse("007", {datePattern:'DDD',selector:'date'})); |
---|
| 251 | t.is(new Date(1970,0,31), locale.parse("031", {datePattern:'DDD',selector:'date'})); |
---|
| 252 | t.is(new Date(1970,3,10), locale.parse("100", {datePattern:'DDD',selector:'date'})); |
---|
| 253 | |
---|
| 254 | t.isNot(null, locale.parse(locale.format(new Date(), {locale:'he', formatLength:'full', selector:'date'}), {locale:'he', formatLength:'full', selector:'date'}), "Hebrew parse"); |
---|
| 255 | |
---|
| 256 | } |
---|
| 257 | }, |
---|
| 258 | { |
---|
| 259 | name: "parse_times", |
---|
| 260 | runTest: function(t){ |
---|
| 261 | var time = new Date(2006, 7, 11, 12, 30); |
---|
| 262 | var tformat = {selector:'time', strict:true, timePattern:"h:mm a", locale:'en'}; |
---|
| 263 | |
---|
| 264 | t.is(time.getHours(), locale.parse("12:30 PM", tformat).getHours()); |
---|
| 265 | t.is(time.getMinutes(), locale.parse("12:30 PM", tformat).getMinutes()); |
---|
| 266 | } |
---|
| 267 | }, |
---|
| 268 | { |
---|
| 269 | name: "format_patterns", |
---|
| 270 | runTest: function(t){ |
---|
| 271 | var time = new Date(2006, 7, 11, 12, 30); |
---|
| 272 | var tformat = {selector:'time', strict:true, timePattern:"h 'o''clock'", locale:'en'}; |
---|
| 273 | t.is(time.getHours(), locale.parse("12 o'clock", tformat).getHours()); |
---|
| 274 | |
---|
| 275 | tformat = {selector:'time', strict:true, timePattern:" 'Hour is' h", locale:'en'}; |
---|
| 276 | t.is(time.getHours(), locale.parse(" Hour is 12", tformat).getHours()); |
---|
| 277 | |
---|
| 278 | tformat = {selector:'time', strict:true, timePattern:"'Hour is' h", locale:'en'}; |
---|
| 279 | t.is(time.getHours(), locale.parse("Hour is 12", tformat).getHours()); |
---|
| 280 | } |
---|
| 281 | }, |
---|
| 282 | { |
---|
| 283 | name: "parse_patterns", |
---|
| 284 | runTest: function(t){ |
---|
| 285 | var time = new Date(2006, 7, 11, 12, 30); |
---|
| 286 | var tformat = {selector:'time', strict:true, timePattern:"h 'o''clock'", locale:'en'}; |
---|
| 287 | t.is(time.getHours(), locale.parse("12 o'clock", tformat).getHours()); |
---|
| 288 | |
---|
| 289 | tformat = {selector:'time', strict:true, timePattern:" 'Hour is' h", locale:'en'}; |
---|
| 290 | t.is(time.getHours(), locale.parse(" Hour is 12", tformat).getHours()); |
---|
| 291 | tformat = {selector:'time', strict:true, timePattern:"'Hour is' h", locale:'en'}; |
---|
| 292 | t.is(time.getHours(), locale.parse("Hour is 12", tformat).getHours()); |
---|
| 293 | } |
---|
| 294 | }, |
---|
| 295 | { |
---|
| 296 | name: "day_of_year", |
---|
| 297 | runTest: function(t){ |
---|
| 298 | |
---|
| 299 | // t.is(23, date.setDayOfYear(new Date(2006,0,1), 23).getDate()); |
---|
| 300 | t.is(1, locale._getDayOfYear(new Date(2006,0,1))); |
---|
| 301 | t.is(32, locale._getDayOfYear(new Date(2006,1,1))); |
---|
| 302 | t.is(72, locale._getDayOfYear(new Date(2007,2,13,0,13))); |
---|
| 303 | t.is(72, locale._getDayOfYear(new Date(2007,2,13,1,13))); |
---|
| 304 | } |
---|
| 305 | }, |
---|
| 306 | { |
---|
| 307 | name: "week_of_year", |
---|
| 308 | runTest: function(t){ |
---|
| 309 | t.is(0, locale._getWeekOfYear(new Date(2000,0,1))); |
---|
| 310 | t.is(1, locale._getWeekOfYear(new Date(2000,0,2))); |
---|
| 311 | t.is(0, locale._getWeekOfYear(new Date(2000,0,2), 1)); |
---|
| 312 | t.is(0, locale._getWeekOfYear(new Date(2007,0,1))); |
---|
| 313 | t.is(1, locale._getWeekOfYear(new Date(2007,0,1), 1)); |
---|
| 314 | t.is(27, locale._getWeekOfYear(new Date(2007,6,14))); |
---|
| 315 | t.is(28, locale._getWeekOfYear(new Date(2007,6,14), 1)); |
---|
| 316 | } |
---|
| 317 | } |
---|
| 318 | ]); |
---|
| 319 | |
---|
| 320 | /* |
---|
| 321 | // workaround deprecated methods. Should decide whether we should convert the tests or add a helper method (in dojo.date?) to do this. |
---|
| 322 | |
---|
| 323 | dojo_validate_isValidTime = function(str, props){ |
---|
| 324 | props = props || {}; |
---|
| 325 | if(!props.format){props.format="h:mm:ss";} |
---|
| 326 | if(!props.am){props.am="a.m.";} |
---|
| 327 | if(!props.pm){props.pm="p.m.";} |
---|
| 328 | var result = false; |
---|
| 329 | if(/[hk]/.test(props.format) && props.format.indexOf('a') == -1){ |
---|
| 330 | result = locale.parse(str, {selector: 'time', timePattern: props.format + " a"}); |
---|
| 331 | } |
---|
| 332 | return Boolean(result || locale.parse(str, {selector: 'time', timePattern: props.format})); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | dojo_validate_is12HourTime = function(str){ |
---|
| 336 | return dojo_validate_isValidTime(str, {format: 'h:mm:ss'}) || dojo_validate_isValidTime(str, {format: 'h:mm'}); |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | dojo_validate_is24HourTime = function(str){ |
---|
| 340 | return dojo_validate_isValidTime(str, {format: 'H:mm:ss'}) || dojo_validate_isValidTime(str, {format: 'H:mm'}); |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | dojo_validate_isValidDate = function(str, fmt){ |
---|
| 344 | return Boolean(locale.parse(str, {selector: 'date', datePattern: fmt})); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | function test_validate_datetime_isValidTime(){ |
---|
| 348 | jum.assertTrue("test1", dojo_validate_isValidTime('5:15:05 pm')); |
---|
| 349 | // FAILURE jum.assertTrue("test2", dojo_validate_isValidTime('5:15:05 p.m.', {pm: "P.M."} )); |
---|
| 350 | jum.assertFalse("test3", dojo_validate_isValidTime('5:15:05 f.m.')); |
---|
| 351 | jum.assertTrue("test4", dojo_validate_isValidTime('5:15 pm', {format: "h:mm a"} ) ); |
---|
| 352 | jum.assertFalse("test5", dojo_validate_isValidTime('5:15 fm', {}) ); |
---|
| 353 | jum.assertTrue("test6", dojo_validate_isValidTime('15:15:00', {format: "H:mm:ss"} ) ); |
---|
| 354 | // FAILURE jum.assertFalse("test7", dojo_validate_isValidTime('15:15:00', {}) ); |
---|
| 355 | jum.assertTrue("test8", dojo_validate_isValidTime('17:01:30', {format: "H:mm:ss"} ) ); |
---|
| 356 | jum.assertFalse("test9", dojo_validate_isValidTime('17:1:30', {format: "H:mm:ss"} ) ); |
---|
| 357 | // FAILURE jum.assertFalse("test10", dojo_validate_isValidTime('17:01:30', {format: "H:m:ss"} ) ); |
---|
| 358 | // Greek |
---|
| 359 | // FAILURE jum.assertTrue("test11", dojo_validate_isValidTime('5:01:30 \u0924\u0924', {am: "\u0928\u0924", pm: "\u0924\u0924"} ) ); |
---|
| 360 | // Italian |
---|
| 361 | jum.assertTrue("test12", dojo_validate_isValidTime('17.01.30', {format: "H.mm.ss"} ) ); |
---|
| 362 | // Mexico |
---|
| 363 | // FAILURE jum.assertTrue("test13", dojo_validate_isValidTime('05:01:30 p.m.', {format: "hh:mm:ss a", am: "a.m.", pm: "p.m."} ) ); |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | |
---|
| 367 | function test_validate_datetime_is12HourTime(){ |
---|
| 368 | jum.assertTrue("test1", dojo_validate_is12HourTime('5:15:05 pm')); |
---|
| 369 | // FAILURE jum.assertFalse("test2", dojo_validate_is12HourTime('05:15:05 pm')); |
---|
| 370 | jum.assertFalse("test3", dojo_validate_is12HourTime('5:5:05 pm')); |
---|
| 371 | jum.assertFalse("test4", dojo_validate_is12HourTime('5:15:5 pm')); |
---|
| 372 | // FAILURE jum.assertFalse("test5", dojo_validate_is12HourTime('13:15:05 pm')); |
---|
| 373 | jum.assertFalse("test6", dojo_validate_is12HourTime('5:60:05 pm')); |
---|
| 374 | jum.assertFalse("test7", dojo_validate_is12HourTime('5:15:60 pm')); |
---|
| 375 | jum.assertTrue("test8", dojo_validate_is12HourTime('5:59:05 pm')); |
---|
| 376 | jum.assertTrue("test9", dojo_validate_is12HourTime('5:15:59 pm')); |
---|
| 377 | // FAILURE jum.assertFalse("test10", dojo_validate_is12HourTime('5:15:05')); |
---|
| 378 | |
---|
| 379 | // optional seconds |
---|
| 380 | jum.assertTrue("test11", dojo_validate_is12HourTime('5:15 pm')); |
---|
| 381 | jum.assertFalse("test12", dojo_validate_is12HourTime('5:15: pm')); |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | function test_validate_datetime_is24HourTime(){ |
---|
| 385 | jum.assertTrue("test1", dojo_validate_is24HourTime('00:03:59')); |
---|
| 386 | jum.assertTrue("test2", dojo_validate_is24HourTime('22:03:59')); |
---|
| 387 | //FIXME: fix tests or code? |
---|
| 388 | // jum.assertFalse("test3", dojo_validate_is24HourTime('22:03:59 pm')); |
---|
| 389 | // jum.assertFalse("test4", dojo_validate_is24HourTime('2:03:59')); |
---|
| 390 | jum.assertFalse("test5", dojo_validate_is24HourTime('0:3:59')); |
---|
| 391 | jum.assertFalse("test6", dojo_validate_is24HourTime('00:03:5')); |
---|
| 392 | jum.assertFalse("test7", dojo_validate_isValidTime('24:03:59', {format: 'kk:mm:ss'})); |
---|
| 393 | jum.assertFalse("test8", dojo_validate_is24HourTime('02:60:59')); |
---|
| 394 | jum.assertFalse("test9", dojo_validate_is24HourTime('02:03:60')); |
---|
| 395 | |
---|
| 396 | // optional seconds |
---|
| 397 | jum.assertTrue("test10", dojo_validate_is24HourTime('22:53')); |
---|
| 398 | jum.assertFalse("test11", dojo_validate_is24HourTime('22:53:')); |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | function test_validate_datetime_isValidDate(){ |
---|
| 402 | |
---|
| 403 | // Month date year |
---|
| 404 | jum.assertTrue("test1", dojo_validate_isValidDate("08/06/2005", "MM/dd/yyyy")); |
---|
| 405 | jum.assertTrue("test2", dojo_validate_isValidDate("08.06.2005", "MM.dd.yyyy")); |
---|
| 406 | jum.assertTrue("test3", dojo_validate_isValidDate("08-06-2005", "MM-dd-yyyy")); |
---|
| 407 | jum.assertTrue("test4", dojo_validate_isValidDate("8/6/2005", "M/d/yyyy")); |
---|
| 408 | jum.assertTrue("test5", dojo_validate_isValidDate("8/6", "M/d")); |
---|
| 409 | jum.assertFalse("test6", dojo_validate_isValidDate("09/31/2005", "MM/dd/yyyy")); |
---|
| 410 | jum.assertFalse("test7", dojo_validate_isValidDate("02/29/2005", "MM/dd/yyyy")); |
---|
| 411 | jum.assertTrue("test8", dojo_validate_isValidDate("02/29/2004", "MM/dd/yyyy")); |
---|
| 412 | |
---|
| 413 | // year month date |
---|
| 414 | jum.assertTrue("test9", dojo_validate_isValidDate("2005-08-06", "yyyy-MM-dd")); |
---|
| 415 | jum.assertTrue("test10", dojo_validate_isValidDate("20050806", "yyyyMMdd")); |
---|
| 416 | |
---|
| 417 | // year month |
---|
| 418 | jum.assertTrue("test11", dojo_validate_isValidDate("2005-08", "yyyy-MM")); |
---|
| 419 | jum.assertTrue("test12", dojo_validate_isValidDate("200508", "yyyyMM")); |
---|
| 420 | |
---|
| 421 | // year |
---|
| 422 | jum.assertTrue("test13", dojo_validate_isValidDate("2005", "yyyy")); |
---|
| 423 | |
---|
| 424 | // year week day |
---|
| 425 | //TODO: need to support 'w'? |
---|
| 426 | // jum.assertTrue("test14", dojo_validate_isValidDate("2005-W42-3", "yyyy-'W'ww-d")); |
---|
| 427 | // jum.assertTrue("test15", dojo_validate_isValidDate("2005W423", "yyyy'W'wwd")); |
---|
| 428 | // jum.assertFalse("test16", dojo_validate_isValidDate("2005-W42-8", "yyyy-'W'ww-d")); |
---|
| 429 | // jum.assertFalse("test17", dojo_validate_isValidDate("2005-W54-3", "yyyy-'W'ww-d")); |
---|
| 430 | |
---|
| 431 | // year week |
---|
| 432 | // jum.assertTrue("test18", dojo_validate_isValidDate("2005-W42", "yyyy-'W'ww")); |
---|
| 433 | // jum.assertTrue("test19", dojo_validate_isValidDate("2005W42", "yyyy'W'ww")); |
---|
| 434 | |
---|
| 435 | // year ordinal-day |
---|
| 436 | jum.assertTrue("test20", dojo_validate_isValidDate("2005-292", "yyyy-DDD")); |
---|
| 437 | jum.assertTrue("test21", dojo_validate_isValidDate("2005292", "yyyyDDD")); |
---|
| 438 | jum.assertFalse("test22", dojo_validate_isValidDate("2005-366", "yyyy-DDD")); |
---|
| 439 | jum.assertTrue("test23", dojo_validate_isValidDate("2004-366", "yyyy-DDD")); |
---|
| 440 | |
---|
| 441 | // date month year |
---|
| 442 | jum.assertTrue("test24", dojo_validate_isValidDate("19.10.2005", "dd.MM.yyyy")); |
---|
| 443 | jum.assertTrue("test25", dojo_validate_isValidDate("19-10-2005", "d-M-yyyy")); |
---|
| 444 | } |
---|
| 445 | */ |
---|
| 446 | |
---|
| 447 | }); |
---|