Discordian date: Difference between revisions
Content added Content deleted
(illustrate issue mentioned on talk page) |
(J: bug fix) |
||
Line 6: | Line 6: | ||
=={{header|J}}== |
=={{header|J}}== |
||
<lang j> |
<lang j>disc=: +"1&1166 0 0 </lang> |
||
Example use: |
Example use: |
||
<lang> |
<lang> disc 2012 2 29 |
||
37182 29</lang> |
|||
see [[Talk:Discordian_date|talk page]]. |
see [[Talk:Discordian_date|talk page]]. |
Revision as of 14:55, 21 July 2010
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
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
J
<lang j>disc=: +"1&1166 0 0 </lang>
Example use:
<lang> disc 2012 2 29 37182 29</lang>
see talk page.
Python
<lang python>import datetime, calendar
DISCORDIAN_SEASONS = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]
def ddate(year, month, day):
today = datetime.date(year, month, day) is_leap_year = calendar.isleap(year) if is_leap_year and month == 2 and day == 29: return "St. Tib's Day, YOLD " + (year + 1166) day_of_year = today.timetuple().tm_yday - 1 if is_leap_year and day_of_year >= 60: day_of_year -= 1 # Compensate for St. Tib's Day season, dday = divmod(day_of_year, 73) return "%s %d, YOLD %d" % (DISCORDIAN_SEASONS[season], dday + 1, year + 1166)
</lang>