Display bug in LocalDate
See original GitHub issueI have found an interesting bug in how LocalDate
is displayed/ToString
ed
To showcase it, take the following code:
var lateDate = new LocalDate(9999, 01, 01);
var minimumYear = minimumDate.Year;
var longDateInterval = new DateInterval(minimumDate, new LocalDate(2021, 09, 01));
var allDays = longDateInterval.ToList();
var firstYear = longDateInterval.First().Year;
When inspecting the variables, the below is what is shown. minimumYear
and firstYear
are both correctly -9998, yet according to what the debugger displays, LocalDate.MinIsoValue
is 9999-01-01 and the next days appear to be the following days, until you appear to go from 9999-12-31 to 9998-01-01.
The day of the week, however, does seem to be correct, given that it is different for LocalDate.MinIsoValue
and new LocalDate(9999, 01, 01)
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Bug in java LocalDate for Date Format [duplicate]
Your format is incorect if you are expecting 2020 for both dates. Change it to yyyyMMdd. y (lowercase) is year; Y (uppercase) is ......
Read more >DateTimeFormatter does not parse LocalDate ...
A DESCRIPTION OF THE PROBLEM : Using the following code on JDK 11.8/11.9 - LocalDate dt = LocalDate.now(); String dtStr= dt.format(DateTimeFormatter.
Read more >LocalDate (Java Platform SE 8 )
LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day. Other date fields, such as day-of-year, day-of-week and ...
Read more >LocalDate (Java SE 17 & JDK 17)
LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day. Other date fields, such as day-of-year, day-of-week and ...
Read more >Mysql connector for java 8.0.20 shifts back LocalDate ...
Description: Hi, I have run into following issue after updating spring boot from 2.2.6 to 2.2.7: When I save LocalDate with spring data...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually, I take that back about not having to distinguish between year-of-era and absolute year: the Japanese calendar supports multiple eras, and “yyyy” returns the year-of-era. Here’s an example:
The result is 03-06-09, because we’re in year 3 of the current era.
So while the result may be unexpected, I believe NodaTime is actually behaving correctly here. I would recommend users who want to deal with BCE dates should probably use
LocalDatePattern.Iso
, or a custom date/time format that usesuuuu
instead ofyyyy
.Closing, as I believe there’s nothing here to change in Noda Time.