mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 16:37:43 +00:00
[js_runtime/js_dev_runtime] Handle fractional timezone offset
Change-Id: I7ed62ecd6fec06aba167fcf44df486674a36918a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373904 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com>
This commit is contained in:
parent
d631c45b08
commit
b3ce1647a8
|
@ -382,9 +382,13 @@ class Primitives {
|
|||
return "";
|
||||
}
|
||||
|
||||
static int getTimeZoneOffsetInMinutes(DateTime receiver) {
|
||||
// Note that JS and Dart disagree on the sign of the offset.
|
||||
return -JS<int>('!', r'#.getTimezoneOffset()', lazyAsJsDate(receiver));
|
||||
static int getTimeZoneOffsetInSeconds(DateTime receiver) {
|
||||
// Note that JavaScript's Date and and Dart's DateTime disagree on the sign
|
||||
// of the offset. Subtract to avoid -0.0. The offset in minutes could
|
||||
// contain 'seconds' as fractional minutes.
|
||||
num offsetInMinutes =
|
||||
JS('num', r'#.getTimezoneOffset()', lazyAsJsDate(receiver));
|
||||
return (0 - offsetInMinutes * 60).toInt();
|
||||
}
|
||||
|
||||
static int? valueFromDecomposedDate(
|
||||
|
|
|
@ -675,11 +675,13 @@ class Primitives {
|
|||
return '';
|
||||
}
|
||||
|
||||
static int getTimeZoneOffsetInMinutes(DateTime receiver) {
|
||||
// Note that JS and Dart disagree on the sign of the offset.
|
||||
// Subtract to avoid -0.0
|
||||
return 0 - JS('int', r'#.getTimezoneOffset()', lazyAsJsDate(receiver))
|
||||
as int;
|
||||
static int getTimeZoneOffsetInSeconds(DateTime receiver) {
|
||||
// Note that JavaScript's Date and and Dart's DateTime disagree on the sign
|
||||
// of the offset. Subtract to avoid -0.0. The offset in minutes could
|
||||
// contain 'seconds' as fractional minutes.
|
||||
num offsetInMinutes =
|
||||
JS('num', r'#.getTimezoneOffset()', lazyAsJsDate(receiver));
|
||||
return (0 - offsetInMinutes * 60).toInt();
|
||||
}
|
||||
|
||||
static int? valueFromDecomposedDate(
|
||||
|
|
|
@ -97,7 +97,7 @@ class DateTime {
|
|||
@patch
|
||||
Duration get timeZoneOffset {
|
||||
if (isUtc) return Duration.zero;
|
||||
return Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this));
|
||||
return Duration(seconds: Primitives.getTimeZoneOffsetInSeconds(this));
|
||||
}
|
||||
|
||||
@patch
|
||||
|
|
Loading…
Reference in a new issue