Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /** | 1 /** |
| 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 * for details. All rights reserved. Use of this source code is governed by a | 3 * for details. All rights reserved. Use of this source code is governed by a |
| 4 * BSD-style license that can be found in the LICENSE file. | 4 * BSD-style license that can be found in the LICENSE file. |
| 5 * | 5 * |
| 6 * DateFormat is for formatting and parsing dates in a locale-sensitive | 6 * DateFormat is for formatting and parsing dates in a locale-sensitive |
| 7 * manner. | 7 * manner. |
| 8 * It allows the user to use any customized pattern to parse or format | 8 * It allows the user to use any customized pattern to parse or format |
| 9 * date-time strings under certain locales. Date elements that vary across | 9 * date-time strings under certain locales. Date elements that vary across |
| 10 * locales include month name, weekname, field, order, etc. | 10 * locales include month name, weekname, field, order, etc. |
| 11 * | 11 * |
| 12 * This library uses the ICU/JDK date/time pattern specification as described | 12 * This library uses the ICU/JDK date/time pattern specification as described |
| 13 * below. | 13 * below. |
| 14 * | 14 * |
| 15 * Time Format Syntax: To specify the time format use a time pattern string. | 15 * Time Format Syntax: To specify the time format use a time pattern string. |
| 16 * In this pattern, following letters are reserved as pattern letters, which | 16 * In this pattern, following letters are reserved as pattern letters, which |
| 17 * are defined in the following manner: | 17 * are defined in the following manner: |
| 18 * | 18 * |
| 19 * Symbol Meaning Presentation Example | 19 * Symbol Meaning Presentation Example |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 * the run, then the leftmost field is shortened by one character, and the | 97 * the run, then the leftmost field is shortened by one character, and the |
| 98 * entire run is parsed again. This is repeated until either the parse succeeds | 98 * entire run is parsed again. This is repeated until either the parse succeeds |
| 99 * or the leftmost field is one character in length. If the parse still fails at | 99 * or the leftmost field is one character in length. If the parse still fails at |
| 100 * that point, the parse of the run fails. | 100 * that point, the parse of the run fails. |
| 101 */ | 101 */ |
| 102 | 102 |
| 103 #library('DateFormat'); | 103 #library('DateFormat'); |
| 104 | 104 |
| 105 class DateFormat { | 105 class DateFormat { |
| 106 | 106 |
| 107 /** Definition of this object formats dates. */ | 107 /** |
| 108 * Definition of how this object formats dates. | |
| 109 * (TODO) alanknight This might just be a String, but it's not clear yet. | |
| 110 */ | |
| 108 var formatDefinition; | 111 var formatDefinition; |
| 109 | 112 |
| 113 /** | |
| 114 * The locale we use to format dates. | |
| 115 * (TODO) alanknight Is there a Locale type? Or is this just a string? | |
| 116 */ | |
| 117 var locale; | |
| 118 | |
| 119 | |
| 110 /** Date/Time format patterns. */ | 120 /** Date/Time format patterns. */ |
|
Emily Fortuna
2012/06/06 22:57:33
120-134 is all indented one extra space. not such
| |
| 111 // TODO(alanknight): There's a style question of whether to use fullDate or | 121 // TODO(alanknight): There's a style question of whether to use fullDate or |
| 112 // FULL_DATE naming conventions. | 122 // FULL_DATE naming conventions. |
| 113 static final int _fullDate = 0; | 123 static final int _fullDate = 0; |
| 114 static final int _longDate = 1; | 124 static final int _longDate = 1; |
| 115 static final int _mediumDate = 2; | 125 static final int _mediumDate = 2; |
| 116 static final int _shortDate = 3; | 126 static final int _shortDate = 3; |
| 117 static final int _fullTime = 4; | 127 static final int _fullTime = 4; |
| 118 static final int _longTime = 5; | 128 static final int _longTime = 5; |
| 119 static final int _mediumTime = 6; | 129 static final int _mediumTime = 6; |
| 120 static final int _shortTime = 7; | 130 static final int _shortTime = 7; |
| 121 static final int _fullDateTime = 8; | 131 static final int _fullDateTime = 8; |
| 122 static final int _longDateTime = 9; | 132 static final int _longDateTime = 9; |
| 123 static final int _mediumDateTime = 10; | 133 static final int _mediumDateTime = 10; |
| 124 static final int _shortDateTime = 11; | 134 static final int _shortDateTime = 11; |
| 125 | 135 |
| 126 /** | 136 /** |
| 127 * Named constructors for each of the above values. | 137 * Named constructors for each of the above values. |
| 128 * These could probably be made shorter if we just set the format to the | |
| 129 * constant and the parsing was lazy. | |
| 130 */ | 138 */ |
| 131 DateFormat.fullDate() : this.formatDefinition = _fullDate; | 139 DateFormat.fullDate() : this.formatDefinition = _fullDate; |
| 132 DateFormat.longDate() : this.formatDefinition = _longDate; | 140 DateFormat.longDate() : this.formatDefinition = _longDate; |
| 133 DateFormat.mediumDate() : this.formatDefinition = _mediumDate; | 141 DateFormat.mediumDate() : this.formatDefinition = _mediumDate; |
| 134 DateFormat.shortDate() : this.formatDefinition = _shortDate; | 142 DateFormat.shortDate() : this.formatDefinition = _shortDate; |
| 135 DateFormat.fullTime() : this.formatDefinition = _fullTime; | 143 DateFormat.fullTime() : this.formatDefinition = _fullTime; |
| 136 DateFormat.longTime() : this.formatDefinition = _longTime; | 144 DateFormat.longTime() : this.formatDefinition = _longTime; |
| 137 DateFormat.mediumTime() : this.formatDefinition = _mediumTime; | 145 DateFormat.mediumTime() : this.formatDefinition = _mediumTime; |
| 138 DateFormat.shortTime() : this.formatDefinition = _shortTime; | 146 DateFormat.shortTime() : this.formatDefinition = _shortTime; |
| 139 DateFormat.fullDateTime() : this.formatDefinition = _fullDateTime; | 147 DateFormat.fullDateTime() : this.formatDefinition = _fullDateTime; |
| 140 DateFormat.longDateTime() : this.formatDefinition = _longDateTime; | 148 DateFormat.longDateTime() : this.formatDefinition = _longDateTime; |
| 141 DateFormat.mediumDateTime() : this.formatDefinition = _mediumDateTime; | 149 DateFormat.mediumDateTime() : this.formatDefinition = _mediumDateTime; |
| 142 DateFormat.shortDateTime() : this.formatDefinition = _shortDateTime; | 150 DateFormat.shortDateTime() : this.formatDefinition = _shortDateTime; |
| 143 | 151 |
| 152 /** | |
| 153 * Explicit constructor given a particular format | |
|
Emily Fortuna
2012/06/06 22:57:33
comment must end in period.
Alan Knight
2012/06/06 23:08:09
Done.
| |
| 154 */ | |
| 144 DateFormat(this.formatDefinition); | 155 DateFormat(this.formatDefinition); |
| 145 | 156 |
| 146 /** | 157 /** |
| 147 * | 158 * Constructors for dates/times that use a default format. |
| 159 */ | |
| 160 DateFormat.date([this.locale]) : formatDefinition = _fullDate; | |
| 161 DateFormat.time() : formatDefinition = _fullTime; | |
| 162 DateFormat.dateTime() : formatDefinition = _fullDateTime; | |
| 163 | |
| 164 /** | |
| 165 * | |
| 148 */ | 166 */ |
| 149 String parse(String inputString) { | 167 String parse(String inputString) { |
| 150 return inputString; | 168 return inputString; |
| 151 } | 169 } |
| 152 | 170 |
| 153 /** | 171 /** |
| 154 * Format the given [date] object according to preset pattern and current | 172 * Format the given [date] object according to preset pattern and current |
| 155 * locale and return a formated string for the given date. | 173 * locale and return a formated string for the given date. |
| 156 */ | 174 */ |
| 157 String format(Date date, [TimeZone timeZone]) { | 175 String format(Date date, [TimeZone timeZone]) { |
| 158 // TODO(efortuna): optional TimeZone argument? TimeZone is deprecated... | 176 // TODO(efortuna): optional TimeZone argument? TimeZone is deprecated... |
| 159 return date.toString(); | 177 return date.toString(); |
| 160 } | 178 } |
| 161 } | 179 } |
| OLD | NEW |