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

Unified Diff: compiler/lib/implementation/date_implementation.js

Issue 9865025: Revert "Removes dartc reliance on its own libraries, now can be targeted at any implementation's li… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
« no previous file with comments | « compiler/lib/implementation/date_implementation.dart ('k') | compiler/lib/implementation/isolate.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/lib/implementation/date_implementation.js
diff --git a/compiler/lib/implementation/date_implementation.js b/compiler/lib/implementation/date_implementation.js
new file mode 100644
index 0000000000000000000000000000000000000000..ccd912d4d49ff7eff491ead60aa927f2ea8c5a5c
--- /dev/null
+++ b/compiler/lib/implementation/date_implementation.js
@@ -0,0 +1,80 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Dart core library.
+
+function date$validateValue(value) {
+ if (isNaN(value)) {
+ // TODO(floitsch): Use real exception object.
+ throw Error("Invalid Date");
+ }
+ return value;
+}
+
+function native_DateImplementation__valueFromDecomposed(
+ years, month, day, hours, minutes, seconds, milliseconds, isUtc) {
+ // JavaScript has 0-based months.
+ var jsMonth = month - 1;
+ var value = isUtc ?
+ Date.UTC(years, jsMonth, day,
+ hours, minutes, seconds, milliseconds) :
+ new Date(years, jsMonth, day,
+ hours, minutes, seconds, milliseconds).valueOf();
+ return date$validateValue(value);
+}
+
+function native_DateImplementation__valueFromString(str) {
+ return date$validateValue(Date.parse(str));
+}
+
+function native_DateImplementation__now() {
+ return new Date().valueOf();
+}
+
+function date$dateFrom(dartDate, value) {
+ // Lazily keep a JS Date stored in the dart object.
+ var date = dartDate.date;
+ if (!date) {
+ date = new Date(value);
+ dartDate.date = date;
+ }
+ return date;
+}
+
+function native_DateImplementation__getYear(value, isUtc) {
+ var date = date$dateFrom(this, value);
+ return isUtc ? date.getUTCFullYear() : date.getFullYear();
+}
+
+function native_DateImplementation__getMonth(value, isUtc) {
+ var date = date$dateFrom(this, value);
+ var jsMonth = isUtc ? date.getUTCMonth() : date.getMonth();
+ // JavaScript has 0-based months.
+ return jsMonth + 1;
+}
+
+function native_DateImplementation__getDay(value, isUtc) {
+ var date = date$dateFrom(this, value);
+ return isUtc ? date.getUTCDate() : date.getDate();
+}
+
+function native_DateImplementation__getHours(value, isUtc) {
+ var date = date$dateFrom(this, value);
+ return isUtc ? date.getUTCHours() : date.getHours();
+}
+
+function native_DateImplementation__getMinutes(value, isUtc) {
+ var date = date$dateFrom(this, value);
+ return isUtc ? date.getUTCMinutes() : date.getMinutes();
+}
+
+function native_DateImplementation__getSeconds(value, isUtc) {
+ var date = date$dateFrom(this, value);
+ return isUtc ? date.getUTCSeconds() : date.getSeconds();
+}
+
+function native_DateImplementation__getMilliseconds(value, isUtc) {
+ var date = date$dateFrom(this, value);
+ return isUtc ? date.getUTCMilliseconds() : date.getMilliseconds();
+}
« no previous file with comments | « compiler/lib/implementation/date_implementation.dart ('k') | compiler/lib/implementation/isolate.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698