Skip to content

LocalDate properties depend on the machine's timezone setting [DATAMONGO-2627] #3482

Closed
@spring-projects-issues

Description

@spring-projects-issues

sothawo opened DATAMONGO-2627 and commented

When storing an entity with a LocalDate property in a Spring Data MongoDB Repository, on reading the entity the property's value depends on the system timezone setting.

LocalDates have no notion of a timezone, they are just a combination of year/month/day , so the value should not change.

I have linked a GitHub repo with a small demo application, in short:

Person margaret = new Person();
margaret.setId("1");
margaret.setName("Margaret Hamilton");
margaret.setBirthday(LocalDate.of(1936, 8, 17));
LOG.info("This is person 1: " + margaret + '\n');

LOG.info("Storing person 1 on a machine in Berlin\n");
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
repository.save(margaret);

LOG.info("Retrieving person 1 on a machine in Los Angeles");
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
Person person1 = repository.findById("1").orElseThrow();
LOG.info("This is person 1: " + person1);

This stores a person with her birthday in the database with one timezone setting and reads the entity with a different timezone setting. The birthday is then one day off.

2020-09-16 19:52:03.458  INFO 23828 --- : This is person 1: Person{id='1', name='Margaret Hamilton', birthday=1936-08-17}
2020-09-16 19:52:03.458  INFO 23828 --- : Storing person 1 on a machine in Berlin
2020-09-16 19:52:03.696  INFO 23828 --- : Retrieving person 1 on a machine in Los Angeles
2020-09-16 19:52:03.719  INFO 23828 --- : This is person 1: Person{id='1', name='Margaret Hamilton', birthday=1936-08-16}

Affects: 3.0.4 (Neumann SR4)

Reference URL: https://github.com/sothawo/spring-data-mongodb-localdate

Issue Links:

  • DATAMONGO-1026 Joda, JSR-310 and ThreeTenBp converters are timezone-sensitive

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions