Discordian date: Difference between revisions

→‎Tcl: Added implementation
(Added PicoLisp)
(→‎Tcl: Added implementation)
Line 52:
return "%s %d, YOLD %d" % (DISCORDIAN_SEASONS[season], dday + 1, year + 1166)
</lang>
 
=={{header|Tcl}}==
<lang tcl>package require Tcl 8.5
proc disdate {year month day} {
set now [clock scan [format %02d-%02d-%04d $day $month $year] -format %d-%m-%Y]
scan [clock format $now -format %j] %d doy
if {!($year%4) && !(!($year%100) && ($year%400))} {
if {$doy == 60} {
return "St. Tib's Day, [expr {$year + 1166}] YOLD"
} elseif {$doy > 60} {
incr doy -1
}
}
incr doy -1; # Allow div/mod to work right
set season [lindex {Chaos Discord Confusion Bureaucracy {The Aftermath}} \
[expr {$doy / 73}]]
set dos [expr {$doy % 73 + 1}]
incr year 1166
return "$season $dos, $year YOLD"
}</lang>
Demonstrating:
<lang tcl>puts [disdate 2010 7 22]; # Today
puts [disdate 2012 2 28]
puts [disdate 2012 2 29]
puts [disdate 2012 3 1]</lang>
Output:
<pre>
Confusion 57, 3176 YOLD
Chaos 59, 3178 YOLD
St. Tib's Day, 3178 YOLD
Chaos 60, 3178 YOLD
</pre>
Anonymous user