Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,4 +1 @@
|
|||
Convert a given date from the Gregorian calendar to the Discordian calendar.
|
||||
|
||||
'''See Also'''
|
||||
* [[wp:Discordian calendar|Discordian calendar (wiki)]]
|
||||
Convert a given date from the [[wp:Gregorian calendar|Gregorian calendar]] to the [[wp:Discordian calendar|Discordian calendar]].
|
||||
|
|
|
|||
4
Task/Discordian-date/00META.yaml
Normal file
4
Task/Discordian-date/00META.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Date and time
|
||||
note: Discordian date
|
||||
23
Task/Discordian-date/Clojure/discordian-date.clj
Normal file
23
Task/Discordian-date/Clojure/discordian-date.clj
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
(require '[clj-time.core :as tc])
|
||||
|
||||
(def seasons ["Chaos" "Discord" "Confusion" "Bureaucracy" "The Aftermath"])
|
||||
(def weekdays ["Sweetmorn" "Boomtime" "Pungenday" "Prickle-Prickle" "Setting Orange"])
|
||||
(def year-offset 1166)
|
||||
|
||||
(defn leap-year? [year]
|
||||
(= 29 (tc/number-of-days-in-the-month year 2)))
|
||||
|
||||
(defn discordian-day [day leap]
|
||||
(let [offset (if (and leap (>= day 59)) 1 0)
|
||||
day-off (- day offset)
|
||||
day-num (inc (rem day-off 73))
|
||||
season (seasons (quot day-off 73))
|
||||
weekday (weekdays (mod day-off 5))]
|
||||
(if (and (= day 59) (= offset 1))
|
||||
"St. Tib's Day"
|
||||
(str weekday ", " season " " day-num))))
|
||||
|
||||
(defn discordian-date [year month day]
|
||||
(let [day-of-year (dec (.getDayOfYear (tc/date-time year month day)))
|
||||
dday (discordian-day day-of-year (leap-year? year))]
|
||||
(format "%s, YOLD %s" dday (+ year year-offset))))
|
||||
57
Task/Discordian-date/Java/discordian-date.java
Normal file
57
Task/Discordian-date/Java/discordian-date.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class DiscordianDate {
|
||||
|
||||
final static String[] seasons = {"Chaos", "Discord", "Confusion",
|
||||
"Bureaucracy", "The Aftermath"};
|
||||
|
||||
final static String[] weekday = {"Sweetmorn", "Boomtime", "Pungenday",
|
||||
"Prickle-Prickle", "Setting Orange"};
|
||||
|
||||
final static String[] apostle = {"Mungday", "Mojoday", "Syaday",
|
||||
"Zaraday", "Maladay"};
|
||||
|
||||
final static String[] holiday = {"Chaoflux", "Discoflux", "Confuflux",
|
||||
"Bureflux", "Afflux"};
|
||||
|
||||
public static String discordianDate(final GregorianCalendar date) {
|
||||
int y = date.get(Calendar.YEAR) + 1166;
|
||||
int m = date.get(Calendar.MONTH);
|
||||
int d = date.get(Calendar.DATE);
|
||||
|
||||
if (date.isLeapYear(y) && m == 2 && d == 29)
|
||||
return "St. Tib's Day, in the YOLD " + y;
|
||||
|
||||
int dayOfYear = date.get(Calendar.DAY_OF_YEAR);
|
||||
if (date.isLeapYear(y) && dayOfYear >= 60)
|
||||
dayOfYear--;
|
||||
|
||||
int seasonDay = dayOfYear % 73;
|
||||
if (seasonDay == 5)
|
||||
return apostle[dayOfYear / 73] + ", in the YOLD " + y;
|
||||
if (seasonDay == 50)
|
||||
return holiday[dayOfYear / 73] + ", in the YOLD " + y;
|
||||
|
||||
String season = seasons[dayOfYear / 73];
|
||||
String dayOfWeek = weekday[(dayOfYear - 1) % 5];
|
||||
|
||||
return String.format("%s, day %s of %s in the YOLD %s",
|
||||
dayOfWeek, seasonDay, season, y);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(discordianDate(new GregorianCalendar()));
|
||||
|
||||
test(2010, 7, 22, "Pungenday, day 57 of Confusion in the YOLD 3176");
|
||||
test(2012, 2, 28, "Prickle-Prickle, day 59 of Chaos in the YOLD 3178");
|
||||
test(2012, 2, 29, "St. Tib's Day, in the YOLD 3178");
|
||||
test(2012, 3, 1, "Setting Orange, day 60 of Chaos in the YOLD 3178");
|
||||
test(2010, 1, 5, "Mungday, in the YOLD 3176");
|
||||
test(2011, 5, 3, "Discoflux, in the YOLD 3177");
|
||||
}
|
||||
|
||||
private static void test(int y, int m, int d, final String result) {
|
||||
assert (discordianDate(new GregorianCalendar(y, m, d)).equals(result));
|
||||
}
|
||||
}
|
||||
33
Task/Discordian-date/Perl/discordian-date.pl
Normal file
33
Task/Discordian-date/Perl/discordian-date.pl
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use 5.010;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::Piece ();
|
||||
|
||||
my @seasons = (qw< Chaos Discord Confusion Bureaucracy >, 'The Aftermath');
|
||||
my @week_days = (qw< Sweetmorn Boomtime Pungenday Prickle-Prickle >, 'Setting Orange');
|
||||
|
||||
sub ordinal {
|
||||
my ($n) = @_;
|
||||
return $n . "th" if int($n/10) == 1;
|
||||
return $n . ((qw< th st nd rd th th th th th th>)[$n % 10]);
|
||||
}
|
||||
|
||||
sub ddate {
|
||||
my $d = Time::Piece->strptime( $_[0], '%Y-%m-%d' );
|
||||
my $yold = 'in the YOLD ' . ($d->year + 1166);
|
||||
|
||||
my $day_of_year0 = $d->day_of_year;
|
||||
|
||||
if( $d->is_leap_year ) {
|
||||
return "St. Tib's Day, $yold" if $d->mon == 2 and $d->mday == 29;
|
||||
$day_of_year0-- if $day_of_year0 >= 60; # Compensate for St. Tib's Day
|
||||
}
|
||||
|
||||
my $weekday = $week_days[ $day_of_year0 % @week_days ];
|
||||
my $season = $seasons[ $day_of_year0 / 73 ];
|
||||
my $season_day = ordinal( $day_of_year0 % 73 + 1 );
|
||||
|
||||
return "$weekday, the $season_day day of $season $yold";
|
||||
}
|
||||
|
||||
say "$_ is " . ddate($_) for qw< 2010-07-22 2012-02-28 2012-02-29 2012-03-01 >;
|
||||
Loading…
Add table
Add a link
Reference in a new issue