Creating new custom calendars

A

Arthur Parker

I have been looking for information on creating new custom calendars; not the
control, but the class that manages dates and date calculations. The only
thing I've been able to find in any of the MS documentation or newsgroups is
that you _can_ derive custom calendars from System.Globablization.Calendar,
but not a word on what you would need to do to accomplish that. Has anyone
ever done or seen any custom calendar implementations? I'd appreciate any
help or pointers on this.
 
F

Family Tree Mike

You may consider looking at extending one of the custom calendars rather
than the abstract Calendar. You then don't need to override so many
methods. For example this class extends GregorianCalendar, making years
relative to 1981.

class ModernCalendar : GregorianCalendar
{
public override int GetYear(DateTime time)
{
return time.Year - 1981;
}
}

Then you could call it via:

static void Main(string[] args)
{
ModernCalendar mc = new ModernCalendar();
GregorianCalendar gc = new GregorianCalendar();

DateTime gcday = new DateTime(2008, 11, 19, gc);
Console.Out.WriteLine(gcday);
DateTime modday = new DateTime(
mc.GetYear(gcday), mc.GetMonth(gcday), mc.GetDayOfMonth(gcday), mc);
Console.Out.WriteLine(modday.ToString());

Console.Out.WriteLine("OK");
Console.In.ReadLine();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top