OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 part of js.wrapping; | |
6 | |
7 /// Adapter to handle a js date as a dart [DateTime]. | |
8 class JsDateToDateTimeAdapter extends TypedProxy implements DateTime { | |
9 | |
10 /// Like [JsDateToDateTimeAdapter.fromProxy] but with `null` handling for | |
11 /// [proxy]. | |
12 static JsDateToDateTimeAdapter cast(Proxy proxy) => | |
13 mapNotNull(proxy, (proxy) => | |
14 new JsDateToDateTimeAdapter.fromProxy(proxy)); | |
15 | |
16 /// Create a new adapter from a dart [dateTime]. | |
17 JsDateToDateTimeAdapter(DateTime dateTime) : | |
18 super(context.Date, [dateTime.millisecondsSinceEpoch]); | |
19 | |
20 /// Create a new adapter from a [proxy] of a Js Date object. | |
21 JsDateToDateTimeAdapter.fromProxy(Proxy proxy) : super.fromProxy(proxy); | |
22 | |
23 // from Comparable | |
24 @override int compareTo(DateTime other) => _asDateTime().compareTo(other); | |
25 | |
26 // from Date | |
27 @override bool operator ==(DateTime other) => _asDateTime() == other; | |
28 @override bool isBefore(DateTime other) => _asDateTime().isBefore(other); | |
29 @override bool isAfter(DateTime other) => _asDateTime().isAfter(other); | |
30 @override bool isAtSameMomentAs(DateTime other) => | |
31 _asDateTime().isAtSameMomentAs(other); | |
32 @override DateTime toLocal() => _asDateTime().toLocal(); | |
33 @override DateTime toUtc() => _asDateTime().toUtc(); | |
34 @override String get timeZoneName => _asDateTime().timeZoneName; | |
35 @override Duration get timeZoneOffset => _asDateTime().timeZoneOffset; | |
36 @override int get year => _asDateTime().year; | |
37 @override int get month => _asDateTime().month; | |
38 @override int get day => _asDateTime().day; | |
39 @override int get hour => _asDateTime().hour; | |
40 @override int get minute => _asDateTime().minute; | |
41 @override int get second => _asDateTime().second; | |
42 @override int get millisecond => _asDateTime().millisecond; | |
43 @override int get weekday => _asDateTime().weekday; | |
44 @override int get millisecondsSinceEpoch => | |
45 _asDateTime().millisecondsSinceEpoch; | |
46 @override bool get isUtc => _asDateTime().isUtc; | |
47 @override String toString() => _asDateTime().toString(); | |
48 @override DateTime add(Duration duration) => _asDateTime().add(duration); | |
49 @override DateTime subtract(Duration duration) => | |
50 _asDateTime().subtract(duration); | |
51 @override Duration difference(DateTime other) => | |
52 _asDateTime().difference(other); | |
53 | |
54 DateTime _asDateTime() => | |
55 new DateTime.fromMillisecondsSinceEpoch($unsafe.getTime()); | |
56 } | |
OLD | NEW |