question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Display bug in LocalDate

See original GitHub issue

I have found an interesting bug in how LocalDate is displayed/ToStringed

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). image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jskeetcommented, Jun 9, 2021

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:

using System;
using System.Globalization;

class Program
{
    static void Main()
    {
        var date = new DateTime(2021, 6, 9);
        var culture = CultureInfo.CreateSpecificCulture("jp-JP");
        var calendar = new JapaneseCalendar();
        culture.DateTimeFormat.Calendar = calendar;
        Console.WriteLine(date.ToString("yyyy-MM-dd", culture));
    }
}

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 uses uuuu instead of yyyy.

0reactions
jskeetcommented, Jul 4, 2021

Closing, as I believe there’s nothing here to change in Noda Time.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found