0

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.

eraelpeha
  • 409
  • 5
  • 15

2 Answers2

1

We had exactly the same problem.

As Number(BirtDateTime.diffDay(BirtDateTime.today(), BirtDateTime.addDay(BirtDateTime.today(), -10))) was correct (-10) the problem was elsewhere.

Using 'yyyy' instead of 'YYYY' fixed the problem. See yyyy vs YYYY.

SergeIO
  • 11
  • 2
1

YYYY specifies using the week year. Use should instead using yyyy to simply use the year on the actual day.

As you can see in the BirtDateTime.java source that under the hood the SimpleDateFormat is used for the formatting. The Javadoc of SimpleDateFormat says

Letter | Date or Time Component

y | Year

Y | Week year

Community
  • 1
  • 1
brass monkey
  • 5,841
  • 10
  • 36
  • 61