meetuparchive / timeywimey

Converters between JodaTime and Java 8 time classes, plus some legacy java.util time classes utility, for Java 8 and Scala
MIT License
13 stars 6 forks source link

Exception when converting a January LocalDate to Joda DateTime #7

Open dlin303 opened 7 years ago

dlin303 commented 7 years ago

repro (ignore the deprecated warnings):

scala> val d2 = new Date(2017,0,1)
<console>:12: warning: constructor Date in class Date is deprecated: see corresponding Javadoc for more information.
       val d2 = new Date(2017,0,1)
                ^
d2: java.util.Date = Mon Jan 01 00:00:00 EST 3917

scala> import com.meetup.timeywimey.JodaConverterImplicits._
import com.meetup.timeywimey.JodaConverterImplicits._

scala> import com.meetup.timeywimey.LegacyConverterImplicits._
import com.meetup.timeywimey.LegacyConverterImplicits._

scala> d2.toLocalDate.plusDays(4).asJoda.toDate
java.time.DateTimeException: Invalid value for MonthOfYear (valid values 1 - 12): 0
  at java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311)
  at java.time.temporal.ChronoField.checkValidValue(ChronoField.java:703)
  at java.time.LocalDate.of(LocalDate.java:267)
  at com.meetup.timeywimey.LegacyConverters.toLocalDate(LegacyConverters.java:66)
  at com.meetup.timeywimey.LegacyConverterImplicits$DateToJava8.toLocalDate(LegacyConverterImplicits.scala:36)
  ... 43 elided

scala> 
mbbush commented 5 years ago

It looks like this was fixed in https://github.com/meetup/timeywimey/pull/6