JulianCalendar formatting + parsing difficulties

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Roy said:
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)?

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
 
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
 
Back
Top