Skip to content

StringColumnDateTimeMapper throws an Exception when Joda Datetime contains zone offset in hours, not Zone ID #88

@andrewko

Description

@andrewko

Hi,

I'm trying to use "org.jadira.usertype.dateandtime.joda.PersistentDateTimeAsUtcString" for saving Joda DateTime with a zone offset into a Postgre DB.

Serialization works, but deserialization throws an Exception:

java.lang.IllegalArgumentException: Invalid format: "2020-03-10T14:04:32.040_+05:00" is malformed at "+05:00"

The exception occurs only when the Joda Datetime is created with a zone with hours offset:

StringColumnDateTimeMapper mapper = new StringColumnDateTimeMapper();
DateTime nowWithOffset = DateTime.parse("2019-08-12T11:15:00+03:00");
String nowWithOffsetAsString = mapper.toNonNullValue(nowWithOffset);
mapper.fromNonNullValue(nowWithOffsetAsString);

When the Joda Datetime is created with a zone with a ZoneID, everything works fine:

StringColumnDateTimeMapper mapper = new StringColumnDateTimeMapper();
DateTime nowWithOffset = DateTime.now().withZone(DateTimeZone.forID("Europe/Moscow"));
String nowWithOffsetAsString = mapper.toNonNullValue(nowWithOffset);
mapper.fromNonNullValue(nowWithOffsetAsString);

A possible sollution could be creating the DateTimeFormatter with

appendTimeZoneOffset(null, true, 2, 2)

instead of

appendTimeZoneId()

We use org.jadira.usertype:usertype.core:6.0.1.GA

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions