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

Side by Side Diff: samples/ui_lib/util/DateUtils.dart

Issue 10538105: Make isUtc a getter, change some method names in Date. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 6 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 | « samples/ui_lib/touch/TimeUtil.dart ('k') | tests/co19/co19-leg.status » ('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 /** 5 /**
6 * General purpose date/time utilities. 6 * General purpose date/time utilities.
7 */ 7 */
8 class DateUtils { 8 class DateUtils {
9 // TODO(jmesserly): localized strings 9 // TODO(jmesserly): localized strings
10 static final WEEKDAYS = const ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 10 static final WEEKDAYS = const ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 */ 116 */
117 static String toRecentTimeString(Date then) { 117 static String toRecentTimeString(Date then) {
118 bool datesAreEqual(Date d1, Date d2) { 118 bool datesAreEqual(Date d1, Date d2) {
119 return (d1.year == d2.year) && (d1.month == d2.month) && 119 return (d1.year == d2.year) && (d1.month == d2.month) &&
120 (d1.day == d2.day); 120 (d1.day == d2.day);
121 } 121 }
122 122
123 final now = new Date.now(); 123 final now = new Date.now();
124 if (datesAreEqual(then, now)) { 124 if (datesAreEqual(then, now)) {
125 return toHourMinutesString(new Duration( 125 return toHourMinutesString(new Duration(
126 0, then.hours, then.minutes, then.seconds, then.milliseconds)); 126 0, then.hour, then.minute, then.second, then.millisecond));
127 } 127 }
128 128
129 final today = new Date(now.year, now.month, now.day, 0, 0, 0, 0); 129 final today = new Date(now.year, now.month, now.day, 0, 0, 0, 0);
130 Duration delta = today.difference(then); 130 Duration delta = today.difference(then);
131 if (delta.inMilliseconds < Duration.MILLISECONDS_PER_DAY) { 131 if (delta.inMilliseconds < Duration.MILLISECONDS_PER_DAY) {
132 return YESTERDAY; 132 return YESTERDAY;
133 } else if (delta.inMilliseconds < MS_IN_WEEK) { 133 } else if (delta.inMilliseconds < MS_IN_WEEK) {
134 return WEEKDAYS[getWeekday(then)]; 134 return WEEKDAYS[getWeekday(then)];
135 } else { 135 } else {
136 // TODO(jmesserly): locale specific date format 136 // TODO(jmesserly): locale specific date format
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 String twoDigits(int n) { 174 String twoDigits(int n) {
175 if (n >= 10) return "${n}"; 175 if (n >= 10) return "${n}";
176 return "0${n}"; 176 return "0${n}";
177 } 177 }
178 String mm = 178 String mm =
179 twoDigits(duration.inMinutes.remainder(Duration.MINUTES_PER_HOUR)); 179 twoDigits(duration.inMinutes.remainder(Duration.MINUTES_PER_HOUR));
180 return "${hours}:${mm} ${a}"; 180 return "${hours}:${mm} ${a}";
181 } 181 }
182 } 182 }
OLDNEW
« no previous file with comments | « samples/ui_lib/touch/TimeUtil.dart ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698