Implementing a non-terrestrial calendar

C#.NetDatetimeCalendar

C# Problem Overview


As I was looking into solutions for another question, I found myself wondering whether it was possible to use .NET's Calendar class to implement a calendar that wasn't based on Earthly conventions.

For instance, Mars' day is about 2.7% longer than a day here on Earth: > A convention used by spacecraft lander projects to date has been to keep track of local solar time using a 24 hour "Mars clock" on which the hours, minutes and seconds are 2.7% longer than their standard (Earth) durations.

Is there any good way to implement a MarsCalendar such that the length of a second is different from the standard GregorianCalendar, and thus be able to use DateTime objects based on it for all the standard AddDays(), AddHours(), etc. functions? (Note: Ideally, a solution - if one exists - would be applicable to any form of planetary object for which it is possible to define both "1 day" and "1 year" of consistent lengths. Mars makes for a great example, though)

C# Solutions


Solution 1 - C#

There are several non-Gregorian calendar classes derived from System.Globalization.Calendar within the Globalization namespace (i.e. JapaneseCalendar). You should be able to implement your own. I'd whip up a sample, but there are 16 abstract methods in the Calendar class...

You might even be able to simply derive your class from GregorianCalendar and just override the GetMilliseconds(DateTime) method, returning the base's return value multiplied by 1.027d.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBobsonView Question on Stackoverflow
Solution 1 - C#Michael HoffmannView Answer on Stackoverflow