Creating new custom calendars

  • Thread starter Thread starter Arthur Parker
  • Start date Start date
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.
 
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();
}
 
Back
Top