]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/date/locale.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / date / locale.js
1 if(!dojo._hasResource["dojo.date.locale"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.date.locale"] = true;
3 dojo.provide("dojo.date.locale");
4
5 // Localization methods for Date.   Honor local customs using locale-dependent dojo.cldr data.
6
7 dojo.require("dojo.date");
8 dojo.require("dojo.cldr.supplemental");
9 dojo.require("dojo.regexp");
10 dojo.require("dojo.string");
11 dojo.require("dojo.i18n");
12
13 // Load the bundles containing localization information for
14 // names and formats
15 dojo.requireLocalization("dojo.cldr", "gregorian", null, "zh-cn,zh,en-ca,ko-kr,pt,pt-br,it-it,ROOT,en-gb,de,ja,en,en-au,fr,es,ko,zh-tw,it,es-es");
16
17 //NOTE: Everything in this module assumes Gregorian calendars.
18 // Other calendars will be implemented in separate modules.
19
20 (function(){
21         // Format a pattern without literals
22         function formatPattern(dateObject, bundle, fullYear, pattern){
23                 return pattern.replace(/([a-z])\1*/ig, function(match){
24                         var s, pad;
25                         var c = match.charAt(0);
26                         var l = match.length;
27                         var widthList = ["abbr", "wide", "narrow"];
28                         switch(c){
29                                 case 'G':
30                                         s = bundle[(l < 4) ? "eraAbbr" : "eraNames"][dateObject.getFullYear() < 0 ? 0 : 1];
31                                         break;
32                                 case 'y':
33                                         s = dateObject.getFullYear();
34                                         switch(l){
35                                                 case 1:
36                                                         break;
37                                                 case 2:
38                                                         if(!fullYear){
39                                                                 s = String(s); s = s.substr(s.length - 2);
40                                                                 break;
41                                                         }
42                                                         // fallthrough
43                                                 default:
44                                                         pad = true;
45                                         }
46                                         break;
47                                 case 'Q':
48                                 case 'q':
49                                         s = Math.ceil((dateObject.getMonth()+1)/3);
50 //                                      switch(l){
51 //                                              case 1: case 2:
52                                                         pad = true;
53 //                                                      break;
54 //                                              case 3: case 4: // unimplemented
55 //                                      }
56                                         break;
57                                 case 'M':
58                                 case 'L':
59                                         var m = dateObject.getMonth();
60                                         var widthM;
61                                         switch(l){
62                                                 case 1: case 2:
63                                                         s = m+1; pad = true;
64                                                         break;
65                                                 case 3: case 4: case 5:
66                                                         widthM = widthList[l-3];
67                                                         break;
68                                         }
69                                         if(widthM){
70                                                 var typeM = (c == "L") ? "standalone" : "format";
71                                                 var propM = ["months", typeM, widthM].join("-");
72                                                 s = bundle[propM][m];
73                                         }
74                                         break;
75                                 case 'w':
76                                         var firstDay = 0;
77                                         s = dojo.date.locale._getWeekOfYear(dateObject, firstDay); pad = true;
78                                         break;
79                                 case 'd':
80                                         s = dateObject.getDate(); pad = true;
81                                         break;
82                                 case 'D':
83                                         s = dojo.date.locale._getDayOfYear(dateObject); pad = true;
84                                         break;
85                                 case 'E':
86                                 case 'e':
87                                 case 'c': // REVIEW: don't see this in the spec?
88                                         var d = dateObject.getDay();
89                                         var widthD;
90                                         switch(l){
91                                                 case 1: case 2:
92                                                         if(c == 'e'){
93                                                                 var first = dojo.cldr.supplemental.getFirstDayOfWeek(options.locale);
94                                                                 d = (d-first+7)%7;
95                                                         }
96                                                         if(c != 'c'){
97                                                                 s = d+1; pad = true;
98                                                                 break;
99                                                         }
100                                                         // else fallthrough...
101                                                 case 3: case 4: case 5:
102                                                         widthD = widthList[l-3];
103                                                         break;
104                                         }
105                                         if(widthD){
106                                                 var typeD = (c == "c") ? "standalone" : "format";
107                                                 var propD = ["days", typeD, widthD].join("-");
108                                                 s = bundle[propD][d];
109                                         }
110                                         break;
111                                 case 'a':
112                                         var timePeriod = (dateObject.getHours() < 12) ? 'am' : 'pm';
113                                         s = bundle[timePeriod];
114                                         break;
115                                 case 'h':
116                                 case 'H':
117                                 case 'K':
118                                 case 'k':
119                                         var h = dateObject.getHours();
120                                         // strange choices in the date format make it impossible to write this succinctly
121                                         switch (c){
122                                                 case 'h': // 1-12
123                                                         s = (h % 12) || 12;
124                                                         break;
125                                                 case 'H': // 0-23
126                                                         s = h;
127                                                         break;
128                                                 case 'K': // 0-11
129                                                         s = (h % 12);
130                                                         break;
131                                                 case 'k': // 1-24
132                                                         s = h || 24;
133                                                         break;
134                                         }
135                                         pad = true;
136                                         break;
137                                 case 'm':
138                                         s = dateObject.getMinutes(); pad = true;
139                                         break;
140                                 case 's':
141                                         s = dateObject.getSeconds(); pad = true;
142                                         break;
143                                 case 'S':
144                                         s = Math.round(dateObject.getMilliseconds() * Math.pow(10, l-3)); pad = true;
145                                         break;
146                                 case 'v': // FIXME: don't know what this is. seems to be same as z?
147                                 case 'z':
148                                         // We only have one timezone to offer; the one from the browser
149                                         s = dojo.date.getTimezoneName(dateObject);
150                                         if(s){break;}
151                                         l=4;
152                                         // fallthrough... use GMT if tz not available
153                                 case 'Z':
154                                         var offset = dateObject.getTimezoneOffset();
155                                         var tz = [
156                                                 (offset<=0 ? "+" : "-"),
157                                                 dojo.string.pad(Math.floor(Math.abs(offset)/60), 2),
158                                                 dojo.string.pad(Math.abs(offset)% 60, 2)
159                                         ];
160                                         if(l==4){
161                                                 tz.splice(0, 0, "GMT");
162                                                 tz.splice(3, 0, ":");
163                                         }
164                                         s = tz.join("");
165                                         break;
166 //                              case 'Y': case 'u': case 'W': case 'F': case 'g': case 'A':
167 //                                      console.debug(match+" modifier unimplemented");
168                                 default:
169                                         throw new Error("dojo.date.locale.format: invalid pattern char: "+pattern);
170                         }
171                         if(pad){ s = dojo.string.pad(s, l); }
172                         return s;
173                 });
174         }
175
176 /*=====
177         dojo.date.locale.__FormatOptions = function(){
178         //      selector: String
179         //              choice of 'time','date' (default: date and time)
180         //      formatLength: String
181         //              choice of long, short, medium or full (plus any custom additions).  Defaults to 'short'
182         //      datePattern:String
183         //              override pattern with this string
184         //      timePattern:String
185         //              override pattern with this string
186         //      am: String
187         //              override strings for am in times
188         //      pm: String
189         //              override strings for pm in times
190         //      locale: String
191         //              override the locale used to determine formatting rules
192         //      fullYear: Boolean
193         //              (format only) use 4 digit years whenever 2 digit years are called for
194         //      strict: Boolean
195         //              (parse only) strict parsing, off by default
196                 this.selector = selector;
197                 this.formatLength = formatLength;
198                 this.datePattern = datePattern;
199                 this.timePattern = timePattern;
200                 this.am = am;
201                 this.pm = pm;
202                 this.locale = locale;
203                 this.fullYear = fullYear;
204                 this.strict = strict;
205         }
206 =====*/
207
208 dojo.date.locale.format = function(/*Date*/dateObject, /*dojo.date.locale.__FormatOptions?*/options){
209         // summary:
210         //              Format a Date object as a String, using locale-specific settings.
211         //
212         // description:
213         //              Create a string from a Date object using a known localized pattern.
214         //              By default, this method formats both date and time from dateObject.
215         //              Formatting patterns are chosen appropriate to the locale.  Different
216         //              formatting lengths may be chosen, with "full" used by default.
217         //              Custom patterns may be used or registered with translations using
218         //              the dojo.date.locale.addCustomFormats method.
219         //              Formatting patterns are implemented using [the syntax described at
220         //              unicode.org](http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns)
221         //
222         // dateObject:
223         //              the date and/or time to be formatted.  If a time only is formatted,
224         //              the values in the year, month, and day fields are irrelevant.  The
225         //              opposite is true when formatting only dates.
226
227         options = options || {};
228
229         var locale = dojo.i18n.normalizeLocale(options.locale);
230         var formatLength = options.formatLength || 'short';
231         var bundle = dojo.date.locale._getGregorianBundle(locale);
232         var str = [];
233         var sauce = dojo.hitch(this, formatPattern, dateObject, bundle, options.fullYear);
234         if(options.selector == "year"){
235                 // Special case as this is not yet driven by CLDR data
236                 var year = dateObject.getFullYear();
237                 if(locale.match(/^zh|^ja/)){
238                         year += "\u5E74";
239                 }
240                 return year;
241         }
242         if(options.selector != "time"){
243                 var datePattern = options.datePattern || bundle["dateFormat-"+formatLength];
244                 if(datePattern){str.push(_processPattern(datePattern, sauce));}
245         }
246         if(options.selector != "date"){
247                 var timePattern = options.timePattern || bundle["timeFormat-"+formatLength];
248                 if(timePattern){str.push(_processPattern(timePattern, sauce));}
249         }
250         var result = str.join(" "); //TODO: use locale-specific pattern to assemble date + time
251         return result; // String
252 };
253
254 dojo.date.locale.regexp = function(/*dojo.date.locale.__FormatOptions?*/options){
255         // summary:
256         //              Builds the regular needed to parse a localized date
257
258         return dojo.date.locale._parseInfo(options).regexp; // String
259 };
260
261 dojo.date.locale._parseInfo = function(/*dojo.date.locale.__FormatOptions?*/options){
262         options = options || {};
263         var locale = dojo.i18n.normalizeLocale(options.locale);
264         var bundle = dojo.date.locale._getGregorianBundle(locale);
265         var formatLength = options.formatLength || 'short';
266         var datePattern = options.datePattern || bundle["dateFormat-" + formatLength];
267         var timePattern = options.timePattern || bundle["timeFormat-" + formatLength];
268         var pattern;
269         if(options.selector == 'date'){
270                 pattern = datePattern;
271         }else if(options.selector == 'time'){
272                 pattern = timePattern;
273         }else{
274                 pattern = datePattern + ' ' + timePattern; //TODO: use locale-specific pattern to assemble date + time
275         }
276
277         var tokens = [];
278         var re = _processPattern(pattern, dojo.hitch(this, _buildDateTimeRE, tokens, bundle, options));
279         return {regexp: re, tokens: tokens, bundle: bundle};
280 };
281
282 dojo.date.locale.parse = function(/*String*/value, /*dojo.date.locale.__FormatOptions?*/options){
283         // summary:
284         //              Convert a properly formatted string to a primitive Date object,
285         //              using locale-specific settings.
286         //
287         // description:
288         //              Create a Date object from a string using a known localized pattern.
289         //              By default, this method parses looking for both date and time in the string.
290         //              Formatting patterns are chosen appropriate to the locale.  Different
291         //              formatting lengths may be chosen, with "full" used by default.
292         //              Custom patterns may be used or registered with translations using
293         //              the dojo.date.locale.addCustomFormats method.
294         //      
295         //              Formatting patterns are implemented using [the syntax described at
296         //              unicode.org](http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns)
297         //              When two digit years are used, a century is chosen according to a sliding 
298         //              window of 80 years before and 20 years after present year, for both `yy` and `yyyy` patterns.
299         //              year < 100CE requires strict mode.
300         //
301         // value:
302         //              A string representation of a date
303
304         var info = dojo.date.locale._parseInfo(options);
305         var tokens = info.tokens, bundle = info.bundle;
306         var re = new RegExp("^" + info.regexp + "$");
307         var match = re.exec(value);
308         if(!match){ return null; } // null
309
310         var widthList = ['abbr', 'wide', 'narrow'];
311         var result = [1970,0,1,0,0,0,0]; // will get converted to a Date at the end
312         var amPm = "";
313         var valid = dojo.every(match, function(v, i){
314                 if(!i){return true;}
315                 var token=tokens[i-1];
316                 var l=token.length;
317                 switch(token.charAt(0)){
318                         case 'y':
319                                 if(l != 2 && options.strict){
320                                         //interpret year literally, so '5' would be 5 A.D.
321                                         result[0] = v;
322                                 }else{
323                                         if(v<100){
324                                                 v = Number(v);
325                                                 //choose century to apply, according to a sliding window
326                                                 //of 80 years before and 20 years after present year
327                                                 var year = '' + new Date().getFullYear();
328                                                 var century = year.substring(0, 2) * 100;
329                                                 var cutoff = Math.min(Number(year.substring(2, 4)) + 20, 99);
330                                                 var num = (v < cutoff) ? century + v : century - 100 + v;
331                                                 result[0] = num;
332                                         }else{
333                                                 //we expected 2 digits and got more...
334                                                 if(options.strict){
335                                                         return false;
336                                                 }
337                                                 //interpret literally, so '150' would be 150 A.D.
338                                                 //also tolerate '1950', if 'yyyy' input passed to 'yy' format
339                                                 result[0] = v;
340                                         }
341                                 }
342                                 break;
343                         case 'M':
344                                 if(l>2){
345                                         var months = bundle['months-format-' + widthList[l-3]].concat();
346                                         if(!options.strict){
347                                                 //Tolerate abbreviating period in month part
348                                                 //Case-insensitive comparison
349                                                 v = v.replace(".","").toLowerCase();
350                                                 months = dojo.map(months, function(s){ return s.replace(".","").toLowerCase(); } );
351                                         }
352                                         v = dojo.indexOf(months, v);
353                                         if(v == -1){
354 //                                              console.debug("dojo.date.locale.parse: Could not parse month name: '" + v + "'.");
355                                                 return false;
356                                         }
357                                 }else{
358                                         v--;
359                                 }
360                                 result[1] = v;
361                                 break;
362                         case 'E':
363                         case 'e':
364                                 var days = bundle['days-format-' + widthList[l-3]].concat();
365                                 if(!options.strict){
366                                         //Case-insensitive comparison
367                                         v = v.toLowerCase();
368                                         days = dojo.map(days, function(d){return d.toLowerCase();});
369                                 }
370                                 v = dojo.indexOf(days, v);
371                                 if(v == -1){
372 //                                      console.debug("dojo.date.locale.parse: Could not parse weekday name: '" + v + "'.");
373                                         return false;
374                                 }
375
376                                 //TODO: not sure what to actually do with this input,
377                                 //in terms of setting something on the Date obj...?
378                                 //without more context, can't affect the actual date
379                                 //TODO: just validate?
380                                 break;
381                         case 'D':
382                                 result[1] = 0;
383                                 // fallthrough...
384                         case 'd':
385                                 result[2] = v;
386                                 break;
387                         case 'a': //am/pm
388                                 var am = options.am || bundle.am;
389                                 var pm = options.pm || bundle.pm;
390                                 if(!options.strict){
391                                         var period = /\./g;
392                                         v = v.replace(period,'').toLowerCase();
393                                         am = am.replace(period,'').toLowerCase();
394                                         pm = pm.replace(period,'').toLowerCase();
395                                 }
396                                 if(options.strict && v != am && v != pm){
397 //                                      console.debug("dojo.date.locale.parse: Could not parse am/pm part.");
398                                         return false;
399                                 }
400
401                                 // we might not have seen the hours field yet, so store the state and apply hour change later
402                                 amPm = (v == pm) ? 'p' : (v == am) ? 'a' : '';
403                                 break;
404                         case 'K': //hour (1-24)
405                                 if(v == 24){ v = 0; }
406                                 // fallthrough...
407                         case 'h': //hour (1-12)
408                         case 'H': //hour (0-23)
409                         case 'k': //hour (0-11)
410                                 //TODO: strict bounds checking, padding
411                                 if(v > 23){
412 //                                      console.debug("dojo.date.locale.parse: Illegal hours value");
413                                         return false;
414                                 }
415
416                                 //in the 12-hour case, adjusting for am/pm requires the 'a' part
417                                 //which could come before or after the hour, so we will adjust later
418                                 result[3] = v;
419                                 break;
420                         case 'm': //minutes
421                                 result[4] = v;
422                                 break;
423                         case 's': //seconds
424                                 result[5] = v;
425                                 break;
426                         case 'S': //milliseconds
427                                 result[6] = v;
428 //                              break;
429 //                      case 'w':
430 //TODO                          var firstDay = 0;
431 //                      default:
432 //TODO: throw?
433 //                              console.debug("dojo.date.locale.parse: unsupported pattern char=" + token.charAt(0));
434                 }
435                 return true;
436         });
437
438         var hours = +result[3];
439         if(amPm === 'p' && hours < 12){
440                 result[3] = hours + 12; //e.g., 3pm -> 15
441         }else if(amPm === 'a' && hours == 12){
442                 result[3] = 0; //12am -> 0
443         }
444
445         //TODO: implement a getWeekday() method in order to test 
446         //validity of input strings containing 'EEE' or 'EEEE'...
447
448         var dateObject = new Date(result[0], result[1], result[2], result[3], result[4], result[5], result[6]); // Date
449         if(options.strict){
450                 dateObject.setFullYear(result[0]);
451         }
452
453         // Check for overflow.  The Date() constructor normalizes things like April 32nd...
454         //TODO: why isn't this done for times as well?
455         var allTokens = tokens.join("");
456         if(!valid ||
457                 (allTokens.indexOf('M') != -1 && dateObject.getMonth() != result[1]) ||
458                 (allTokens.indexOf('d') != -1 && dateObject.getDate() != result[2])){
459                 return null;
460         }
461
462         return dateObject; // Date
463 };
464
465 function _processPattern(pattern, applyPattern, applyLiteral, applyAll){
466         //summary: Process a pattern with literals in it
467
468         // Break up on single quotes, treat every other one as a literal, except '' which becomes '
469         var identity = function(x){return x;};
470         applyPattern = applyPattern || identity;
471         applyLiteral = applyLiteral || identity;
472         applyAll = applyAll || identity;
473
474         //split on single quotes (which escape literals in date format strings) 
475         //but preserve escaped single quotes (e.g., o''clock)
476         var chunks = pattern.match(/(''|[^'])+/g); 
477         var literal = false;
478
479         dojo.forEach(chunks, function(chunk, i){
480                 if(!chunk){
481                         chunks[i]='';
482                 }else{
483                         chunks[i]=(literal ? applyLiteral : applyPattern)(chunk);
484                         literal = !literal;
485                 }
486         });
487         return applyAll(chunks.join(''));
488 }
489
490 function _buildDateTimeRE(tokens, bundle, options, pattern){
491         pattern = dojo.regexp.escapeString(pattern);
492         if(!options.strict){ pattern = pattern.replace(" a", " ?a"); } // kludge to tolerate no space before am/pm
493         return pattern.replace(/([a-z])\1*/ig, function(match){
494                 // Build a simple regexp.  Avoid captures, which would ruin the tokens list
495                 var s;
496                 var c = match.charAt(0);
497                 var l = match.length;
498                 var p2 = '', p3 = '';
499                 if(options.strict){
500                         if(l > 1){ p2 = '0' + '{'+(l-1)+'}'; }
501                         if(l > 2){ p3 = '0' + '{'+(l-2)+'}'; }
502                 }else{
503                         p2 = '0?'; p3 = '0{0,2}';
504                 }
505                 switch(c){
506                         case 'y':
507                                 s = '\\d{2,4}';
508                                 break;
509                         case 'M':
510                                 s = (l>2) ? '\\S+' : p2+'[1-9]|1[0-2]';
511                                 break;
512                         case 'D':
513                                 s = p2+'[1-9]|'+p3+'[1-9][0-9]|[12][0-9][0-9]|3[0-5][0-9]|36[0-6]';
514                                 break;
515                         case 'd':
516                                 s = p2+'[1-9]|[12]\\d|3[01]';
517                                 break;
518                         case 'w':
519                                 s = p2+'[1-9]|[1-4][0-9]|5[0-3]';
520                                 break;
521                     case 'E':
522                                 s = '\\S+';
523                                 break;
524                         case 'h': //hour (1-12)
525                                 s = p2+'[1-9]|1[0-2]';
526                                 break;
527                         case 'k': //hour (0-11)
528                                 s = p2+'\\d|1[01]';
529                                 break;
530                         case 'H': //hour (0-23)
531                                 s = p2+'\\d|1\\d|2[0-3]';
532                                 break;
533                         case 'K': //hour (1-24)
534                                 s = p2+'[1-9]|1\\d|2[0-4]';
535                                 break;
536                         case 'm':
537                         case 's':
538                                 s = '[0-5]\\d';
539                                 break;
540                         case 'S':
541                                 s = '\\d{'+l+'}';
542                                 break;
543                         case 'a':
544                                 var am = options.am || bundle.am || 'AM';
545                                 var pm = options.pm || bundle.pm || 'PM';
546                                 if(options.strict){
547                                         s = am + '|' + pm;
548                                 }else{
549                                         s = am + '|' + pm;
550                                         if(am != am.toLowerCase()){ s += '|' + am.toLowerCase(); }
551                                         if(pm != pm.toLowerCase()){ s += '|' + pm.toLowerCase(); }
552                                 }
553                                 break;
554                         default:
555                         // case 'v':
556                         // case 'z':
557                         // case 'Z':
558                                 s = ".*";
559 //                              console.debug("parse of date format, pattern=" + pattern);
560                 }
561
562                 if(tokens){ tokens.push(match); }
563
564                 return "(" + s + ")"; // add capture
565         }).replace(/[\xa0 ]/g, "[\\s\\xa0]"); // normalize whitespace.  Need explicit handling of \xa0 for IE.
566 }
567 })();
568
569 (function(){
570 var _customFormats = [];
571 dojo.date.locale.addCustomFormats = function(/*String*/packageName, /*String*/bundleName){
572         // summary:
573         //              Add a reference to a bundle containing localized custom formats to be
574         //              used by date/time formatting and parsing routines.
575         //
576         // description:
577         //              The user may add custom localized formats where the bundle has properties following the
578         //              same naming convention used by dojo.cldr: `dateFormat-xxxx` / `timeFormat-xxxx`
579         //              The pattern string should match the format used by the CLDR.
580         //              See dojo.date.locale.format() for details.
581         //              The resources must be loaded by dojo.requireLocalization() prior to use
582
583         _customFormats.push({pkg:packageName,name:bundleName});
584 };
585
586 dojo.date.locale._getGregorianBundle = function(/*String*/locale){
587         var gregorian = {};
588         dojo.forEach(_customFormats, function(desc){
589                 var bundle = dojo.i18n.getLocalization(desc.pkg, desc.name, locale);
590                 gregorian = dojo.mixin(gregorian, bundle);
591         }, this);
592         return gregorian; /*Object*/
593 };
594 })();
595
596 dojo.date.locale.addCustomFormats("dojo.cldr","gregorian");
597
598 dojo.date.locale.getNames = function(/*String*/item, /*String*/type, /*String?*/use, /*String?*/locale){
599         // summary:
600         //              Used to get localized strings from dojo.cldr for day or month names.
601         //
602         // item:
603         //      'months' || 'days'
604         // type:
605         //      'wide' || 'narrow' || 'abbr' (e.g. "Monday", "Mon", or "M" respectively, in English)
606         // use:
607         //      'standAlone' || 'format' (default)
608         // locale:
609         //      override locale used to find the names
610
611         var label;
612         var lookup = dojo.date.locale._getGregorianBundle(locale);
613         var props = [item, use, type];
614         if(use == 'standAlone'){
615                 label = lookup[props.join('-')];
616         }
617         props[1] = 'format';
618
619         // return by copy so changes won't be made accidentally to the in-memory model
620         return (label || lookup[props.join('-')]).concat(); /*Array*/
621 };
622
623 dojo.date.locale.isWeekend = function(/*Date?*/dateObject, /*String?*/locale){
624         // summary:
625         //      Determines if the date falls on a weekend, according to local custom.
626
627         var weekend = dojo.cldr.supplemental.getWeekend(locale);
628         var day = (dateObject || new Date()).getDay();
629         if(weekend.end < weekend.start){
630                 weekend.end += 7;
631                 if(day < weekend.start){ day += 7; }
632         }
633         return day >= weekend.start && day <= weekend.end; // Boolean
634 };
635
636 // These are used only by format and strftime.  Do they need to be public?  Which module should they go in?
637
638 dojo.date.locale._getDayOfYear = function(/*Date*/dateObject){
639         // summary: gets the day of the year as represented by dateObject
640         return dojo.date.difference(new Date(dateObject.getFullYear(), 0, 1), dateObject) + 1; // Number
641 };
642
643 dojo.date.locale._getWeekOfYear = function(/*Date*/dateObject, /*Number*/firstDayOfWeek){
644         if(arguments.length == 1){ firstDayOfWeek = 0; } // Sunday
645
646         var firstDayOfYear = new Date(dateObject.getFullYear(), 0, 1).getDay();
647         var adj = (firstDayOfYear - firstDayOfWeek + 7) % 7;
648         var week = Math.floor((dojo.date.locale._getDayOfYear(dateObject) + adj - 1) / 7);
649
650         // if year starts on the specified day, start counting weeks at 1
651         if(firstDayOfYear == firstDayOfWeek){ week++; }
652
653         return week; // Number
654 };
655
656 }