Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Side by Side Diff: samples/swarm/swarm_ui_lib/util/DateUtils.dart

Issue 13841005: Rename DateTime constants to full names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/date_patch.dart ('k') | sdk/lib/core/date_time.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 4
5 part of utilslib; 5 part of utilslib;
6 6
7 /** 7 /**
8 * General purpose date/time utilities. 8 * General purpose date/time utilities.
9 */ 9 */
10 class DateUtils { 10 class DateUtils {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 148 }
149 } 149 }
150 150
151 // TODO(jmesserly): this is a workaround for unimplemented DateTime.weekday 151 // TODO(jmesserly): this is a workaround for unimplemented DateTime.weekday
152 // Code inspired by v8/src/date.js 152 // Code inspired by v8/src/date.js
153 static int getWeekday(DateTime dateTime) { 153 static int getWeekday(DateTime dateTime) {
154 final unixTimeStart = new DateTime(1970, 1, 1, 0, 0, 0, 0); 154 final unixTimeStart = new DateTime(1970, 1, 1, 0, 0, 0, 0);
155 int msSince1970 = dateTime.difference(unixTimeStart).inMilliseconds; 155 int msSince1970 = dateTime.difference(unixTimeStart).inMilliseconds;
156 int daysSince1970 = msSince1970 ~/ Duration.MILLISECONDS_PER_DAY; 156 int daysSince1970 = msSince1970 ~/ Duration.MILLISECONDS_PER_DAY;
157 // 1970-1-1 was Thursday 157 // 1970-1-1 was Thursday
158 return ((daysSince1970 + DateTime.THU) % DateTime.DAYS_IN_WEEK); 158 return ((daysSince1970 + DateTime.THURSDAY) % DateTime.DAYS_IN_WEEK);
159 } 159 }
160 160
161 /** Formats a time in H:MM A format */ 161 /** Formats a time in H:MM A format */
162 // TODO(jmesserly): should get 12 vs 24 hour clock setting from the locale 162 // TODO(jmesserly): should get 12 vs 24 hour clock setting from the locale
163 static String toHourMinutesString(Duration duration) { 163 static String toHourMinutesString(Duration duration) {
164 assert(duration.inDays == 0); 164 assert(duration.inDays == 0);
165 int hours = duration.inHours; 165 int hours = duration.inHours;
166 String a; 166 String a;
167 if (hours >= 12) { 167 if (hours >= 12) {
168 a = 'pm'; 168 a = 'pm';
169 if (hours != 12) { 169 if (hours != 12) {
170 hours -= 12; 170 hours -= 12;
171 } 171 }
172 } else { 172 } else {
173 a = 'am'; 173 a = 'am';
174 if (hours == 0) { 174 if (hours == 0) {
175 hours += 12; 175 hours += 12;
176 } 176 }
177 } 177 }
178 String twoDigits(int n) { 178 String twoDigits(int n) {
179 if (n >= 10) return "${n}"; 179 if (n >= 10) return "${n}";
180 return "0${n}"; 180 return "0${n}";
181 } 181 }
182 String mm = 182 String mm =
183 twoDigits(duration.inMinutes.remainder(Duration.MINUTES_PER_HOUR)); 183 twoDigits(duration.inMinutes.remainder(Duration.MINUTES_PER_HOUR));
184 return "${hours}:${mm} ${a}"; 184 return "${hours}:${mm} ${a}";
185 } 185 }
186 } 186 }
OLDNEW
« no previous file with comments | « runtime/lib/date_patch.dart ('k') | sdk/lib/core/date_time.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698