Debian Codegraph @

dojox/date/timezone.js

raw symbols SCIP
1 /******************************************************************************
2 * Dojo port of fleegix date plugin from
3 *
4 * http://js.fleegix.org/plugins/date/date
5 *
6 * contributed to Dojo under CLA, with thanks to Matthew Eernisse ([email protected])
7 * and Open Source Applications Foundation
8 *
9 * Credits: Ideas included from incomplete JS implementation of Olson
10 * parser, "XMLDate" by Philippe Goetz ([email protected])
11 *****************************************************************************/
12
13 define([
14 "dojo/_base/array",
15 "dojo/_base/config",
16 "dojo/_base/declare",
17 "dojo/_base/kernel",
18 "dojo/_base/lang",
19 "dojo/date",
20 "dojo/date/locale",
21 "dojo/request",
22 "dojo/request/handlers"
23 ],
24 function(arrayUtil, config, declare, kernel, lang, dateUtil, localeUtil, request, handlers){
25 kernel.experimental("dojox.date.timezone");
26
27 var _zoneFiles = [ "africa", "antarctica", "asia", "australasia", "backward",
28 "etcetera", "europe", "northamerica", "pacificnew",
29 "southamerica" ];
30
31 // Our mins an maxes for years that we care about
32 var _minYear = 1835,
33 _maxYear = 2038;
34
35 var _loadedZones = {},
36 _zones = {},
37 _loadedRanges = {},
38 _rules = {};
39
40 // loadingScheme: String
41 // One of "preloadAll", "lazyLoad" (Defaults "preloadAll")
42 var loadingScheme = config.timezoneLoadingScheme || "preloadAll";
43
44 // defaultZoneFile: String or String[]
45 // The default file (or files) to load on startup - other files will
46 // be lazily-loaded on-demand
47 var defaultZoneFile = config.defaultZoneFile ||
48 ((loadingScheme == "preloadAll") ? _zoneFiles : "northamerica");
49
50 // Set our olson_zoneinfo content handler
51 handlers.register("olson_zoneinfo", function(response) {
52 var text = response.text,
53 s = "",
54 lines = text.split("\n"),
55 arr = [],
56 chunk = "",
57 zone = null,
58 rule = null,
59 ret = {zones: {}, rules: {}};
60
61 for(var i = 0; i < lines.length; i++){
62 var l = lines[i];
63 if(l.match(/^\s/)){
64 l = "Zone " + zone + l;
65 }
66 l = l.split("#")[0];
67 if(l.length > 3){
68 arr = l.split(/\s+/);
69 chunk = arr.shift();
70 switch(chunk){
71 case 'Zone':
72 zone = arr.shift();
73 if(arr[0]){
74 // Handle extra commas in the middle of a zone
75 if(!ret.zones[zone]){ ret.zones[zone] = []; }
76 ret.zones[zone].push(arr);
77 }
78 break;
79 case 'Rule':
80 rule = arr.shift();
81 if(!ret.rules[rule]){ ret.rules[rule] = []; }
82 ret.rules[rule].push(arr);
83 break;
84 case 'Link':
85 // No zones for these should already exist
86 if(ret.zones[arr[1]]){
87 throw new Error('Error with Link ' + arr[1]);
88 }
89 // Create the link
90 ret.zones[arr[1]] = arr[0];
91 break;
92 case 'Leap':
93 break;
94 default:
95 // Fail silently
96 break;
97 }
98 }
99 }
100 return ret; // Object
101 });
102
103 function loadZoneData(/* Object */ data){
104 // summary:
105 // Loads the given data object into the zone database
106 // data: Object
107 // The data to load - contains "zones" and "rules" parameters
108 data = data || {};
109 _zones = lang.mixin(_zones, data.zones||{});
110 _rules = lang.mixin(_rules, data.rules||{});
111 }
112
113 function loadZoneFile(/* String */ fileName){
114 // summary:
115 // Loads the given URL of the Olson zone information into the
116 // zone database
117 //
118 // fileName: String
119 // The zoneinfo file name to load
120
121 // TODO: Maybe behave similar to requireLocalization - rather than
122 // Using request.get?
123 _loadedZones[fileName] = true;
124 request.get(require.toUrl((config.timezoneFileBasePath || "dojox/date/zoneinfo") + "/" + fileName), {
125 handleAs: "olson_zoneinfo",
126 sync: true
127 }).then(loadZoneData, function(e){
128 console.error("Error loading zone file:", e);
129 throw e;
130 });
131 }
132
133 var monthMap = { 'jan': 0, 'feb': 1, 'mar': 2, 'apr': 3,'may': 4, 'jun': 5,
134 'jul': 6, 'aug': 7, 'sep': 8, 'oct': 9, 'nov': 10, 'dec': 11 },
135 dayMap = {'sun': 0, 'mon': 1, 'tue': 2, 'wed': 3, 'thu': 4,
136 'fri': 5, 'sat': 6 },
137 regionMap = {'EST': "northamerica", 'MST': "northamerica",
138 'HST': "northamerica", 'EST5EDT': "northamerica",
139 'CST6CDT': "northamerica", 'MST7MDT': "northamerica",
140 'PST8PDT': "northamerica", 'America': "northamerica",
141 'Pacific': "australasia", 'Atlantic': "europe",
142 'Africa': "africa", 'Indian': "africa",
143 'Antarctica': "antarctica", 'Asia': "asia",
144 'Australia': "australasia", 'Europe': "europe",
145 'WET': "europe", 'CET': "europe", 'MET': "europe",
146 'EET': "europe"},
147 regionExceptions = {'Pacific/Honolulu':"northamerica",
148 'Atlantic/Bermuda':"northamerica",
149 'Atlantic/Cape_Verde':"africa",
150 'Atlantic/St_Helena':"africa",
151 'Indian/Kerguelen':"antarctica",
152 'Indian/Chagos':"asia",
153 'Indian/Maldives':"asia",
154 'Indian/Christmas':"australasia",
155 'Indian/Cocos':"australasia",
156 'America/Danmarkshavn':"europe",
157 'America/Scoresbysund':"europe",
158 'America/Godthab':"europe",
159 'America/Thule':"europe",
160 'Asia/Yekaterinburg':"europe",
161 'Asia/Omsk':"europe",
162 'Asia/Novosibirsk':"europe",
163 'Asia/Krasnoyarsk':"europe",
164 'Asia/Irkutsk':"europe",
165 'Asia/Yakutsk':"europe",
166 'Asia/Vladivostok':"europe",
167 'Asia/Sakhalin':"europe",
168 'Asia/Magadan':"europe",
169 'Asia/Kamchatka':"europe",
170 'Asia/Anadyr':"europe",
171 'Africa/Ceuta':"europe",
172 'America/Argentina/Buenos_Aires':"southamerica",
173 'America/Argentina/Cordoba':"southamerica",
174 'America/Argentina/Tucuman':"southamerica",
175 'America/Argentina/La_Rioja':"southamerica",
176 'America/Argentina/San_Juan':"southamerica",
177 'America/Argentina/Jujuy':"southamerica",
178 'America/Argentina/Catamarca':"southamerica",
179 'America/Argentina/Mendoza':"southamerica",
180 'America/Argentina/Rio_Gallegos':"southamerica",
181 'America/Argentina/Ushuaia':"southamerica",
182 'America/Aruba':"southamerica",
183 'America/La_Paz':"southamerica",
184 'America/Noronha':"southamerica",
185 'America/Belem':"southamerica",
186 'America/Fortaleza':"southamerica",
187 'America/Recife':"southamerica",
188 'America/Araguaina':"southamerica",
189 'America/Maceio':"southamerica",
190 'America/Bahia':"southamerica",
191 'America/Sao_Paulo':"southamerica",
192 'America/Campo_Grande':"southamerica",
193 'America/Cuiaba':"southamerica",
194 'America/Porto_Velho':"southamerica",
195 'America/Boa_Vista':"southamerica",
196 'America/Manaus':"southamerica",
197 'America/Eirunepe':"southamerica",
198 'America/Rio_Branco':"southamerica",
199 'America/Santiago':"southamerica",
200 'Pacific/Easter':"southamerica",
201 'America/Bogota':"southamerica",
202 'America/Curacao':"southamerica",
203 'America/Guayaquil':"southamerica",
204 'Pacific/Galapagos':"southamerica",
205 'Atlantic/Stanley':"southamerica",
206 'America/Cayenne':"southamerica",
207 'America/Guyana':"southamerica",
208 'America/Asuncion':"southamerica",
209 'America/Lima':"southamerica",
210 'Atlantic/South_Georgia':"southamerica",
211 'America/Paramaribo':"southamerica",
212 'America/Port_of_Spain':"southamerica",
213 'America/Montevideo':"southamerica",
214 'America/Caracas':"southamerica"},
215 abbrExceptions = { 'US': "S", 'Chatham': "S", 'NZ': "S", 'NT_YK': "S",
216 'Edm': "S", 'Salv': "S", 'Canada': "S", 'StJohns': "S",
217 'TC': "S", 'Guat': "S", 'Mexico': "S", 'Haiti': "S",
218 'Barb': "S", 'Belize': "S", 'CR': "S", 'Moncton': "S",
219 'Swift': "S", 'Hond': "S", 'Thule': "S", 'NZAQ': "S",
220 'Zion': "S", 'ROK': "S", 'PRC': "S", 'Taiwan': "S",
221 'Ghana': "GMT", 'SL': "WAT", 'Chicago': "S",
222 'Detroit': "S", 'Vanc': "S", 'Denver': "S",
223 'Halifax': "S", 'Cuba': "S", 'Indianapolis': "S",
224 'Starke': "S", 'Marengo': "S", 'Pike': "S",
225 'Perry': "S", 'Vincennes': "S", 'Pulaski': "S",
226 'Louisville': "S", 'CA': "S", 'Nic': "S",
227 'Menominee': "S", 'Mont': "S", 'Bahamas': "S",
228 'NYC': "S", 'Regina': "S", 'Resolute': "ES",
229 'DR': "S", 'Toronto': "S", 'Winn': "S" };
230
231 function invalidTZError(t) {
232 throw new Error('Timezone "' + t +
233 '" is either incorrect, or not loaded in the timezone registry.');
234 }
235
236 function getRegionForTimezone(/* String */ tz) {
237 // summary:
238 // Returns the Olson region for the given timezone
239 var ret = regionExceptions[tz];
240 if(!ret){
241 var reg = tz.split('/')[0];
242 ret = regionMap[reg];
243 // If there's nothing listed in the main regions for
244 // this TZ, check the 'backward' links
245 if(!ret){
246 var link = _zones[tz];
247 if(typeof link == 'string'){
248 return getRegionForTimezone(link); // String
249 }else{
250 // Backward-compat file hasn't loaded yet, try looking in there
251 if (!_loadedZones.backward) {
252 // This is for obvious legacy zones (e.g., Iceland) that
253 // don't even have a prefix like "America/" that look like
254 // normal zones
255 loadZoneFile("backward");
256 return getRegionForTimezone(tz); // String
257 }else{
258 invalidTZError(tz);
259 }
260 }
261 }
262 }
263 return ret; // String
264 }
265
266 function parseTimeString(/* String */ str) {
267 // summary:
268 // Parses the given time string and returns it as an integer array
269 var pat = /(\d+)(?::0*(\d*))?(?::0*(\d*))?([su])?$/;
270 var hms = str.match(pat);
271 if(!hms){
272 return null;
273 }
274 hms[1] = parseInt(hms[1], 10);
275 hms[2] = hms[2] ? parseInt(hms[2], 10) : 0;
276 hms[3] = hms[3] ? parseInt(hms[3], 10) : 0;
277 return hms; // int[]
278 }
279
280 function getUTCStamp(/* int */ y, /* int */ m, /* int */ d, /* int */ h,
281 /* int */ mn, /* int */ s, /* int? */ off){
282 // summary:
283 // Returns the UTC timestamp, adjusted by the given (optional) offset
284 return Date.UTC(y, m, d, h, mn, s) + ((off||0) * 60 * 1000);
285 }
286
287 function getMonthNumber(/* String */ m){
288 // summary:
289 // Returns the javascript month number for the given string
290 return monthMap[m.substr(0, 3).toLowerCase()];
291 }
292
293 function getOffsetInMins(/* String */ str){
294 // summary:
295 // Returns the offset value represented by the string, in minutes
296 var off = parseTimeString(str);
297 if(off === null){ return 0; }
298 var adj = str.indexOf('-') === 0 ? -1 : 1;
299 off = adj * (((off[1] * 60 + off[2]) *60 + off[3]) * 1000);
300 return -off/60/1000;
301 }
302
303 function _getRuleStart(/* Rule */ rule, /* int */ year, /* int */ off){
304 // summary:
305 // Returns a date that the rule begins matching in the given year.
306 var month = getMonthNumber(rule[3]),
307 day = rule[4],
308 time = parseTimeString(rule[5]);
309 if(time[4] == "u"){
310 // We are UTC - so there is no offset to use
311 off = 0;
312 }
313
314 var d, dtDay, incr;
315 if(isNaN(day)){
316 if(day.substr(0, 4) == "last"){
317 // Last day of the month at the desired time of day
318 day = dayMap[day.substr(4,3).toLowerCase()];
319 d = new Date(getUTCStamp(year, month + 1, 1,
320 time[1] - 24, time[2], time[3],
321 off));
322 dtDay = dateUtil.add(d, "minute", -off).getUTCDay();
323 // Set it to the final day of the correct weekday that month
324 incr = (day > dtDay) ? (day - dtDay - 7) : (day - dtDay);
325 if(incr !== 0){
326 d = dateUtil.add(d, "hour", incr * 24);
327 }
328 return d;
329 }else{
330 day = dayMap[day.substr(0, 3).toLowerCase()];
331 if(day != "undefined"){
332 if(rule[4].substr(3, 2) == '>='){
333 // The stated date of the month
334 d = new Date(getUTCStamp(year, month, parseInt(rule[4].substr(5), 10),
335 time[1], time[2], time[3], off));
336 dtDay = dateUtil.add(d, "minute", -off).getUTCDay();
337 // Set to the first correct weekday after the stated date
338 incr = (day < dtDay) ? (day - dtDay + 7) : (day - dtDay);
339 if(incr !== 0){
340 d = dateUtil.add(d, "hour", incr * 24);
341 }
342 return d;
343 }else if(day.substr(3, 2) == '<='){
344 // The stated date of the month
345 d = new Date(getUTCStamp(year, month, parseInt(rule[4].substr(5), 10),
346 time[1], time[2], time[3], off));
347 dtDay = dateUtil.add(d, "minute", -off).getUTCDay();
348 // Set to first correct weekday before the stated date
349 incr = (day > dtDay) ? (day - dtDay - 7) : (day - dtDay);
350 if(incr !== 0){
351 d = dateUtil.add(d, "hour", incr * 24);
352 }
353 return d;
354 }
355 }
356 }
357 }else{
358 // Numeric date
359 d = new Date(getUTCStamp(year, month, parseInt(day, 10),
360 time[1], time[2], time[3], off));
361 return d;
362 }
363 return null;
364 }
365
366 function _getRulesForYear(/* Zone */ zone, /* int */ year){
367 var rules = [];
368 arrayUtil.forEach(_rules[zone[1]]||[], function(r){
369 // Clean up rules as needed
370 for(var i = 0; i < 2; i++){
371 switch(r[i]){
372 case "min":
373 r[i] = _minYear;
374 break;
375 case "max":
376 r[i] = _maxYear;
377 break;
378 case "only":
379 break;
380 default:
381 r[i] = parseInt(r[i], 10);
382 if(isNaN(r[i])){
383 throw new Error('Invalid year found on rule');
384 }
385 break;
386 }
387 }
388 if(typeof r[6] == "string"){
389 // Change our offset to be an integer
390 r[6] = getOffsetInMins(r[6]);
391 }
392
393 // Quick-filter to grab all rules that match my year
394 if((r[0] <= year && r[1] >= year) || // Matches my y
395 (r[0] == year && r[1] == "only")){ // Matches my only
396 rules.push({r: r, d: _getRuleStart(r, year, zone[0])});
397 }
398 });
399 return rules;
400 }
401
402
403 function _loadZoneRanges(/* String */ tz, /* Object[] */ zoneList) {
404 // summary:
405 // Loads the zone ranges for the given timezone
406
407 var zr = _loadedRanges[tz] = [];
408 for(var i = 0; i < zoneList.length; i++){
409 var z = zoneList[i];
410 var r = zr[i] = [];
411 var prevZone = null;
412 var prevRange = null;
413 var prevRules = [];
414
415 // Set up our zone offset to not be a string anymore
416 if(typeof z[0] == "string"){
417 z[0] = getOffsetInMins(z[0]);
418 }
419
420 if(i === 0){
421 // The beginning of zoneinfo time - let's not worry about
422 // to-the-hour accuracy before Jan 1, 1835
423 r[0] = Date.UTC(_minYear,0,1,0,0,0,0);
424 }else{
425 r[0] = zr[i - 1][1];
426 prevZone = zoneList[i - 1];
427 prevRange = zr[i - 1];
428 prevRules = prevRange[2];
429 }
430
431 // Load the rules that will be going in to our zone
432 var startYear = new Date(r[0]).getUTCFullYear();
433 var endYear = z[3] ? parseInt(z[3], 10) : _maxYear;
434 var rlz = [];
435 var j;
436 for(j = startYear; j <= endYear; j++){
437 rlz = rlz.concat(_getRulesForYear(z, j));
438 }
439 rlz.sort(function(a, b){
440 return dateUtil.compare(a.d, b.d);
441 });
442 var rl;
443 for(j = 0, rl; (rl = rlz[j]); j++){
444 var prevRule = j > 0 ? rlz[j - 1] : null;
445 if(rl.r[5].indexOf("u") < 0 && rl.r[5].indexOf("s") < 0){
446 if(j === 0 && i > 0){
447 if(prevRules.length){
448 // We have a previous rule - so use it
449 rl.d = dateUtil.add(rl.d, "minute", prevRules[prevRules.length - 1].r[6]);
450 }else if(dateUtil.compare(new Date(prevRange[1]), rl.d, "date") === 0){
451 // No previous rules - but our date is the same as the
452 // previous zone ended on - so use that.
453 rl.d = new Date(prevRange[1]);
454 }else{
455 rl.d = dateUtil.add(rl.d, "minute", getOffsetInMins(prevZone[1]));
456 }
457 }else if(j > 0){
458 rl.d = dateUtil.add(rl.d, "minute", prevRule.r[6]);
459 }
460 }
461 }
462 r[2] = rlz;
463
464 if(!z[3]){
465 // The end of zoneinfo time - we'll cross this bridge when we
466 // get close to Dec 31, 2038
467 r[1] = Date.UTC(_maxYear,11,31,23,59,59,999);
468 }else{
469 var year = parseInt(z[3], 10),
470 month = getMonthNumber(z[4]||"Jan"),
471 day = parseInt(z[5]||"1", 10),
472 time = parseTimeString(z[6]||"0");
473 var utcStmp = r[1] = getUTCStamp(year, month, day,
474 time[1], time[2], time[3],
475 ((time[4] == "u") ? 0 : z[0]));
476 if(isNaN(utcStmp)){
477 utcStmp = r[1] = _getRuleStart([0,0,0,z[4],z[5],z[6]||"0"],
478 year, ((time[4] == "u") ? 0 : z[0])).getTime();
479 }
480 var matches = arrayUtil.filter(rlz, function(rl, idx){
481 var o = idx > 0 ? rlz[idx - 1].r[6] * 60 * 1000 : 0;
482 return (rl.d.getTime() < utcStmp + o);
483 });
484 if(time[4] != "u" && time[4] != "s"){
485 if(matches.length){
486 r[1] += matches[matches.length - 1].r[6] * 60 * 1000;
487 }else{
488 r[1] += getOffsetInMins(z[1]) * 60 * 1000;
489 }
490 }
491 }
492 }
493 }
494
495 function getZoneInfo(/* String */ dt, /* String */ tz) {
496 // summary:
497 // Returns the zone entry from the zoneinfo database for the given date
498 // and timezone
499 var t = tz;
500 var zoneList = _zones[t];
501
502 // Follow links to get to an actual zone
503 while(typeof zoneList == "string"){
504 t = zoneList;
505 zoneList = _zones[t];
506 }
507 if(!zoneList){
508 // Backward-compat file hasn't loaded yet, try looking in there
509 if(!_loadedZones.backward){
510 // This is for backward entries like "America/Fort_Wayne" that
511 // getRegionForTimezone *thinks* it has a region file and zone
512 // for (e.g., America => 'northamerica'), but in reality it's a
513 // legacy zone we need the backward file for
514 var parsed = loadZoneFile("backward", true);
515 return getZoneInfo(dt, tz); //Object
516 }
517 invalidTZError(t);
518 }
519
520 if(!_loadedRanges[tz]){
521 _loadZoneRanges(tz, zoneList);
522 }
523 var ranges = _loadedRanges[tz];
524 var tm = dt.getTime();
525 for(var i = 0, r; (r = ranges[i]); i++){
526 if(tm >= r[0] && tm < r[1]){
527 return {zone: zoneList[i], range: ranges[i], idx: i};
528 }
529 }
530 throw new Error('No Zone found for "' + tz + '" on ' + dt);
531 }
532
533 function getRule(/* Date */ dt, /* ZoneInfo */ zoneInfo) {
534 // summary:
535 // Returns the latest-matching rule entry from the zoneinfo
536 // database for the given date and zone
537
538 var lastMatch = -1;
539 var rules = zoneInfo.range[2]||[];
540 var tsp = dt.getTime();
541 var zr = zoneInfo.range;
542 for(var i = 0, r; (r = rules[i]); i++){
543 if(tsp >= r.d.getTime()){
544 lastMatch = i;
545 }
546 }
547 if(lastMatch >= 0){
548 return rules[lastMatch].r;
549 }
550 return null;
551 }
552
553 function getAbbreviation(/* String */ tz, /* Object */ zoneInfo, /* Object */ rule) {
554 // summary:
555 // Returns the abbreviation for the given zone and rule
556 var res;
557 var zone = zoneInfo.zone;
558 var base = zone[2];
559 if(base.indexOf('%s') > -1){
560 var repl;
561 if(rule){
562 repl = rule[7];
563 if(repl == "-"){ repl = ""; }
564 }else if(zone[1] in abbrExceptions){
565 repl = abbrExceptions[zone[1]];
566 }else{
567 if(zoneInfo.idx > 0){
568 // Check if our previous zone's base is the same as our
569 // current in "S" (standard) mode. If so, then use "S"
570 // for our replacement
571 var pz = _zones[tz][zoneInfo.idx - 1];
572 var pb = pz[2];
573 if(pb.indexOf('%s') < 0){
574 if(base.replace('%s', "S") == pb){
575 repl = "S";
576 }else{
577 repl = "";
578 }
579 }else{
580 repl = "";
581 }
582 }else{
583 repl = "";
584 }
585 }
586 res = base.replace('%s', repl);
587 }else if(base.indexOf("/") > -1){
588 var bs = base.split("/");
589 if(rule){
590 res = bs[rule[6] === 0 ? 0 : 1];
591 }else{
592 res = bs[0];
593 }
594 }else{
595 res = base;
596 }
597 return res; // String
598 }
599
600 lang.setObject("dojox.date.timezone", {
601 // summary:
602 // mix-in to dojo.date to provide timezones based on
603 // the Olson timezone data
604 // description:
605 // mix-in to dojo.date to provide timezones based on
606 // the Olson timezone data.
607 // If you pass "timezone" as a parameter to your format options,
608 // then you get the date formatted (and offset) for that timezone
609
610 getTzInfo: function(/* Date */ dt, /* String */ tz){
611 // summary:
612 // Returns the timezone information for the given date and
613 // timezone string
614 // dt: Date
615 // The Date - a "proxyDate"
616 // tz: String
617 // String representation of the timezone you want to get info
618 // for date
619
620 // Lazy-load any zones not yet loaded
621 if(loadingScheme == "lazyLoad"){
622 // Get the correct region for the zone
623 var zoneFile = getRegionForTimezone(tz);
624 if(!zoneFile){
625 throw new Error("Not a valid timezone ID.");
626 }else{
627 if(!_loadedZones[zoneFile]){
628 // Get the file and parse it -- use synchronous XHR
629 loadZoneFile(zoneFile);
630 }
631 }
632 }
633 var zoneInfo = getZoneInfo(dt, tz);
634 var off = zoneInfo.zone[0];
635 // See if the offset needs adjustment
636 var rule = getRule(dt, zoneInfo);
637 if(rule){
638 off += rule[6];
639 }else{
640 if(_rules[zoneInfo.zone[1]] && zoneInfo.idx > 0){
641 off += getOffsetInMins(_zones[tz][zoneInfo.idx - 1][1]);
642 }else{
643 off += getOffsetInMins(zoneInfo.zone[1]);
644 }
645 }
646
647 var abbr = getAbbreviation(tz, zoneInfo, rule);
648 return { tzOffset: off, tzAbbr: abbr }; // Object
649 },
650
651 loadZoneData: function(data){
652 // summary:
653 // Loads the given data object into the zone database
654 // data: Object
655 // The data to load - contains "zones" and "rules" parameters
656 loadZoneData(data);
657 },
658
659 getAllZones: function(){
660 // summary:
661 // Returns an array of zones that have been loaded
662 var arr = [];
663 for(var z in _zones){ arr.push(z); }
664 arr.sort();
665 return arr; // String[]
666 }
667 });
668
669 // Now - initialize the stuff that we should have pre-loaded
670 if(typeof defaultZoneFile == "string" && defaultZoneFile){
671 defaultZoneFile = [defaultZoneFile];
672 }
673 if(defaultZoneFile instanceof Array){
674 arrayUtil.forEach(defaultZoneFile, loadZoneFile);
675 }
676
677 // And enhance the default formatting functions
678 // If you pass "timezone" as a parameter to your format options,
679 // then you get the date formatted (and offset) for that timezone
680 var oLocaleFmt = localeUtil.format,
681 oGetZone = localeUtil._getZone;
682 localeUtil.format = function(dateObject, options){
683 options = options||{};
684 if(options.timezone && !options._tzInfo){
685 // Store it in our options so we can use it later
686 options._tzInfo = dojox.date.timezone.getTzInfo(dateObject, options.timezone);
687 }
688 if(options._tzInfo){
689 // Roll our date to display the correct time according to the
690 // desired offset
691 var offset = dateObject.getTimezoneOffset() - options._tzInfo.tzOffset;
692 dateObject = new Date(dateObject.getTime() + (offset * 60 * 1000));
693 }
694 return oLocaleFmt.call(this, dateObject, options);
695 };
696 localeUtil._getZone = function(dateObject, getName, options){
697 if(options._tzInfo){
698 return getName ? options._tzInfo.tzAbbr : options._tzInfo.tzOffset;
699 }
700 return oGetZone.call(this, dateObject, getName, options);
701 };
702
703 /*=====
704 // Hide these enhancements from the doc parser because they obscure the original definition of _getZone() and
705 // format. TODO: change above overrides to around() advice so that original definitions aren't changed.
706 localeUtil.format = oLocaleFmt;
707 localeUtil._getZone = oGetZone;
708 =====*/
709
710 return dojox.date.timezone;
711 });