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

Side by Side Diff: client/samples/total/src/DateTimeUtils.dart

Issue 8786002: Check that interface constructors and default class constructors are compatible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Check that types of constructors parameters are identical Created 9 years 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
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 class DateUtils { 5 class DateUtils {
6 static final int DAYS_FROM_1900_TO_1970 = 25569; 6 static final int DAYS_FROM_1900_TO_1970 = 25569;
7 static final int MILLISECONDS_PER_DAY = 86400000; 7 static final int MILLISECONDS_PER_DAY = 86400000;
8 static final int MILLISECONDS_PER_HOUR = 3600000; 8 static final int MILLISECONDS_PER_HOUR = 3600000;
9 static Date _EPOCH; 9 static Date _EPOCH;
10 10
11 // Return the 1899-12-30 spreadsheet epoch 11 // Return the 1899-12-30 spreadsheet epoch
12 static Date get EPOCH() { 12 static Date get EPOCH() {
13 if (_EPOCH == null) { 13 if (_EPOCH == null) {
14 _EPOCH = new Date(1899, 12, 30, 0, 0, 0, 0); 14 _EPOCH = new Date(1899, 12, 30, 0, 0, 0, 0);
15 } 15 }
16 return _EPOCH; 16 return _EPOCH;
17 } 17 }
18 18
19 static double getDate(int year, int month, int day) { 19 static double getDate(int year, int month, int day) {
20 Date dateTime = new Date(year, month, day, 12, 0, 0, 0); 20 Date dateTime = new Date(year, month, day, 12, 0, 0, 0);
21 int milliseconds = dateTime.difference(EPOCH).inMilliseconds; 21 int milliseconds = dateTime.difference(EPOCH).inMilliseconds;
22 double days = (milliseconds / MILLISECONDS_PER_DAY).floor(); 22 double days = (milliseconds / MILLISECONDS_PER_DAY).floor();
23 return days; 23 return days;
24 } 24 }
25 25
26 // Return a Date object corresponding to the given number of days after 1899-1 2-30. 26 // Return a Date object corresponding to the given number of days after 1899-1 2-30.
27 static Date getDateTime(double daysSince18991230) { 27 static Date getDateTime(double daysSince18991230) {
28 double daysSinceEpoch = daysSince18991230 - DAYS_FROM_1900_TO_1970; 28 double daysSinceEpoch = daysSince18991230 - DAYS_FROM_1900_TO_1970;
29 double millisSinceEpoch = daysSinceEpoch * MILLISECONDS_PER_DAY; 29 int millisSinceEpoch = (daysSinceEpoch * MILLISECONDS_PER_DAY).toInt();
30 return new Date.fromEpoch(millisSinceEpoch, const TimeZone.utc()); 30 return new Date.fromEpoch(millisSinceEpoch, const TimeZone.utc());
31 } 31 }
32 32
33 static double getTime(int hour, int minute, int second) { 33 static double getTime(int hour, int minute, int second) {
34 Date dateTime = new Date(1899, 12, 30, hour, minute, second, 0); 34 Date dateTime = new Date(1899, 12, 30, hour, minute, second, 0);
35 int milliseconds = dateTime.difference(EPOCH).inMilliseconds; 35 int milliseconds = dateTime.difference(EPOCH).inMilliseconds;
36 double days = milliseconds / MILLISECONDS_PER_DAY; 36 double days = milliseconds / MILLISECONDS_PER_DAY;
37 return days; 37 return days;
38 } 38 }
39 39
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 static double today() => now().floor(); 114 static double today() => now().floor();
115 115
116 // Parse an integer, stripping leading zeros to avoid an octal parsing bug. 116 // Parse an integer, stripping leading zeros to avoid an octal parsing bug.
117 static int _parseInt(String s) { 117 static int _parseInt(String s) {
118 while (s.length > 1 && s.charCodeAt(0) == StringUtils.ZERO) { 118 while (s.length > 1 && s.charCodeAt(0) == StringUtils.ZERO) {
119 s = s.substring(1, s.length); 119 s = s.substring(1, s.length);
120 } 120 }
121 return Math.parseInt(s); 121 return Math.parseInt(s);
122 } 122 }
123 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698