On Thu, 16 Jul 2026 18:45:11 GMT, Justin Lu <[email protected]> wrote:

>> Sholto has updated the pull request incrementally with two additional 
>> commits since the last revision:
>> 
>>  - 8272194: remove autoCloseArguments from Date/Timestamp 
>> LocalDate/LocalDateTime conversion tests
>>  - 8272194: remove outdated comment in Timestamp LocalDateTime conversion
>
> src/java.sql/share/classes/java/sql/Date.java line 287:
> 
>> 285:      * providing a faster code path for almost 1970 years.
>> 286:      */
>> 287:     private static final long TWO_AD_AT_UTC_EPOCH_MILLIS = 
>> -62104233600000L;
> 
> We can make this package-private and have `Timestamp` use it as well to 
> reduce some duplication.

I've left this private as Timestamp no longer needs this constant as it is 
directly using the new `Date.toProlepticYear`.

> src/java.sql/share/classes/java/sql/Date.java line 324:
> 
>> 322:         // 0002-01-01 are AD, we can use a much faster local date 
>> derivation
>> 323:         // for these dates.
>> 324:         if (getTime() >= TWO_AD_AT_UTC_EPOCH_MILLIS) {
> 
> We can pull out the shared logic here and in `Timestamp` and create a static 
> package-private helper in `java.sql.Date`. 
> 
> Something like 
> 
> 
> static int toProlepticYear(long millis, int year) {
>       if slow path
>           set calendar using setTimeInMillis
>           if calendar is in BC
>               adjust year
>       return year;
> 
>   }
> 
> 
> The helper can call `GregorianCalendar.setTimeInMillis(...)` instead of 
> `GregorianCalendar.setTime(...)`. That lets us pass its millisecond value via 
> `getTime()` rather than having to pass `this` as a `java.util.Date` to the 
> helper method. I also think within the helper, you can inverse the `getTime() 
> >= TWO_AD_AT_UTC_EPOCH_MILLIS` conditional to simplify the logic some more.
> 
> After that, `toLocalDate` need only look something like,
> 
> 
> return LocalDate.of(
>               toProlepticYear(getTime(), getYear() + 1900),
>               getMonth() + 1,
>               getDate());

Yup great idea. I have updated this as suggested.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31808#discussion_r3602861569
PR Review Comment: https://git.openjdk.org/jdk/pull/31808#discussion_r3602866339

Reply via email to