JakeWharton / ThreeTenABP

An adaptation of the JSR-310 backport for Android.
Apache License 2.0
3.55k stars 133 forks source link

minusDays() returns wrong date for specific use case #120

Closed deepakmn86 closed 4 years ago

deepakmn86 commented 4 years ago

minusDays() returns wrong date for below specific use case

Version: v1.2.1

Code to reproduce:

val date = LocalDate.of(2020, 1, 13).minusMonths(1)
val lastDate = date.withDayOfMonth(date.lengthOfMonth())
val dateStr = DateTimeFormatter.ofPattern("MMMM dd YYYY").format(lastDate)

Expected: dateStr must be "December 31 2019"

Actual: dateStr is "December 31 2020"

deepakmn86 commented 4 years ago

Weird, It seems to work fine if I use ""MMMM dd yyyy""instead of "MMMM dd YYYY". Closing the issue.

dlew commented 4 years ago

This video explains what's going on: https://www.youtube.com/watch?v=D3jxx8Yyw1c