1 | define(["../_base/kernel", "../_base/lang", "../i18n"], function(dojo, lang) { |
---|
2 | // module: |
---|
3 | // dojo/cldr/supplemental |
---|
4 | // summary: |
---|
5 | // TODOC |
---|
6 | |
---|
7 | lang.getObject("cldr.supplemental", true, dojo); |
---|
8 | |
---|
9 | dojo.cldr.supplemental.getFirstDayOfWeek = function(/*String?*/locale){ |
---|
10 | // summary: Returns a zero-based index for first day of the week |
---|
11 | // description: |
---|
12 | // Returns a zero-based index for first day of the week, as used by the local (Gregorian) calendar. |
---|
13 | // e.g. Sunday (returns 0), or Monday (returns 1) |
---|
14 | |
---|
15 | // from http://www.unicode.org/cldr/data/common/supplemental/supplementalData.xml:supplementalData/weekData/firstDay |
---|
16 | var firstDay = {/*default is 1=Monday*/ |
---|
17 | mv:5, |
---|
18 | ae:6,af:6,bh:6,dj:6,dz:6,eg:6,er:6,et:6,iq:6,ir:6,jo:6,ke:6,kw:6, |
---|
19 | ly:6,ma:6,om:6,qa:6,sa:6,sd:6,so:6,sy:6,tn:6,ye:6, |
---|
20 | ar:0,as:0,az:0,bw:0,ca:0,cn:0,fo:0,ge:0,gl:0,gu:0,hk:0, |
---|
21 | il:0,'in':0,jm:0,jp:0,kg:0,kr:0,la:0,mh:0,mn:0,mo:0,mp:0, |
---|
22 | mt:0,nz:0,ph:0,pk:0,sg:0,th:0,tt:0,tw:0,um:0,us:0,uz:0, |
---|
23 | vi:0,zw:0 |
---|
24 | // variant. do not use? gb:0, |
---|
25 | }; |
---|
26 | |
---|
27 | var country = dojo.cldr.supplemental._region(locale); |
---|
28 | var dow = firstDay[country]; |
---|
29 | return (dow === undefined) ? 1 : dow; /*Number*/ |
---|
30 | }; |
---|
31 | |
---|
32 | dojo.cldr.supplemental._region = function(/*String?*/locale){ |
---|
33 | locale = dojo.i18n.normalizeLocale(locale); |
---|
34 | var tags = locale.split('-'); |
---|
35 | var region = tags[1]; |
---|
36 | if(!region){ |
---|
37 | // IE often gives language only (#2269) |
---|
38 | // Arbitrary mappings of language-only locales to a country: |
---|
39 | region = {de:"de", en:"us", es:"es", fi:"fi", fr:"fr", he:"il", hu:"hu", it:"it", |
---|
40 | ja:"jp", ko:"kr", nl:"nl", pt:"br", sv:"se", zh:"cn"}[tags[0]]; |
---|
41 | }else if(region.length == 4){ |
---|
42 | // The ISO 3166 country code is usually in the second position, unless a |
---|
43 | // 4-letter script is given. See http://www.ietf.org/rfc/rfc4646.txt |
---|
44 | region = tags[2]; |
---|
45 | } |
---|
46 | return region; |
---|
47 | }; |
---|
48 | |
---|
49 | dojo.cldr.supplemental.getWeekend = function(/*String?*/locale){ |
---|
50 | // summary: Returns a hash containing the start and end days of the weekend |
---|
51 | // description: |
---|
52 | // Returns a hash containing the start and end days of the weekend according to local custom using locale, |
---|
53 | // or by default in the user's locale. |
---|
54 | // e.g. {start:6, end:0} |
---|
55 | |
---|
56 | // from http://www.unicode.org/cldr/data/common/supplemental/supplementalData.xml:supplementalData/weekData/weekend{Start,End} |
---|
57 | var weekendStart = {/*default is 6=Saturday*/ |
---|
58 | 'in':0, |
---|
59 | af:4,dz:4,ir:4,om:4,sa:4,ye:4, |
---|
60 | ae:5,bh:5,eg:5,il:5,iq:5,jo:5,kw:5,ly:5,ma:5,qa:5,sd:5,sy:5,tn:5 |
---|
61 | }; |
---|
62 | |
---|
63 | var weekendEnd = {/*default is 0=Sunday*/ |
---|
64 | af:5,dz:5,ir:5,om:5,sa:5,ye:5, |
---|
65 | ae:6,bh:5,eg:6,il:6,iq:6,jo:6,kw:6,ly:6,ma:6,qa:6,sd:6,sy:6,tn:6 |
---|
66 | }; |
---|
67 | |
---|
68 | var country = dojo.cldr.supplemental._region(locale); |
---|
69 | var start = weekendStart[country]; |
---|
70 | var end = weekendEnd[country]; |
---|
71 | if(start === undefined){start=6;} |
---|
72 | if(end === undefined){end=0;} |
---|
73 | return {start:start, end:end}; /*Object {start,end}*/ |
---|
74 | }; |
---|
75 | |
---|
76 | return dojo.cldr.supplemental; |
---|
77 | }); |
---|