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

Side by Side Diff: frog/lib/date_implementation.dart

Issue 10532068: Revert "Remove deprecated classes and functions in Date." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « frog/lib/corelib.dart ('k') | lib/compiler/implementation/lib/core.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 // TODO(jmesserly): the native class should be the real JS Date. 5 // TODO(jmesserly): the native class should be the real JS Date.
6 // TODO(jimhug): Making the date value non-lazy might be a good path there. 6 // TODO(jimhug): Making the date value non-lazy might be a good path there.
7 class DateImplementation implements Date { 7 class DateImplementation implements Date {
8 final int value; 8 final int value;
9 final TimeZone timeZone; 9 final TimeZone timeZone;
10 10
11 factory DateImplementation(int years, 11 factory DateImplementation(int years,
12 [int month = 1, 12 [int month = 1,
13 int day = 1, 13 int day = 1,
14 int hours = 0, 14 int hours = 0,
15 int minutes = 0, 15 int minutes = 0,
16 int seconds = 0, 16 int seconds = 0,
17 int milliseconds = 0, 17 int milliseconds = 0,
18 bool isUtc = false]) { 18 bool isUtc = false]) {
19 return new DateImplementation.withTimeZone( 19 return new DateImplementation.withTimeZone(
20 years, month, day, 20 years, month, day,
21 hours, minutes, seconds, milliseconds, 21 hours, minutes, seconds, milliseconds,
22 isUtc ? const TimeZone.utc() 22 isUtc ? const TimeZoneImplementation.utc()
23 : new TimeZone.local()); 23 : new TimeZoneImplementation.local());
24 } 24 }
25 25
26 DateImplementation.withTimeZone(int years, 26 DateImplementation.withTimeZone(int years,
27 int month, 27 int month,
28 int day, 28 int day,
29 int hours, 29 int hours,
30 int minutes, 30 int minutes,
31 int seconds, 31 int seconds,
32 int milliseconds, 32 int milliseconds,
33 TimeZone timeZone) 33 TimeZone timeZone)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 throw new IllegalArgumentException(formattedString); 92 throw new IllegalArgumentException(formattedString);
93 } 93 }
94 if (addOneMillisecond) epochValue++; 94 if (addOneMillisecond) epochValue++;
95 return new DateImplementation.fromEpoch(epochValue, isUtc); 95 return new DateImplementation.fromEpoch(epochValue, isUtc);
96 } else { 96 } else {
97 throw new IllegalArgumentException(formattedString); 97 throw new IllegalArgumentException(formattedString);
98 } 98 }
99 } 99 }
100 100
101 DateImplementation.fromEpoch(this.value, [bool isUtc = false]) 101 DateImplementation.fromEpoch(this.value, [bool isUtc = false])
102 : this.timeZone = isUtc ? const TimeZone.utc() : new TimeZone.local(); 102 : this.timeZone = isUtc ? const TimeZoneImplementation.utc()
103 : new TimeZoneImplementation.local();
103 104
104 bool operator ==(other) { 105 bool operator ==(other) {
105 if (other is !DateImplementation) return false; 106 if (other is !DateImplementation) return false;
106 return (value == other.value); 107 return (value == other.value);
107 } 108 }
108 109
109 bool operator <(Date other) => value < other.value; 110 bool operator <(Date other) => value < other.value;
110 111
111 bool operator <=(Date other) => value <= other.value; 112 bool operator <=(Date other) => value <= other.value;
112 113
113 bool operator >(Date other) => value > other.value; 114 bool operator >(Date other) => value > other.value;
114 115
115 bool operator >=(Date other) => value >= other.value; 116 bool operator >=(Date other) => value >= other.value;
116 117
117 int compareTo(Date other) { 118 int compareTo(Date other) {
118 return value.compareTo(other.value); 119 return value.compareTo(other.value);
119 } 120 }
120 121
121 int hashCode() { 122 int hashCode() {
122 return value; 123 return value;
123 } 124 }
124 125
125 Date toLocal() { 126 Date toLocal() {
126 if (isUtc()) return changeTimeZone(new TimeZone.local()); 127 if (isUtc()) return changeTimeZone(new TimeZoneImplementation.local());
127 return this; 128 return this;
128 } 129 }
129 130
130 Date toUtc() { 131 Date toUtc() {
131 if (isUtc()) return this; 132 if (isUtc()) return this;
132 return changeTimeZone(const TimeZone.utc()); 133 return changeTimeZone(const TimeZoneImplementation.utc());
133 } 134 }
134 135
135 Date changeTimeZone(TimeZone targetTimeZone) { 136 Date changeTimeZone(TimeZone targetTimeZone) {
136 if (targetTimeZone == null) { 137 if (targetTimeZone == null) {
137 targetTimeZone = new TimeZone.local(); 138 targetTimeZone = new TimeZoneImplementation.local();
138 } 139 }
139 return new Date.fromEpoch(value, targetTimeZone.isUtc); 140 return new Date.fromEpoch(value, targetTimeZone.isUtc);
140 } 141 }
141 142
142 String get timeZoneName() { throw "Unimplemented"; } 143 String get timeZoneName() { throw "Unimplemented"; }
143 Duration get timeZoneOffset() { throw "Unimplemented"; } 144 Duration get timeZoneOffset() { throw "Unimplemented"; }
144 145
145 int get year() native 146 int get year() native
146 '''return this.isUtc() ? this._asJs().getUTCFullYear() : 147 '''return this.isUtc() ? this._asJs().getUTCFullYear() :
147 this._asJs().getFullYear();''' { 148 this._asJs().getFullYear();''' {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 static int _now() native "return new Date().valueOf();"; 277 static int _now() native "return new Date().valueOf();";
277 278
278 // Lazily keep a JS Date stored in the dart object. 279 // Lazily keep a JS Date stored in the dart object.
279 _asJs() native ''' 280 _asJs() native '''
280 if (!this.date) { 281 if (!this.date) {
281 this.date = new Date(this.value); 282 this.date = new Date(this.value);
282 } 283 }
283 return this.date;'''; 284 return this.date;''';
284 } 285 }
285 286
286 class TimeZone { 287 // Trivial implementation of TimeZone
287 const TimeZone.utc() : this.isUtc = true; 288 class TimeZoneImplementation implements TimeZone {
288 const TimeZone.local() : this.isUtc = false; 289 const TimeZoneImplementation.utc() : this.isUtc = true;
290 const TimeZoneImplementation.local() : this.isUtc = false;
289 291
290 bool operator ==(other) { 292 bool operator ==(other) {
291 if (other is !TimeZone) return false; 293 if (other is !TimeZoneImplementation) return false;
292 return isUtc == other.isUtc; 294 return isUtc == other.isUtc;
293 } 295 }
294 296
295 String toString() { 297 String toString() {
296 if (isUtc) return "TimeZone (UTC)"; 298 if (isUtc) return "TimeZone (UTC)";
297 return "TimeZone (Local)"; 299 return "TimeZone (Local)";
298 } 300 }
299 301
300 final bool isUtc; 302 final bool isUtc;
301 } 303 }
OLDNEW
« no previous file with comments | « frog/lib/corelib.dart ('k') | lib/compiler/implementation/lib/core.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698