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

Unified Diff: frog/lib/date_implementation.dart

Issue 10411057: Deprecate use of timezones. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: frog/lib/date_implementation.dart
diff --git a/frog/lib/date_implementation.dart b/frog/lib/date_implementation.dart
index 5dc70f018d3a4aa87b3e32f0d9b4ee4f58d44d80..253fc904260259c81805547f776cc8d603e96c6e 100644
--- a/frog/lib/date_implementation.dart
+++ b/frog/lib/date_implementation.dart
@@ -14,11 +14,13 @@ class DateImplementation implements Date {
int hours = 0,
int minutes = 0,
int seconds = 0,
- int milliseconds = 0]) {
+ int milliseconds = 0,
+ bool isUtc = false]) {
return new DateImplementation.withTimeZone(
ngeoffray 2012/05/22 08:58:45 If that one is deprecated, maybe don't use it.
floitsch 2012/05/22 14:50:38 This is the frog-implementation of the library. Gi
years, month, day,
hours, minutes, seconds, milliseconds,
- new TimeZoneImplementation.local());
+ isUtc ? const TimeZoneImplementation.utc()
+ : new TimeZoneImplementation.local());
}
DateImplementation.withTimeZone(int years,
@@ -84,24 +86,25 @@ class DateImplementation implements Date {
}
// TODO(floitsch): we should not need to test against the empty string.
bool isUtc = (match[8] !== null) && (match[8] != "");
- TimeZone timezone = isUtc ? const TimeZone.utc() : new TimeZone.local();
int epochValue = _valueFromDecomposed(
years, month, day, hours, minutes, seconds, milliseconds, isUtc);
if (epochValue === null) {
throw new IllegalArgumentException(formattedString);
}
if (addOneMillisecond) epochValue++;
- return new DateImplementation.fromEpoch(epochValue, timezone);
+ return new DateImplementation.fromEpoch(epochValue, isUtc);
} else {
throw new IllegalArgumentException(formattedString);
}
}
- const DateImplementation.fromEpoch(this.value, this.timeZone);
+ DateImplementation.fromEpoch(this.value, [bool isUtc = false])
+ : this.timeZone = isUtc ? const TimeZoneImplementation.utc()
+ : new TimeZoneImplementation.local();
bool operator ==(other) {
if (!(other is DateImplementation)) return false;
ngeoffray 2012/05/22 08:58:45 other is !DateImplementation
floitsch 2012/05/22 14:50:38 Done.
- return (value == other.value) && (timeZone == other.timeZone);
+ return (value == other.value);
}
bool operator <(Date other) => value < other.value;
@@ -120,11 +123,22 @@ class DateImplementation implements Date {
return value;
}
+ Date toLocal() {
+ if (isUtc()) return changeTimeZone(new TimeZoneImplementation.local());
ngeoffray 2012/05/22 08:58:45 Don't use the deprecated method?
floitsch 2012/05/22 14:50:38 ditto.
+ return this;
+ }
+
+ Date toUtc() {
+ if (isUtc()) return this;
+ return changeTimeZone(const TimeZoneImplementation.utc());
ngeoffray 2012/05/22 08:58:45 ditto
floitsch 2012/05/22 14:50:38 ditto.
+ }
+
Date changeTimeZone(TimeZone targetTimeZone) {
if (targetTimeZone == null) {
targetTimeZone = new TimeZoneImplementation.local();
}
- return new Date.fromEpoch(value, targetTimeZone);
+ print(targetTimeZone.isUtc);
ngeoffray 2012/05/22 08:58:45 Remove print
floitsch 2012/05/22 14:50:38 ouch. done.
+ return new Date.fromEpoch(value, targetTimeZone.isUtc);
}
String get timeZoneName() { throw "Unimplemented"; }
@@ -184,11 +198,6 @@ class DateImplementation implements Date {
var day = this.isUtc() ? this._asJs().getUTCDay() : this._asJs().getDay();
return (day + 6) % 7;''';
- // TODO(jimhug): Could this please be getters?
- bool isLocalTime() {
- return !timeZone.isUtc;
- }
-
bool isUtc() {
return timeZone.isUtc;
}
@@ -230,13 +239,13 @@ class DateImplementation implements Date {
// Adds the [duration] to this Date instance.
Date add(Duration duration) {
return new DateImplementation.fromEpoch(value + duration.inMilliseconds,
- timeZone);
+ timeZone.isUtc);
}
// Subtracts the [duration] from this Date instance.
Date subtract(Duration duration) {
return new DateImplementation.fromEpoch(value - duration.inMilliseconds,
- timeZone);
+ timeZone.isUtc);
}
// Returns a [Duration] with the difference of [this] and [other].

Powered by Google App Engine
This is Rietveld 408576698