JadiraOrg / jadira

Jadira Framework
Apache License 2.0
74 stars 44 forks source link

Incompatible handling of timezones in 7.0.0.CR1 #76

Open SchmidtThomas opened 6 years ago

SchmidtThomas commented 6 years ago

Upgrading from Version 6.0.1.GA to 7.0.0.RC1 we encountered the following issue:

We use the following JPA Mapping to persist a Joda Datetime field.

    @Columns(columns = {
            @Column(name = "valid_until"),
            @Column(name = "valid_until_timezone")
    })
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeAndZoneWithOffset")
    protected DateTime validUntil;

In all versions before 7.0.0.RC1 the Date "2018-11-05T23:59:59+01:00" would result in the following DB Entries.

valid_until valid_until_timezone
2018-11-05 22:59:59 Europe/Berlin{+01:00}

Time is saved in UTC, Timezone information is written to the second field. After reading the record from DB, the timezone gets reapplied and the Joda DateTime Object in Memory is set to "23:59:59".

After upgrading to 7.0.0.RC1 the same date gets persisted like this:

valid_until valid_until_timezone
2018-11-05 23:59:59 Europe/Berlin{+01:00}

The time is not saved in UTC anymore and is written as is. When reading from DB the Joda DateTime Object in Memory is set correctly to "23:59:59".

This works fine for all new records inserted by the new version of Jadira, but all old records are off by one hour (or better the zone offset).

Is this breaking change intended or did it happen by mistake?

regards

Thomas

nitehawk42 commented 4 years ago

This worked prior to this change: https://github.com/JadiraOrg/jadira/commit/b5c662923cd86f778b20897cdfe592140e21f133

Now jadira is incapable of converting dates during the repeated 1am hour during the daylight time changeover.

Looks like the problem for me is in TimestampColumnDateTimeMapper: The change from DateTime dateTime = new DateTime(value.getTime()); to: DateTime dateTime = DATETIME_FORMATTER.parseDateTime(value.toString()); makes it completely mess up dates in the daylight saving time repeated 1am hour. Converting it first to a string loses timezone information.