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

Side by Side Diff: runtime/lib/date.dart

Issue 10416008: Revert "Add support for timezone offset and timezone name." (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/date.cc ('k') | runtime/vm/bootstrap_natives.h » ('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 // Dart core library. 4 // Dart core library.
5 5
6 class TimeZoneImplementation implements TimeZone { 6 class TimeZoneImplementation implements TimeZone {
7 const TimeZoneImplementation.utc() : isUtc = true; 7 const TimeZoneImplementation.utc() : isUtc = true;
8 TimeZoneImplementation.local() : isUtc = false {} 8 TimeZoneImplementation.local() : isUtc = false {}
9 9
10 bool operator ==(Object other) { 10 bool operator ==(Object other) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 int compareTo(Date other) => value.compareTo(other.value); 123 int compareTo(Date other) => value.compareTo(other.value);
124 int hashCode() => value; 124 int hashCode() => value;
125 125
126 Date changeTimeZone(TimeZone targetTimeZone) { 126 Date changeTimeZone(TimeZone targetTimeZone) {
127 if (targetTimeZone === null) { 127 if (targetTimeZone === null) {
128 targetTimeZone = new TimeZoneImplementation.local(); 128 targetTimeZone = new TimeZoneImplementation.local();
129 } 129 }
130 return new Date.fromEpoch(value, targetTimeZone); 130 return new Date.fromEpoch(value, targetTimeZone);
131 } 131 }
132 132
133 String get timeZoneName() {
134 if (isUtc()) return "UTC";
135 return _timeZoneName(_equivalentSeconds(_secondsSinceEpoch));
136 }
137
138 Duration get timeZoneOffset() {
139 if (isUtc()) return new Duration(0);
140 int offsetInSeconds =
141 _timeZoneOffsetInSeconds(_equivalentSeconds(_secondsSinceEpoch));
142 return new Duration(seconds: offsetInSeconds);
143 }
144
145 int get year() { 133 int get year() {
146 int secondsSinceEpoch = _secondsSinceEpoch; 134 int secondsSinceEpoch = _secondsSinceEpoch;
147 // According to V8 some library calls have troubles with negative values. 135 // According to V8 some library calls have troubles with negative values.
148 // Therefore clamp to 0 - year 2035 (which is less than the size of 32bit). 136 // Therefore clamp to 0 - year 2035 (which is less than the size of 32bit).
149 if (secondsSinceEpoch >= 0 && secondsSinceEpoch < _SECONDS_YEAR_2035) { 137 if (secondsSinceEpoch >= 0 && secondsSinceEpoch < _SECONDS_YEAR_2035) {
150 return _getYear(secondsSinceEpoch, timeZone.isUtc); 138 return _getYear(secondsSinceEpoch, timeZone.isUtc);
151 } 139 }
152 140
153 // Approximate the result. We don't take timeZone into account. 141 // Approximate the result. We don't take timeZone into account.
154 int approximateYear = _yearsFromSecondsSinceEpoch(secondsSinceEpoch); 142 int approximateYear = _yearsFromSecondsSinceEpoch(secondsSinceEpoch);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 return adjustedSeconds * Duration.MILLISECONDS_PER_SECOND + milliseconds; 394 return adjustedSeconds * Duration.MILLISECONDS_PER_SECOND + milliseconds;
407 } 395 }
408 396
409 // Natives 397 // Natives
410 static _brokenDownDateToSecondsSinceEpoch( 398 static _brokenDownDateToSecondsSinceEpoch(
411 int years, int month, int day, int hours, int minutes, int seconds, 399 int years, int month, int day, int hours, int minutes, int seconds,
412 bool isUtc) native "DateNatives_brokenDownToSecondsSinceEpoch"; 400 bool isUtc) native "DateNatives_brokenDownToSecondsSinceEpoch";
413 401
414 static int _getCurrentMs() native "DateNatives_currentTimeMillis"; 402 static int _getCurrentMs() native "DateNatives_currentTimeMillis";
415 403
416 static String _timeZoneName(int secondsSinceEpoch)
417 native "DateNatives_timeZoneName";
418
419 static int _timeZoneOffsetInSeconds(int secondsSinceEpoch)
420 native "DateNatives_timeZoneOffsetInSeconds";
421
422 // TODO(floitsch): it would be more efficient if we didn't call the native 404 // TODO(floitsch): it would be more efficient if we didn't call the native
423 // function for every member, but cached the broken-down date. 405 // function for every member, but cached the broken-down date.
424 static int _getYear(int secondsSinceEpoch, bool isUtc) 406 static int _getYear(int secondsSinceEpoch, bool isUtc)
425 native "DateNatives_getYear"; 407 native "DateNatives_getYear";
426 408
427 static int _getMonth(int secondsSinceEpoch, bool isUtc) 409 static int _getMonth(int secondsSinceEpoch, bool isUtc)
428 native "DateNatives_getMonth"; 410 native "DateNatives_getMonth";
429 411
430 static int _getDay(int secondsSinceEpoch, bool isUtc) 412 static int _getDay(int secondsSinceEpoch, bool isUtc)
431 native "DateNatives_getDay"; 413 native "DateNatives_getDay";
432 414
433 static int _getHours(int secondsSinceEpoch, bool isUtc) 415 static int _getHours(int secondsSinceEpoch, bool isUtc)
434 native "DateNatives_getHours"; 416 native "DateNatives_getHours";
435 417
436 static int _getMinutes(int secondsSinceEpoch, bool isUtc) 418 static int _getMinutes(int secondsSinceEpoch, bool isUtc)
437 native "DateNatives_getMinutes"; 419 native "DateNatives_getMinutes";
438 420
439 static int _getSeconds(int secondsSinceEpoch, bool isUtc) 421 static int _getSeconds(int secondsSinceEpoch, bool isUtc)
440 native "DateNatives_getSeconds"; 422 native "DateNatives_getSeconds";
441 } 423 }
OLDNEW
« no previous file with comments | « runtime/lib/date.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698