mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:07:11 +00:00
[dart2wasm] Implement unimplemented methods in DateTime
.
Change-Id: Ia84d2e65ab6207fc70f6f8380c18ba3b89f7400f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/251590 Reviewed-by: Aske Simon Christensen <askesc@google.com> Commit-Queue: Joshua Litt <joshualitt@google.com>
This commit is contained in:
parent
fe78a23e9a
commit
63a9057f12
2 changed files with 25 additions and 7 deletions
|
@ -163,6 +163,19 @@ var dart2wasm = {
|
|||
var factoryFunction = constructor.bind.apply(constructor, [null, ...args]);
|
||||
return new factoryFunction();
|
||||
},
|
||||
getTimeZoneNameForSeconds: function(secondsSinceEpoch) {
|
||||
var date = new Date(secondsSinceEpoch * 1000);
|
||||
var match = /\((.*)\)/.exec(date.toString());
|
||||
if (match == null) {
|
||||
// This should never happen on any recent browser.
|
||||
return '';
|
||||
}
|
||||
return stringToDartString(match[1]);
|
||||
|
||||
},
|
||||
getTimeZoneOffsetInSeconds: function(secondsSinceEpoch) {
|
||||
return new Date(secondsSinceEpoch * 1000).getTimezoneOffset() * 60;
|
||||
},
|
||||
};
|
||||
|
||||
function instantiate(filename, imports) {
|
||||
|
|
|
@ -17,16 +17,19 @@ external double _jsDateNow();
|
|||
class DateTime {
|
||||
// Natives.
|
||||
// The natives have been moved up here to work around Issue 10401.
|
||||
@pragma("vm:external-name", "DateTime_currentTimeMicros")
|
||||
static int _getCurrentMicros() =>
|
||||
(_jsDateNow() * Duration.microsecondsPerMillisecond).toInt();
|
||||
|
||||
@pragma("vm:external-name", "DateTime_timeZoneName")
|
||||
external static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch);
|
||||
@pragma("wasm:import", "dart2wasm.getTimeZoneNameForSeconds")
|
||||
external static String _timeZoneNameForClampedSecondsRaw(
|
||||
double secondsSinceEpoch);
|
||||
|
||||
@pragma("vm:external-name", "DateTime_timeZoneOffsetInSeconds")
|
||||
external static int _timeZoneOffsetInSecondsForClampedSeconds(
|
||||
int secondsSinceEpoch);
|
||||
static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) =>
|
||||
_timeZoneNameForClampedSecondsRaw(secondsSinceEpoch.toDouble());
|
||||
|
||||
@pragma("wasm:import", "dart2wasm.getTimeZoneOffsetInSeconds")
|
||||
external static double _timeZoneOffsetInSecondsForClampedSeconds(
|
||||
double secondsSinceEpoch);
|
||||
|
||||
static const _MICROSECOND_INDEX = 0;
|
||||
static const _MILLISECOND_INDEX = 1;
|
||||
|
@ -424,7 +427,9 @@ class DateTime {
|
|||
|
||||
static int _timeZoneOffsetInSeconds(int microsecondsSinceEpoch) {
|
||||
int equivalentSeconds = _equivalentSeconds(microsecondsSinceEpoch);
|
||||
return _timeZoneOffsetInSecondsForClampedSeconds(equivalentSeconds);
|
||||
return _timeZoneOffsetInSecondsForClampedSeconds(
|
||||
equivalentSeconds.toDouble())
|
||||
.toInt();
|
||||
}
|
||||
|
||||
static String _timeZoneName(int microsecondsSinceEpoch) {
|
||||
|
|
Loading…
Reference in a new issue