Skip to content

Part 1: Fix read/write/query LocalTime values (when time zone configured to be used) - #2708

Merged
rbygrave merged 3 commits into
ebean-orm:masterfrom
FOCONIS:fix-localtime
Jun 9, 2022
Merged

Part 1: Fix read/write/query LocalTime values (when time zone configured to be used)#2708
rbygrave merged 3 commits into
ebean-orm:masterfrom
FOCONIS:fix-localtime

Conversation

@nPraml

@nPraml nPraml commented May 31, 2022

Copy link
Copy Markdown
Contributor

Hello @rbygrave ,

we decided to split our big refactoring PR #2443 in smaller ones.
This PR would be the first which tests the write & read & query of the LocalTime values.

In the Javadoc I noticed how it can be tested in different java time zones with -Duser.timezone.

Can you take a look at this PR?

Kind regards
Noemi


Summary of this change

This changes how Time type is read (ResultSet) and bound (PreparedStatement) when there is a time zone set via DatabaseConfig.

Previously, Time was using the time zone method for Timestamp types rather than Date types and this changes it to use the method for Date types (which is actually null for everything apart from MySql).

Effectively no change for MySql.
Effectively for non-MySql, the Time types where incorrectly using the timezone if specified and this change means they no longer use that configured time zone.

nPraml added 3 commits May 31, 2022 10:47
(cherry picked from commit d2e21aa)
(cherry picked from commit 43e28c4)
@nPraml nPraml changed the title Fix read/write/query LocalTime values Part 1: Fix read/write/query LocalTime values May 31, 2022
@Override
public final void setTime(Time v) throws SQLException {
Calendar timeZone = dataTimeZone.getTimeZone();
Calendar timeZone = dataTimeZone.getTimeComponentTimeZone();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here...

@Override
public final Time getTime() throws SQLException {
Calendar cal = dataTimeZone.getTimeZone();
Calendar cal = dataTimeZone.getTimeComponentTimeZone();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and here is the fix. I suggested to @nPraml to rename that method.

* The test checks the write and read of LocalTime values. The database is in GMT time zone.
* In order to verify the test in different java time zones (where the application runs),
* use the <code>-Duser.timezone</code> as JVM argument,
* e.g. <code>-Duser.timezone="America/New_York"</code> or <code>-Duser.timezone="PST"</code>>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbygrave should we adjust the surefire.argline parameters or github workflow to run the tests in some strange time zones? We noticed that LocalDates may jump backwards in json roundtrips if timezone is negative and mode is set to millis. See also #2456 - this would prevent this

@rbygrave rbygrave added the bug label Jun 8, 2022
@rbygrave rbygrave added this to the 13.6.4 milestone Jun 8, 2022
@rbygrave
rbygrave merged commit c02ab73 into ebean-orm:master Jun 9, 2022
@rbygrave rbygrave changed the title Part 1: Fix read/write/query LocalTime values Part 1: Fix read/write/query LocalTime values (when time zone configured to be used) Jun 9, 2022
@rPraml
rPraml deleted the fix-localtime branch August 10, 2023 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants