Year is incrementing for the last dates of december for some random years.
muralikrishna-kolapalli opened this issue · 4 comments
The year is incrementing when the simple data format is being changed.
//CODE SNIPPET:
String sdate = "2021-12-29 13:45:00";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
Date date = dateFormat.parse(sdate);
System.out.println(date);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-YYYY HH:mm:ss");
System.out.println(simpleDateFormat.format(date));
OUTPUT:
Wed Dec 29 13:45:00 IST 2021
29-Dec-2022 13:45:00
Another date where the issue is found.
String sdate = "2024-12-29 13:45:00";
Sun Dec 29 13:45:00 IST 2024
29-Dec-2025 13:45:00
@muralikrishna-kolapalli thank you for reporting this! May we ask you for a PR with a test for the issue described above? 😄 Thanks!
This is probably due to the fact that you're using YYYY instead of yyyy.
YYYY is week based year
yyyy is era based year.
If the week straddles the next year YYYY will give you the current year +1/-1.
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
Also, SimpleDateFormat is not part of the cron-utils library as far as I know. It's part of the core Java library.
@lodenrogue thank you for looking into this and providing an answer. @muralikrishna-kolapalli we are closing the issue given the answer above. Thanks! 😄