Does NodaTime support AYN (per ISO 8601)?

44 views
Skip to first unread message

Roke Beedell (RokeJulianLockhart)

unread,
Nov 11, 2024, 12:01:20 AM11/11/24
to Noda Time
As I originally asked more verbosely at github.com/dotnet/runtime/discussions/109687 (please read it), does NodaTime support ISO 8601-1:2019+A1:2022's astronomical year numbering?

I ask because I want to be able to utilize it to parse negative years in dates. To my knowledge, ca-iso8601 backdates the Gregorian calendar for this purpose.

This is my first time participating in Google Groups, so please understand if I utilize it incorrectly. Being <30, mailing lists are somewhat foreign to me.

Jon Skeet

unread,
Nov 11, 2024, 12:25:12 AM11/11/24
to Noda Time
I'll need to double check, but I'm pretty sure we support negative "absolute" years out of the box, e.g. -0002-06-19T00:00:00 meaning "June 19th, 3 BCE (proleptic Gregorian)". But I don't think we support a leading + at the moment.

Please file an issue on GitHub for that l, with as many details as I may have missed.

--

---
You received this message because you are subscribed to the Google Groups "Noda Time" group.
To unsubscribe from this group and stop receiving emails from it, send an email to noda-time+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/noda-time/b7266f14-b04f-4f47-9234-7a1203d8bc42n%40googlegroups.com.

Jon Skeet

unread,
Nov 11, 2024, 2:13:34 AM11/11/24
to Noda Time
Right, I've just confirmed what I thought: we don't support "+", but parsing both "-0002-06-19" and "0002-06-19" work as expected. For the moment, if you need "+" support, I'd suggest adding a small amount of code to your application code to remove a leading "+" when parsing and add one when formatting - it's ugly, but hopefully just about good enough until Noda Time supports the "+" fully.

Note that the range of years supported by Noda Time is 9999 BCE (-9998 AN) to 9999 CE (+9999 AN).

Jon

using NodaTime.Text;

Test("-0002-06-19");
Test("0002-06-19");
// Fails
Test("+0002-06-19");

void Test(string text)
{
    var pattern = LocalDatePattern.Iso;
    var date = pattern.Parse(text).Value;
    Console.WriteLine($"{text} => {date} => {pattern.Format(date)}");
}

Roke Beedell (RokeJulianLockhart)

unread,
Nov 13, 2024, 9:17:31 AM11/13/24
to Noda Time
Reply all
Reply to author
Forward
0 new messages