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

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

Issue 10538061: Reapply "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 TimeZoneImplementation.utc() 22 isUtc ? const TimeZone.utc()
23 : new TimeZoneImplementation.local()); 23 : new TimeZone.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 TimeZoneImplementation.utc() 102 : this.timeZone = isUtc ? const TimeZone.utc() : new TimeZone.local();
103 : new TimeZoneImplementation.local();
104 103
105 bool operator ==(other) { 104 bool operator ==(other) {
106 if (other is !DateImplementation) return false; 105 if (other is !DateImplementation) return false;
107 return (value == other.value); 106 return (value == other.value);
108 } 107 }
109 108
110 bool operator <(Date other) => value < other.value; 109 bool operator <(Date other) => value < other.value;
111 110
112 bool operator <=(Date other) => value <= other.value; 111 bool operator <=(Date other) => value <= other.value;
113 112
114 bool operator >(Date other) => value > other.value; 113 bool operator >(Date other) => value > other.value;
115 114
116 bool operator >=(Date other) => value >= other.value; 115 bool operator >=(Date other) => value >= other.value;
117 116
118 int compareTo(Date other) { 117 int compareTo(Date other) {
119 return value.compareTo(other.value); 118 return value.compareTo(other.value);
120 } 119 }
121 120
122 int hashCode() { 121 int hashCode() {
123 return value; 122 return value;
124 } 123 }
125 124
126 Date toLocal() { 125 Date toLocal() {
127 if (isUtc()) return changeTimeZone(new TimeZoneImplementation.local()); 126 if (isUtc()) return changeTimeZone(new TimeZone.local());
128 return this; 127 return this;
129 } 128 }
130 129
131 Date toUtc() { 130 Date toUtc() {
132 if (isUtc()) return this; 131 if (isUtc()) return this;
133 return changeTimeZone(const TimeZoneImplementation.utc()); 132 return changeTimeZone(const TimeZone.utc());
134 } 133 }
135 134
136 Date changeTimeZone(TimeZone targetTimeZone) { 135 Date changeTimeZone(TimeZone targetTimeZone) {
137 if (targetTimeZone == null) { 136 if (targetTimeZone == null) {
138 targetTimeZone = new TimeZoneImplementation.local(); 137 targetTimeZone = new TimeZone.local();
139 } 138 }
140 return new Date.fromEpoch(value, targetTimeZone.isUtc); 139 return new Date.fromEpoch(value, targetTimeZone.isUtc);
141 } 140 }
142 141
143 String get timeZoneName() { throw "Unimplemented"; } 142 String get timeZoneName() { throw "Unimplemented"; }
144 Duration get timeZoneOffset() { throw "Unimplemented"; } 143 Duration get timeZoneOffset() { throw "Unimplemented"; }
145 144
146 int get year() native 145 int get year() native
147 '''return this.isUtc() ? this._asJs().getUTCFullYear() : 146 '''return this.isUtc() ? this._asJs().getUTCFullYear() :
148 this._asJs().getFullYear();''' { 147 this._asJs().getFullYear();''' {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 static int _now() native "return new Date().valueOf();"; 276 static int _now() native "return new Date().valueOf();";
278 277
279 // Lazily keep a JS Date stored in the dart object. 278 // Lazily keep a JS Date stored in the dart object.
280 _asJs() native ''' 279 _asJs() native '''
281 if (!this.date) { 280 if (!this.date) {
282 this.date = new Date(this.value); 281 this.date = new Date(this.value);
283 } 282 }
284 return this.date;'''; 283 return this.date;''';
285 } 284 }
286 285
287 // Trivial implementation of TimeZone 286 class TimeZone {
288 class TimeZoneImplementation implements TimeZone { 287 const TimeZone.utc() : this.isUtc = true;
289 const TimeZoneImplementation.utc() : this.isUtc = true; 288 const TimeZone.local() : this.isUtc = false;
290 const TimeZoneImplementation.local() : this.isUtc = false;
291 289
292 bool operator ==(other) { 290 bool operator ==(other) {
293 if (other is !TimeZoneImplementation) return false; 291 if (other is !TimeZone) return false;
294 return isUtc == other.isUtc; 292 return isUtc == other.isUtc;
295 } 293 }
296 294
297 String toString() { 295 String toString() {
298 if (isUtc) return "TimeZone (UTC)"; 296 if (isUtc) return "TimeZone (UTC)";
299 return "TimeZone (Local)"; 297 return "TimeZone (Local)";
300 } 298 }
301 299
302 final bool isUtc; 300 final bool isUtc;
303 } 301 }
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