8212895: ChronoField.INSTANT_SECONDS's range doesn't match the range of Instant

Reviewed-by: rriggs, naoto
This commit is contained in:
Jaikiran Pai 2024-04-17 10:59:12 +00:00
parent 9445047d05
commit 89129e3f67
2 changed files with 17 additions and 3 deletions
src/java.base/share/classes/java/time/temporal
test/jdk/java/time/tck/java/time/temporal

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -586,8 +586,11 @@ public enum ChronoField implements TemporalField {
* <p>
* This field is strictly defined to have the same meaning in all calendar systems.
* This is necessary to ensure interoperation between calendars.
* <p>
* Range of InstantSeconds is between {@link Instant#MIN} and {@link Instant#MAX}
* {@linkplain Instant#getEpochSecond() epoch second}, both inclusive.
*/
INSTANT_SECONDS("InstantSeconds", SECONDS, FOREVER, ValueRange.of(Long.MIN_VALUE, Long.MAX_VALUE)),
INSTANT_SECONDS("InstantSeconds", SECONDS, FOREVER, ValueRange.of(Instant.MIN.getEpochSecond(), Instant.MAX.getEpochSecond())),
/**
* The offset from UTC/Greenwich.
* <p>

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -97,6 +97,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -263,4 +264,14 @@ public class TCKChronoField {
assertEquals(ChronoField.valueOf(field.name()), field);
}
}
// verify the minimum and maximum values of ChronoField.INSTANT_SECONDS
// matches the minimum and maximum supported epoch second by Instant.
@Test
public void testMinMaxInstantSeconds() {
assertEquals(ChronoField.INSTANT_SECONDS.range().getMinimum(),
Instant.MIN.getLong(ChronoField.INSTANT_SECONDS));
assertEquals(ChronoField.INSTANT_SECONDS.range().getMaximum(),
Instant.MAX.getLong(ChronoField.INSTANT_SECONDS));
}
}