OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library date_symbols; | 4 library date_symbols; |
5 | 5 |
6 /** | 6 /// This holds onto information about how a particular locale formats dates. It |
7 * This holds onto information about how a particular locale formats dates. It | 7 /// contains mostly strings, e.g. what the names of months or weekdays are, |
8 * contains mostly strings, e.g. what the names of months or weekdays are, | 8 /// but also indicates things like the first day of the week. We expect the data |
9 * but also indicates things like the first day of the week. We expect the data | 9 /// for instances of these to be generated out of ICU or a similar reference |
10 * for instances of these to be generated out of ICU or a similar reference | 10 /// source. This is used in conjunction with the date_time_patterns, which |
11 * source. This is used in conjunction with the date_time_patterns, which | 11 /// defines for a particular locale the different named formats that will |
12 * defines for a particular locale the different named formats that will | 12 /// make use of this data. |
13 * make use of this data. | |
14 */ | |
15 class DateSymbols { | 13 class DateSymbols { |
16 String NAME; | 14 String NAME; |
17 List<String> ERAS, | 15 List<String> ERAS, |
18 ERANAMES, | 16 ERANAMES, |
19 NARROWMONTHS, | 17 NARROWMONTHS, |
20 STANDALONENARROWMONTHS, | 18 STANDALONENARROWMONTHS, |
21 MONTHS, | 19 MONTHS, |
22 STANDALONEMONTHS, | 20 STANDALONEMONTHS, |
23 SHORTMONTHS, | 21 SHORTMONTHS, |
24 STANDALONESHORTMONTHS, | 22 STANDALONESHORTMONTHS, |
(...skipping 24 matching lines...) Expand all Loading... |
49 // where there's only a fixed set of available formats. | 47 // where there's only a fixed set of available formats. |
50 // Here we have the patterns separately. These should | 48 // Here we have the patterns separately. These should |
51 // either be used, or removed. | 49 // either be used, or removed. |
52 this.DATEFORMATS, this.TIMEFORMATS, this.AVAILABLEFORMATS, | 50 this.DATEFORMATS, this.TIMEFORMATS, this.AVAILABLEFORMATS, |
53 this.FIRSTDAYOFWEEK, this.WEEKENDRANGE, this.FIRSTWEEKCUTOFFDAY, | 51 this.FIRSTDAYOFWEEK, this.WEEKENDRANGE, this.FIRSTWEEKCUTOFFDAY, |
54 this.DATETIMEFORMATS}); | 52 this.DATETIMEFORMATS}); |
55 | 53 |
56 // TODO(alanknight): Replace this with use of a more general serialization | 54 // TODO(alanknight): Replace this with use of a more general serialization |
57 // facility once one is available. Issue 4926. | 55 // facility once one is available. Issue 4926. |
58 DateSymbols.deserializeFromMap(Map map) { | 56 DateSymbols.deserializeFromMap(Map map) { |
| 57 List<String> _getStringList(String name) => new List<String>.from(map[name])
; |
59 NAME = map["NAME"]; | 58 NAME = map["NAME"]; |
60 ERAS = map["ERAS"]; | 59 ERAS = _getStringList("ERAS"); |
61 ERANAMES = map["ERANAMES"]; | 60 ERANAMES = _getStringList("ERANAMES"); |
62 NARROWMONTHS = map["NARROWMONTHS"]; | 61 NARROWMONTHS = _getStringList("NARROWMONTHS"); |
63 STANDALONENARROWMONTHS = map["STANDALONENARROWMONTHS"]; | 62 STANDALONENARROWMONTHS = _getStringList("STANDALONENARROWMONTHS"); |
64 MONTHS = map["MONTHS"]; | 63 MONTHS = _getStringList("MONTHS"); |
65 STANDALONEMONTHS = map["STANDALONEMONTHS"]; | 64 STANDALONEMONTHS = _getStringList("STANDALONEMONTHS"); |
66 SHORTMONTHS = map["SHORTMONTHS"]; | 65 SHORTMONTHS = _getStringList("SHORTMONTHS"); |
67 STANDALONESHORTMONTHS = map["STANDALONESHORTMONTHS"]; | 66 STANDALONESHORTMONTHS = _getStringList("STANDALONESHORTMONTHS"); |
68 WEEKDAYS = map["WEEKDAYS"]; | 67 WEEKDAYS = _getStringList("WEEKDAYS"); |
69 STANDALONEWEEKDAYS = map["STANDALONEWEEKDAYS"]; | 68 STANDALONEWEEKDAYS = _getStringList("STANDALONEWEEKDAYS"); |
70 SHORTWEEKDAYS = map["SHORTWEEKDAYS"]; | 69 SHORTWEEKDAYS = _getStringList("SHORTWEEKDAYS"); |
71 STANDALONESHORTWEEKDAYS = map["STANDALONESHORTWEEKDAYS"]; | 70 STANDALONESHORTWEEKDAYS = _getStringList("STANDALONESHORTWEEKDAYS"); |
72 NARROWWEEKDAYS = map["NARROWWEEKDAYS"]; | 71 NARROWWEEKDAYS = _getStringList("NARROWWEEKDAYS"); |
73 STANDALONENARROWWEEKDAYS = map["STANDALONENARROWWEEKDAYS"]; | 72 STANDALONENARROWWEEKDAYS = _getStringList("STANDALONENARROWWEEKDAYS"); |
74 SHORTQUARTERS = map["SHORTQUARTERS"]; | 73 SHORTQUARTERS = _getStringList("SHORTQUARTERS"); |
75 QUARTERS = map["QUARTERS"]; | 74 QUARTERS = _getStringList("QUARTERS"); |
76 AMPMS = map["AMPMS"]; | 75 AMPMS = _getStringList("AMPMS"); |
77 DATEFORMATS = map["DATEFORMATS"]; | 76 DATEFORMATS = _getStringList("DATEFORMATS"); |
78 TIMEFORMATS = map["TIMEFORMATS"]; | 77 TIMEFORMATS = _getStringList("TIMEFORMATS"); |
79 AVAILABLEFORMATS = map["AVAILABLEFORMATS"]; | 78 AVAILABLEFORMATS = new Map<String, String>.from(map["AVAILABLEFORMATS"] ?? {
}); |
80 FIRSTDAYOFWEEK = map["FIRSTDAYOFWEEK"]; | 79 FIRSTDAYOFWEEK = map["FIRSTDAYOFWEEK"]; |
81 WEEKENDRANGE = map["WEEKENDRANGE"]; | 80 WEEKENDRANGE = new List<int>.from(map["WEEKENDRANGE"]); |
82 FIRSTWEEKCUTOFFDAY = map["FIRSTWEEKCUTOFFDAY"]; | 81 FIRSTWEEKCUTOFFDAY = map["FIRSTWEEKCUTOFFDAY"]; |
83 DATETIMEFORMATS = map["DATETIMEFORAMTS"]; | 82 DATETIMEFORMATS = _getStringList("DATETIMEFORMATS"); |
84 } | 83 } |
85 | 84 |
86 Map serializeToMap() => { | 85 Map serializeToMap() => { |
87 "NAME": NAME, | 86 "NAME": NAME, |
88 "ERAS": ERAS, | 87 "ERAS": ERAS, |
89 "ERANAMES": ERANAMES, | 88 "ERANAMES": ERANAMES, |
90 "NARROWMONTHS": NARROWMONTHS, | 89 "NARROWMONTHS": NARROWMONTHS, |
91 "STANDALONENARROWMONTHS": STANDALONENARROWMONTHS, | 90 "STANDALONENARROWMONTHS": STANDALONENARROWMONTHS, |
92 "MONTHS": MONTHS, | 91 "MONTHS": MONTHS, |
93 "STANDALONEMONTHS": STANDALONEMONTHS, | 92 "STANDALONEMONTHS": STANDALONEMONTHS, |
(...skipping 13 matching lines...) Expand all Loading... |
107 "AVAILABLEFORMATS": AVAILABLEFORMATS, | 106 "AVAILABLEFORMATS": AVAILABLEFORMATS, |
108 "FIRSTDAYOFWEEK": FIRSTDAYOFWEEK, | 107 "FIRSTDAYOFWEEK": FIRSTDAYOFWEEK, |
109 "WEEKENDRANGE": WEEKENDRANGE, | 108 "WEEKENDRANGE": WEEKENDRANGE, |
110 "FIRSTWEEKCUTOFFDAY": FIRSTWEEKCUTOFFDAY, | 109 "FIRSTWEEKCUTOFFDAY": FIRSTWEEKCUTOFFDAY, |
111 "DATETIMEFORMATS": DATETIMEFORMATS, | 110 "DATETIMEFORMATS": DATETIMEFORMATS, |
112 }; | 111 }; |
113 | 112 |
114 toString() => NAME; | 113 toString() => NAME; |
115 } | 114 } |
116 | 115 |
117 /** | 116 /// We hard-code the locale data for en_US here so that there's at least one |
118 * We hard-code the locale data for en_US here so that there's at least one | 117 /// locale always available. |
119 * locale always available. | |
120 */ | |
121 var en_USSymbols = new DateSymbols( | 118 var en_USSymbols = new DateSymbols( |
122 NAME: "en_US", | 119 NAME: "en_US", |
123 ERAS: const ['BC', 'AD'], | 120 ERAS: const ['BC', 'AD'], |
124 ERANAMES: const ['Before Christ', 'Anno Domini'], | 121 ERANAMES: const ['Before Christ', 'Anno Domini'], |
125 NARROWMONTHS: const [ | 122 NARROWMONTHS: const [ |
126 'J', | 123 'J', |
127 'F', | 124 'F', |
128 'M', | 125 'M', |
129 'A', | 126 'A', |
130 'M', | 127 'M', |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 'jmz': 'h:mm a z', // HOUR_MINUTETZ | 292 'jmz': 'h:mm a z', // HOUR_MINUTETZ |
296 'jz': 'h a z', // HOURGENERIC_TZ | 293 'jz': 'h a z', // HOURGENERIC_TZ |
297 'm': 'm', // MINUTE | 294 'm': 'm', // MINUTE |
298 'ms': 'mm:ss', // MINUTE_SECOND | 295 'ms': 'mm:ss', // MINUTE_SECOND |
299 's': 's', // SECOND | 296 's': 's', // SECOND |
300 'v': 'v', // ABBR_GENERIC_TZ | 297 'v': 'v', // ABBR_GENERIC_TZ |
301 'z': 'z', // ABBR_SPECIFIC_TZ | 298 'z': 'z', // ABBR_SPECIFIC_TZ |
302 'zzzz': 'zzzz', // SPECIFIC_TZ | 299 'zzzz': 'zzzz', // SPECIFIC_TZ |
303 'ZZZZ': 'ZZZZ' // ABBR_UTC_TZ | 300 'ZZZZ': 'ZZZZ' // ABBR_UTC_TZ |
304 }; | 301 }; |
OLD | NEW |