[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:
Stephen Adams 2024-07-02 15:00:19 +00:00 committed by Commit Queue
parent d631c45b08
commit b3ce1647a8
3 changed files with 15 additions and 9 deletions

View file

@ -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(

View file

@ -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(

View file

@ -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