JulianCalendar formatting + parsing difficulties
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Roy Ivy III (VIP)
I'm implementing a program dealing with astronomic phenomena and need to use
Julian Calendar dates (for dates before the Gregorian Calendar changeover). I
can use the JulianCalendar class to convert dates to and from the Julian
Calendar, but I'm unable to use any of the built-in DateTime formatting or
parsing routines because the JulianCalendar is not an "OptionalCalendar" for
any culture.

I've looked through the Framework documentation extensively, but see no way
around this "calendar lockout".

Does anyone know the basis for this limitation or how to work around it
without re-implementing the entire DateTime formatting and parsing engine for
this one calendar (which obviously seems like a completely wrong-headed
approach)?

Thanks, in advance.

- Roy Ivy
Reply to this message...
 
    
Robert Jordan
Roy Ivy III wrote:
[Original message clipped]

I'd use the GregorianCalender for parsing:

    DateTime g = DateTime.Parse(formatStr);

then convert the Gregorian date into Julian:

    DateTime j = new DateTime(g.Year, g.Month, g.Day,
        new JulianCalender());

and then convert it into Gregorian again:

    g = new DateTime(j.Ticks);

"g" is now normalized (I'd always work with normalized entities, btw.)

bye
Rob
Reply to this message...
 
    
Roy Ivy III
Thanks for the suggestion.

Unfortunately, I've already checked into this as a solution. It doesn't
quite work because the calendar rules are different between Julian and
Gregorian calendars, eg. "Feb 29, 1500" is a valid Julian date but _not_ a
valid Gregorian date. And the parser promptly throws a format exception for
the invalid date.

DateTime j = DateTime.Parse("feb 29, 1500"); // valid Julian date, throws
exception

As I said the conversion between Gregorian proleptic calendar (such as
DateTime) and Julian calendars is do-able with the tools, but I still haven't
found a way to parse/input or format/print the Julian dates without way too
much reimplementation of existing framework code.

Other ideas?

- Roy

"Robert Jordan" wrote:

[Original message clipped]

Reply to this message...
 
 
System.DateTime
System.Globalization.JulianCalendar




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com