Discordian date: Difference between revisions
Content added Content deleted
(Created page with '{{task}}Convert a given date from the Gregorian calendar to the Discordian calendar. '''See Also''' * Discordian calendar (wiki) =={{header|Python}}=…') |
(Added missing </lang>) |
||
Line 29: | Line 29: | ||
dday = day_of_year - (season * 73) |
dday = day_of_year - (season * 73) |
||
return "%s %d, YOLD %d" % (DISCORDIAN_SEASONS[season], (dday + 1), (year + 1166)) |
return "%s %d, YOLD %d" % (DISCORDIAN_SEASONS[season], (dday + 1), (year + 1166)) |
||
</lang> |
Revision as of 19:35, 20 July 2010
Discordian date
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Convert a given date from the Gregorian calendar to the Discordian calendar.
See Also
Python
<lang python>import datetime
DISCORDIAN_SEASONS = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]
def ddate(year, month, day):
today = datetime.date(year, month, day) is_leap_year = True try: leap_day = datetime.date(year, 2, 29) if leap_day == today: return "St. Tib's Day, YOLD " + (year + 1166) except ValueError: is_leap_year = False day_of_year = (today - datetime.date(year, 1, 1)).days if is_leap_year and day_of_year >= 60: day_of_year -= 1 # Compensate for St. Tib's Day season = day_of_year // 73 dday = day_of_year - (season * 73) return "%s %d, YOLD %d" % (DISCORDIAN_SEASONS[season], (dday + 1), (year + 1166))
</lang>