[corelib] Update date_time_far_away_dates_test

Bug: #37442
Change-Id: I0c04136bc4fdbf2908154a608f09311c5c511da5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366720
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
This commit is contained in:
Stephen Adams 2024-05-16 14:19:18 +00:00 committed by Commit Queue
parent eb413f21fe
commit 762ca98456

View file

@ -10,11 +10,11 @@ import "package:expect/expect.dart";
// are 'web' integers.
bool get supportsMicroseconds =>
new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1;
DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1;
void testFarAwayDates() {
DateTime dt =
new DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true);
DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true);
Expect.equals(33658, dt.year);
Expect.equals(9, dt.month);
Expect.equals(27, dt.day);
@ -23,7 +23,7 @@ void testFarAwayDates() {
Expect.equals(40, dt.second);
Expect.equals(1, dt.millisecond);
Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-1000000000000001, isUtc: true);
dt = DateTime.fromMillisecondsSinceEpoch(-1000000000000001, isUtc: true);
Expect.equals(-29719, dt.year);
Expect.equals(4, dt.month);
Expect.equals(5, dt.day);
@ -32,8 +32,9 @@ void testFarAwayDates() {
Expect.equals(19, dt.second);
Expect.equals(999, dt.millisecond);
Expect.equals(0, dt.microsecond);
// Same with local zone.
dt = new DateTime.fromMillisecondsSinceEpoch(1000000000000001);
dt = DateTime.fromMillisecondsSinceEpoch(1000000000000001);
Expect.equals(33658, dt.year);
Expect.equals(9, dt.month);
Expect.equals(true, dt.day == 27 || dt.day == 26);
@ -44,21 +45,32 @@ void testFarAwayDates() {
Expect.equals(40, dt.second);
Expect.equals(1, dt.millisecond);
Expect.equals(0, dt.microsecond);
dt = new DateTime.fromMillisecondsSinceEpoch(-1000000000000001);
dt = DateTime.fromMillisecondsSinceEpoch(-1000000000000001);
Expect.equals(-29719, dt.year);
Expect.equals(4, dt.month);
Expect.equals(true, 5 == dt.day || 6 == dt.day);
// Not much we can test for local hour.
Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
// Timezones can have offsets down to 15 minute.
Expect.equals(true, dt.minute % 15 == 13);
Expect.equals(19, dt.second);
// Not much we can test for the minute and second.
//
// Historical timezones can have arbitrary offets. For example, "Pacific
// Standard Time" in the United States is represented by Los Angeles. Prior to
// the adoption of "Railway Time" in the United States at noon on 18 November
// 1883, the local time in Los Angeles had an offset of a few minutes from the
// standard time.
//
// -2717640000001 Nov 18 1883 12:07:01 GMT-0752 (Pacific Standard Time)
// -2717640000000 Nov 18 1883 12:00:00 GMT-0800 (Pacific Standard Time)
Expect.equals(true, 0 <= dt.minute && dt.minute < 60);
Expect.equals(true, 0 <= dt.second && dt.second < 60);
Expect.equals(999, dt.millisecond);
Expect.equals(0, dt.microsecond);
if (!supportsMicroseconds) return;
dt =
new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001, isUtc: true);
// `1000000000000000128` is a valid web number, allowing this test to be
// compiled by the web compilers.
dt = DateTime.fromMicrosecondsSinceEpoch(1000000000000000128, isUtc: true);
Expect.equals(33658, dt.year);
Expect.equals(9, dt.month);
Expect.equals(27, dt.day);
@ -66,9 +78,8 @@ void testFarAwayDates() {
Expect.equals(46, dt.minute);
Expect.equals(40, dt.second);
Expect.equals(0, dt.millisecond);
Expect.equals(1, dt.microsecond);
dt = new DateTime.fromMicrosecondsSinceEpoch(-1000000000000000001,
isUtc: true);
Expect.equals(128, dt.microsecond);
dt = DateTime.fromMicrosecondsSinceEpoch(-1000000000000000128, isUtc: true);
Expect.equals(-29719, dt.year);
Expect.equals(4, dt.month);
Expect.equals(5, dt.day);
@ -76,9 +87,10 @@ void testFarAwayDates() {
Expect.equals(13, dt.minute);
Expect.equals(19, dt.second);
Expect.equals(999, dt.millisecond);
Expect.equals(999, dt.microsecond);
Expect.equals(1000 - 128, dt.microsecond);
// Same with local zone.
dt = new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001);
dt = DateTime.fromMicrosecondsSinceEpoch(1000000000000000128);
Expect.equals(33658, dt.year);
Expect.equals(9, dt.month);
Expect.equals(true, dt.day == 27 || dt.day == 26);
@ -88,18 +100,18 @@ void testFarAwayDates() {
Expect.equals(true, dt.minute % 15 == 46 % 15);
Expect.equals(40, dt.second);
Expect.equals(0, dt.millisecond);
Expect.equals(1, dt.microsecond);
dt = new DateTime.fromMicrosecondsSinceEpoch(-1000000000000000001);
Expect.equals(128, dt.microsecond);
dt = DateTime.fromMicrosecondsSinceEpoch(-1000000000000000128);
Expect.equals(-29719, dt.year);
Expect.equals(4, dt.month);
Expect.equals(true, 5 == dt.day || 6 == dt.day);
// Not much we can test for local hour.
Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
// Timezones can have offsets down to 15 minute.
Expect.equals(true, dt.minute % 15 == 13);
Expect.equals(19, dt.second);
// Not much we can test for the minute and second.
Expect.equals(true, 0 <= dt.minute && dt.minute < 60);
Expect.equals(true, 0 <= dt.second && dt.second < 60);
Expect.equals(999, dt.millisecond);
Expect.equals(999, dt.microsecond);
Expect.equals(1000 - 128, dt.microsecond);
}
void main() {