.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification