Skip to content

Commit

Permalink
Update Jsr310Converters.java
Browse files Browse the repository at this point in the history
Addressing the inconsistencies in date storage related to MongoDB's default timestamp with timezone approach. The current method often leads to discrepancies in date interpretation across various timezones and services. This commit introduces a revised storage strategy that prioritizes storing dates as LocalDate to ensure consistent interpretation irrespective of timezone differences. By avoiding implicit conversions to timestamps, it mitigates issues where the date representation may differ based on the timezone of the reading service or aggregation functions. This change aims to ensure uniformity in date representation, particularly critical for scenarios like invoicing where the date's day component should be preserved consistently across systems.
  • Loading branch information
hamzahanafi11 authored Nov 16, 2023
1 parent 7fab81b commit cc57b81
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public enum DateToLocalDateConverter implements Converter<Date, LocalDate> {
@NonNull
@Override
public LocalDate convert(Date source) {
return ofInstant(ofEpochMilli(source.getTime()), systemDefault()).toLocalDate();
return source.toInstant().atZone(ZoneOffset.UTC).toLocalDate();
}
}

Expand All @@ -138,7 +138,7 @@ public enum LocalDateToDateConverter implements Converter<LocalDate, Date> {
@NonNull
@Override
public Date convert(LocalDate source) {
return Date.from(source.atStartOfDay(systemDefault()).toInstant());
return new Date(source.atStartOfDay().atZone(ZoneOffset.UTC).toInstant().toEpochMilli());
}
}

Expand Down

0 comments on commit cc57b81

Please sign in to comment.