I have a birt report with two parameters, startDate and endDate (which are both text-fields / strings). They are prefilled with yesterday and yesterday + ' 23:59:59', so the format looks like 2019-12-20
and 2019-12-20 23:59:59
.
The function for this is Formatter.format(BirtDateTime.addDay(BirtDateTime.today(), -1), "YYYY-MM-dd")
and Formatter.format(BirtDateTime.addDay(BirtDateTime.today(), -1), "YYYY-MM-dd 23:59:59")
respectively.
This works fine until the end of this year. The generated dates look like this:
| BirtDateTime.today() | Generated date |
| -------------------- | -------------- |
| 2019-12-29 | 2019-12-28 |
| 2019-12-30 | 2020-12-29 |
| 2019-12-31 | 2020-12-30 |
| 2020-01-01 | 2020-12-31 |
| 2019-01-02 | 2020-01-01 |
As you can see, from 2019-12-30 until 2020-01-01 the generated dates from the addDay function have the wrong year. My first guess is that it has to do something with the calendar weeks (because a new week starts on 2019-12-30, but on the 2nd of January everything is fine again...
I can reproduce this if I replace BirtDateTime.today() with a fixed string "2019-12-31"
or similar. If I use another year, let's say 2018, only the 2019-01-01 will return a wrong date (2019-31-12 instead of 2018-12-31).
Is there something I haven't seen or came anybody across this behaviour? If it matters, I'm using birt 2019-03.