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

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

Issue 10905255: Change Duration to take proper named optional parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
« runtime/lib/date_patch.dart ('K') | « runtime/lib/date_patch.dart ('k') | no next file » | 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 const WEEKDAYS = const ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 10 static const 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.hour, then.minute, then.second, then.millisecond)); 126 days: 0,
127 hours: then.hour,
128 minutes: then.minute,
129 seconds: then.second,
130 milliseconds: then.millisecond));
127 } 131 }
128 132
129 final today = new Date(now.year, now.month, now.day, 0, 0, 0, 0); 133 final today = new Date(now.year, now.month, now.day, 0, 0, 0, 0);
130 Duration delta = today.difference(then); 134 Duration delta = today.difference(then);
131 if (delta.inMilliseconds < Duration.MILLISECONDS_PER_DAY) { 135 if (delta.inMilliseconds < Duration.MILLISECONDS_PER_DAY) {
132 return YESTERDAY; 136 return YESTERDAY;
133 } else if (delta.inMilliseconds < MS_IN_WEEK) { 137 } else if (delta.inMilliseconds < MS_IN_WEEK) {
134 return WEEKDAYS[getWeekday(then)]; 138 return WEEKDAYS[getWeekday(then)];
135 } else { 139 } else {
136 // TODO(jmesserly): locale specific date format 140 // TODO(jmesserly): locale specific date format
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 177 }
174 String twoDigits(int n) { 178 String twoDigits(int n) {
175 if (n >= 10) return "${n}"; 179 if (n >= 10) return "${n}";
176 return "0${n}"; 180 return "0${n}";
177 } 181 }
178 String mm = 182 String mm =
179 twoDigits(duration.inMinutes.remainder(Duration.MINUTES_PER_HOUR)); 183 twoDigits(duration.inMinutes.remainder(Duration.MINUTES_PER_HOUR));
180 return "${hours}:${mm} ${a}"; 184 return "${hours}:${mm} ${a}";
181 } 185 }
182 } 186 }
OLDNEW
« runtime/lib/date_patch.dart ('K') | « runtime/lib/date_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698