I'm trying to simply add TimeZone information back into a LocalDate before performing some more calculations. The LocalDate came from using the ObjectLab LocalDateCalculator to add days to an existing DateTime but the method needs to return a modified ReadableInstant to form an Interval which I can then inspect.
The code I'm trying amounts to a conversion of Joda LocalDate to Joda DateTime:
LocalDate contextLocalBusinessDate = calculator.getCurrentBusinessDate();
DateTime businessDateAsInContextLocation = new DateTime(contextLocalBusinessDate, contextTimeZone);
The error I get is from Joda's conversion system:
java.lang.IllegalArgumentException: No instant converter found for type: org.joda.time.LocalDate
at org.joda.time.convert.ConverterManager.getInstantConverter(ConverterManager.java:165)
at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:147)
at org.joda.time.DateTime.<init>(DateTime.java:192)
I'm looking for a fix to this problem, or a workaround that results in an accurate Interval with full timezone information.
There are various methods on LocalDate
for this, including:
LocalDate::toDateTimeAtCurrentTime()
LocalDate::toDateTimeAtStartOfDay()
LocalDate::toDateTime( LocalTime )
LocalDate::toDateTime( LocalTime , DateTimeZone )
You have to be explicit about what you want the time component to be in the resulting DateTime
object, which is why DateTime
's general-conversion constructor can't do it.