Details
-
Improvement
-
Resolution: Fixed
-
Major
-
1.3.0-beta0
-
None
Description
CachingDateFormat creates a temporary OffsetDateTime from the given instant to apply the configured time zone (see here) before passing it to the DateTimeFormatter for rendering.
This temporary OffsetDateTime can be avoided by setting the ZoneId directly on the DateTimeFormatter when it is initialized. This is apparently what was foreseen in the constructor with the following lines:
public CachingDateFormatter(String pattern, ZoneId aZoneId) { dtf = DateTimeFormatter.ofPattern(pattern); ... dtf.withZone(this.zoneId); ... }
Unfortunately this won't work because "withZone()" returns a new formatter which is not assigned to the "dtf" instance variable...
To summarise:
(1) In the constructor do something like:
dtf = DateTimeFormatter.ofPattern(pattern).withZone(this.zoneId)
(2) In the "format()" method do something like:
Instant instant = Instant.ofEpochMilli(now);
String result = dtf.format(instant);
--> no need for an intermediate OffsetDateTime anymore
Attachments
Issue Links
- links to