2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1 +1,3 @@
|
|||
Convert a given date from the [[wp:Gregorian calendar|Gregorian calendar]] to the [[wp:Discordian calendar|Discordian calendar]].
|
||||
;Task:
|
||||
Convert a given date from the [[wp:Gregorian calendar|Gregorian calendar]] to the [[wp:Discordian calendar|Discordian calendar]].
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -83,11 +83,14 @@ function yearly_calendar(y, d,m) {
|
|||
}
|
||||
}
|
||||
}
|
||||
function dos_date( cmd,x) { # under Microsoft Windows XP
|
||||
function dos_date( arr,cmd,d,x) { # under Microsoft Windows
|
||||
# XP - The current date is: MM/DD/YYYY
|
||||
# 8 - The current date is: DOW MM/DD/YYYY
|
||||
cmd = "DATE <NUL"
|
||||
cmd | getline x # The current date is: MM/DD/YYYY
|
||||
cmd | getline x
|
||||
close(cmd) # close pipe
|
||||
return sprintf("%04d%02d%02d",substr(x,28,4),substr(x,22,2),substr(x,25,2))
|
||||
d = arr[split(x,arr," ")]
|
||||
return sprintf("%04d%02d%02d",substr(d,7,4),substr(d,1,2),substr(d,4,2))
|
||||
}
|
||||
function error(x) {
|
||||
printf("error: argument %d is invalid, %s, in %s\n",argno,ARGV[argno],x)
|
||||
|
|
|
|||
|
|
@ -1,29 +1,104 @@
|
|||
with Ada.Calendar.Arithmetic;
|
||||
with Ada.Text_IO;
|
||||
with Ada.Integer_Text_IO;
|
||||
with Ada.Strings.Unbounded;
|
||||
with Ada.Strings.Unbounded.Text_IO;
|
||||
with Ada.Command_Line;
|
||||
|
||||
procedure Discordian is
|
||||
use Ada.Calendar;
|
||||
use Ada.Strings.Unbounded;
|
||||
use Ada.Command_Line;
|
||||
package UStr_IO renames Ada.Strings.Unbounded.Text_IO;
|
||||
|
||||
subtype Year_Number is Integer range 3067 .. 3565;
|
||||
type Seasons is (Chaos, Discord, Confusion, Bureaucracy, The_Aftermath);
|
||||
type Days_Of_Week is (Sweetmorn, Boomtime, Pungenday,
|
||||
Prickle_Prickle, Setting_Orange);
|
||||
subtype Day_Number is Integer range 1 .. 73;
|
||||
|
||||
type Discordian_Date is record
|
||||
Year : Year_Number;
|
||||
Season : Seasons;
|
||||
Day : Day_Number;
|
||||
Week_Day : Days_Of_Week;
|
||||
Is_Tibs_Day : Boolean := False;
|
||||
end record;
|
||||
|
||||
function Week_Day_To_Str(Day : Days_Of_Week) return Unbounded_String is
|
||||
s : Unbounded_String;
|
||||
begin
|
||||
case Day is
|
||||
when Sweetmorn => s := To_Unbounded_String("Sweetmorn");
|
||||
when Boomtime => s := To_Unbounded_String("Boomtime");
|
||||
when Pungenday => s := To_Unbounded_String("Pungenday");
|
||||
when Prickle_Prickle => s := To_Unbounded_String("Prickle-Prickle");
|
||||
when Setting_Orange => s := To_Unbounded_String("Setting Orange");
|
||||
end case;
|
||||
return s;
|
||||
end Week_Day_To_Str;
|
||||
|
||||
function Holiday(Season: Seasons) return Unbounded_String is
|
||||
s : Unbounded_String;
|
||||
begin
|
||||
case Season is
|
||||
when Chaos => s := To_Unbounded_String("Chaoflux");
|
||||
when Discord => s := To_Unbounded_String("Discoflux");
|
||||
when Confusion => s := To_Unbounded_String("Confuflux");
|
||||
when Bureaucracy => s := To_Unbounded_String("Bureflux");
|
||||
when The_Aftermath => s := To_Unbounded_String("Afflux");
|
||||
end case;
|
||||
return s;
|
||||
end Holiday;
|
||||
|
||||
function Apostle(Season: Seasons) return Unbounded_String is
|
||||
s : Unbounded_String;
|
||||
begin
|
||||
case Season is
|
||||
when Chaos => s := To_Unbounded_String("Mungday");
|
||||
when Discord => s := To_Unbounded_String("Mojoday");
|
||||
when Confusion => s := To_Unbounded_String("Syaday");
|
||||
when Bureaucracy => s := To_Unbounded_String("Zaraday");
|
||||
when The_Aftermath => s := To_Unbounded_String("Maladay");
|
||||
end case;
|
||||
return s;
|
||||
end Apostle;
|
||||
|
||||
function Season_To_Str(Season: Seasons) return Unbounded_String is
|
||||
s : Unbounded_String;
|
||||
begin
|
||||
case Season is
|
||||
when Chaos => s := To_Unbounded_String("Chaos");
|
||||
when Discord => s := To_Unbounded_String("Discord");
|
||||
when Confusion => s := To_Unbounded_String("Confusion");
|
||||
when Bureaucracy => s := To_Unbounded_String("Bureaucracy");
|
||||
when The_Aftermath => s := To_Unbounded_String("The Aftermath");
|
||||
end case;
|
||||
return s;
|
||||
end Season_To_Str;
|
||||
|
||||
procedure Convert (From : Time; To : out Discordian_Date) is
|
||||
use Ada.Calendar.Arithmetic;
|
||||
First_Day : Time;
|
||||
Number_Days : Day_Count;
|
||||
Leap_Year : boolean;
|
||||
begin
|
||||
First_Day := Time_Of (Year => Year (From), Month => 1, Day => 1);
|
||||
Number_Days := From - First_Day;
|
||||
|
||||
To.Year := Year (Date => From) + 1166;
|
||||
To.Is_Tibs_Day := False;
|
||||
if (To.Year - 2) mod 4 = 0 then
|
||||
Leap_Year := False;
|
||||
if Year (Date => From) mod 4 = 0 then
|
||||
if Year (Date => From) mod 100 = 0 then
|
||||
if Year (Date => From) mod 400 = 0 then
|
||||
Leap_Year := True;
|
||||
end if;
|
||||
else
|
||||
Leap_Year := True;
|
||||
end if;
|
||||
end if;
|
||||
if Leap_Year then
|
||||
if Number_Days > 59 then
|
||||
Number_Days := Number_Days - 1;
|
||||
elsif Number_Days = 59 then
|
||||
|
|
@ -39,42 +114,90 @@ procedure Discordian is
|
|||
when 4 => To.Season := The_Aftermath;
|
||||
when others => raise Constraint_Error;
|
||||
end case;
|
||||
case Number_Days mod 5 is
|
||||
when 0 => To.Week_Day := Sweetmorn;
|
||||
when 1 => To.Week_Day := Boomtime;
|
||||
when 2 => To.Week_Day := Pungenday;
|
||||
when 3 => To.Week_Day := Prickle_Prickle;
|
||||
when 4 => To.Week_Day := Setting_Orange;
|
||||
when others => raise Constraint_Error;
|
||||
end case;
|
||||
end Convert;
|
||||
|
||||
procedure Put (Item : Discordian_Date) is
|
||||
begin
|
||||
Ada.Text_IO.Put ("YOLD" & Integer'Image (Item.Year));
|
||||
if Item.Is_Tibs_Day then
|
||||
Ada.Text_IO.Put (", St. Tib's Day");
|
||||
Ada.Text_IO.Put ("St. Tib's Day");
|
||||
else
|
||||
Ada.Text_IO.Put (", " & Seasons'Image (Item.Season));
|
||||
Ada.Text_IO.Put (" " & Integer'Image (Item.Day));
|
||||
UStr_IO.Put (Week_Day_To_Str(Item.Week_Day));
|
||||
Ada.Text_IO.Put (", day" & Integer'Image (Item.Day));
|
||||
Ada.Text_IO.Put (" of ");
|
||||
UStr_IO.Put (Season_To_Str (Item.Season));
|
||||
if Item.Day = 5 then
|
||||
Ada.Text_IO.Put (", ");
|
||||
UStr_IO.Put (Apostle(Item.Season));
|
||||
elsif Item.Day = 50 then
|
||||
Ada.Text_IO.Put (", ");
|
||||
UStr_IO.Put (Holiday(Item.Season));
|
||||
end if;
|
||||
end if;
|
||||
Ada.Text_IO.Put (" in the YOLD" & Integer'Image (Item.Year));
|
||||
Ada.Text_IO.New_Line;
|
||||
end Put;
|
||||
|
||||
Test_Day : Time;
|
||||
Test_DDay : Discordian_Date;
|
||||
Year : Integer;
|
||||
Month : Integer;
|
||||
Day : Integer;
|
||||
YYYYMMDD : Integer;
|
||||
begin
|
||||
Test_Day := Clock;
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
Test_Day := Time_Of (Year => 2012, Month => 2, Day => 28);
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
Test_Day := Time_Of (Year => 2012, Month => 2, Day => 29);
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
Test_Day := Time_Of (Year => 2012, Month => 3, Day => 1);
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
Test_Day := Time_Of (Year => 2010, Month => 7, Day => 22);
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
Test_Day := Time_Of (Year => 2012, Month => 9, Day => 2);
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
Test_Day := Time_Of (Year => 2012, Month => 12, Day => 31);
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
|
||||
if Argument_Count = 0 then
|
||||
Test_Day := Clock;
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
end if;
|
||||
|
||||
for Arg in 1..Argument_Count loop
|
||||
|
||||
if Argument(Arg)'Length < 8 then
|
||||
Ada.Text_IO.Put("ERROR: Invalid Argument : '" & Argument(Arg) & "'");
|
||||
Ada.Text_IO.Put("Input format YYYYMMDD");
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
|
||||
begin
|
||||
YYYYMMDD := Integer'Value(Argument(Arg));
|
||||
exception
|
||||
when Constraint_Error =>
|
||||
Ada.Text_IO.Put("ERROR: Invalid Argument : '" & Argument(Arg) & "'");
|
||||
raise;
|
||||
end;
|
||||
|
||||
Day := YYYYMMDD mod 100;
|
||||
if Day < Day_Number'First or Day > Day_Number'Last then
|
||||
Ada.Text_IO.Put("ERROR: Invalid Day:" & Integer'Image(Day));
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
|
||||
Month := ((YYYYMMDD - Day) / 100) mod 100;
|
||||
if Month < Month_Number'First or Month > Month_Number'Last then
|
||||
Ada.Text_IO.Put("ERROR: Invalid Month:" & Integer'Image(Month));
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
|
||||
Year := ((YYYYMMDD - Day - Month * 100) / 10000);
|
||||
if Year < 1901 or Year > 2399 then
|
||||
Ada.Text_IO.Put("ERROR: Invalid Year:" & Integer'Image(Year));
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
|
||||
Test_Day := Time_Of (Year => Year, Month => Month, Day => Day);
|
||||
|
||||
Convert (From => Test_Day, To => Test_DDay);
|
||||
Put (Test_DDay);
|
||||
|
||||
end loop;
|
||||
|
||||
end Discordian;
|
||||
|
|
|
|||
177
Task/Discordian-date/Batch-File/discordian-date.bat
Normal file
177
Task/Discordian-date/Batch-File/discordian-date.bat
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
@echo off
|
||||
goto Parse
|
||||
|
||||
Discordian Date Converter:
|
||||
|
||||
Usage:
|
||||
ddate
|
||||
ddate /v
|
||||
ddate /d isoDate
|
||||
ddate /v /d isoDate
|
||||
|
||||
:Parse
|
||||
shift
|
||||
if "%0"=="" goto Prologue
|
||||
if "%0"=="/v" set Verbose=1
|
||||
if "%0"=="/d" set dateToTest=%1
|
||||
if "%0"=="/d" shift
|
||||
goto Parse
|
||||
|
||||
:Prologue
|
||||
if "%dateToTest%"=="" set dateToTest=%date%
|
||||
for %%a in (GYear GMonth GDay GMonthName GWeekday GDayThisYear) do set %%a=fnord
|
||||
for %%a in (DYear DMonth DDay DMonthName DWeekday) do set %%a=MUNG
|
||||
goto Start
|
||||
|
||||
:Start
|
||||
for /f "tokens=1,2,3 delims=/:;-. " %%a in ('echo %dateToTest%') do (
|
||||
set GYear=%%a
|
||||
set GMonth=%%b
|
||||
set GDay=%%c
|
||||
)
|
||||
goto GMonthName
|
||||
|
||||
:GMonthName
|
||||
if %GMonth% EQU 1 set GMonthName=January
|
||||
if %GMonth% EQU 2 set GMonthName=February
|
||||
if %GMonth% EQU 3 set GMonthName=March
|
||||
if %GMonth% EQU 4 set GMonthName=April
|
||||
if %GMonth% EQU 5 set GMonthName=May
|
||||
if %GMonth% EQU 6 set GMonthName=June
|
||||
if %GMonth% EQU 7 set GMonthName=July
|
||||
if %GMonth% EQU 8 set GMonthName=August
|
||||
if %GMonth% EQU 9 set GMonthName=September
|
||||
if %GMonth% EQU 10 set GMonthName=October
|
||||
if %GMonth% EQU 11 set GMonthName=November
|
||||
if %GMonth% EQU 12 set GMonthName=December
|
||||
goto GLeap
|
||||
|
||||
:GLeap
|
||||
set /a CommonYear=GYear %% 4
|
||||
set /a CommonCent=GYear %% 100
|
||||
set /a CommonQuad=GYear %% 400
|
||||
set GLeap=0
|
||||
if %CommonYear% EQU 0 set GLeap=1
|
||||
if %CommonCent% EQU 0 set GLeap=0
|
||||
if %CommonQuad% EQU 0 set GLeap=1
|
||||
goto GDayThisYear
|
||||
|
||||
:GDayThisYear
|
||||
set GDayThisYear=%GDay%
|
||||
if %GMonth% GTR 11 set /a GDayThisYear=%GDayThisYear%+30
|
||||
if %GMonth% GTR 10 set /a GDayThisYear=%GDayThisYear%+31
|
||||
if %GMonth% GTR 9 set /a GDayThisYear=%GDayThisYear%+30
|
||||
if %GMonth% GTR 8 set /a GDayThisYear=%GDayThisYear%+31
|
||||
if %GMonth% GTR 7 set /a GDayThisYear=%GDayThisYear%+31
|
||||
if %GMonth% GTR 6 set /a GDayThisYear=%GDayThisYear%+30
|
||||
if %GMonth% GTR 5 set /a GDayThisYear=%GDayThisYear%+31
|
||||
if %GMonth% GTR 4 set /a GDayThisYear=%GDayThisYear%+30
|
||||
if %GMonth% GTR 3 set /a GDayThisYear=%GDayThisYear%+31
|
||||
if %GMonth% GTR 2 if %GLeap% EQU 1 set /a GDayThisYear=%GDayThisYear%+29
|
||||
if %GMonth% GTR 2 if %GLeap% EQU 0 set /a GDayThisYear=%GDayThisYear%+28
|
||||
if %GMonth% GTR 1 set /a GDayThisYear=%GDayThisYear%+31
|
||||
goto DYear
|
||||
|
||||
:DYear
|
||||
set /a DYear=GYear+1166
|
||||
goto DMonth
|
||||
|
||||
:DMonth
|
||||
set DMonth=1
|
||||
set DDay=%GDayThisYear%
|
||||
if %DDay% GTR 73 (
|
||||
set /a DDay=%DDay%-73
|
||||
set /a DMonth=%DMonth%+1
|
||||
)
|
||||
if %DDay% GTR 73 (
|
||||
set /a DDay=%DDay%-73
|
||||
set /a DMonth=%DMonth%+1
|
||||
)
|
||||
if %DDay% GTR 73 (
|
||||
set /a DDay=%DDay%-73
|
||||
set /a DMonth=%DMonth%+1
|
||||
)
|
||||
if %DDay% GTR 73 (
|
||||
set /a DDay=%DDay%-73
|
||||
set /a DMonth=%DMonth%+1
|
||||
)
|
||||
goto DDay
|
||||
|
||||
:DDay
|
||||
if %GLeap% EQU 1 (
|
||||
if %GDayThisYear% GEQ 61 (
|
||||
set /a DDay=%DDay%-1
|
||||
)
|
||||
)
|
||||
if %DDay% EQU 0 (
|
||||
set /a DDay=73
|
||||
set /a DMonth=%DMonth%-1
|
||||
)
|
||||
goto DMonthName
|
||||
|
||||
:DMonthName
|
||||
if %DMonth% EQU 1 set DMonthName=Chaos
|
||||
if %DMonth% EQU 2 set DMonthName=Discord
|
||||
if %DMonth% EQU 3 set DMonthName=Confusion
|
||||
if %DMonth% EQU 4 set DMonthName=Bureaucracy
|
||||
if %DMonth% EQU 5 set DMonthName=Aftermath
|
||||
goto DTib
|
||||
|
||||
:DTib
|
||||
set DTib=0
|
||||
if %GDayThisYear% EQU 60 if %GLeap% EQU 1 set DTib=1
|
||||
if %GLeap% EQU 1 if %GDayThisYear% GTR 60 set /a GDayThisYear=%GDayThisYear%-1
|
||||
set DWeekday=%GDayThisYear%
|
||||
goto DWeekday
|
||||
|
||||
:DWeekday
|
||||
if %DWeekday% LEQ 5 goto _DWeekday
|
||||
set /a DWeekday=%DWeekday%-5
|
||||
goto DWeekday
|
||||
:_DWeekday
|
||||
if %DWeekday% EQU 1 set DWeekday=Sweetmorn
|
||||
if %DWeekday% EQU 2 set DWeekday=Boomtime
|
||||
if %DWeekday% EQU 3 set DWeekday=Pungenday
|
||||
if %DWeekday% EQU 4 set DWeekday=Prickle-Prickle
|
||||
if %DWeekday% EQU 5 set DWeekday=Setting Orange
|
||||
goto GWeekday
|
||||
|
||||
:GWeekday
|
||||
goto GEnding
|
||||
|
||||
:GEnding
|
||||
set GEnding=th
|
||||
for %%a in (1 21 31) do if %GDay% EQU %%a set GEnding=st
|
||||
for %%a in (2 22) do if %GDay% EQU %%a set GEnding=nd
|
||||
for %%a in (3 23) do if %GDay% EQU %%a set GEnding=rd
|
||||
goto DEnding
|
||||
|
||||
:DEnding
|
||||
set DEnding=th
|
||||
for %%a in (1 21 31 41 51 61 71) do if %Dday% EQU %%a set DEnding=st
|
||||
for %%a in (2 22 32 42 52 62 72) do if %Dday% EQU %%a set DEnding=nd
|
||||
for %%a in (3 23 33 43 53 63 73) do if %Dday% EQU %%a set DEnding=rd
|
||||
goto Display
|
||||
|
||||
:Display
|
||||
if "%Verbose%"=="1" goto Display2
|
||||
echo.
|
||||
if %DTib% EQU 1 (
|
||||
echo St. Tib's Day, %DYear%
|
||||
) else echo %DWeekday%, %DMonthName% %DDay%%DEnding%, %DYear%
|
||||
goto Epilogue
|
||||
|
||||
:Display2
|
||||
echo.
|
||||
echo Gregorian: %GMonthName% %GDay%%GEnding%, %GYear%
|
||||
if %DTib% EQU 1 (
|
||||
echo Discordian: St. Tib's Day, %DYear%
|
||||
) else echo Discordian: %DWeekday%, %DMonthName% %DDay%%DEnding%, %DYear%
|
||||
goto Epilogue
|
||||
|
||||
:Epilogue
|
||||
set Verbose=
|
||||
set dateToTest=
|
||||
echo.
|
||||
|
||||
:End
|
||||
|
|
@ -2,6 +2,12 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#define day_of_week( x ) ((x) == 1 ? "Sweetmorn" :\
|
||||
(x) == 2 ? "Boomtime" :\
|
||||
(x) == 3 ? "Pungenday" :\
|
||||
(x) == 4 ? "Prickle-Prickle" :\
|
||||
"Setting Orange")
|
||||
|
||||
#define season( x ) ((x) == 0 ? "Chaos" :\
|
||||
(x) == 1 ? "Discord" :\
|
||||
(x) == 2 ? "Confusion" :\
|
||||
|
|
@ -25,7 +31,8 @@ char * ddate( int y, int d ){
|
|||
}
|
||||
}
|
||||
|
||||
sprintf( result, "%s %d, YOLD %d", season( d/73 ), date( d ), dyear );
|
||||
sprintf( result, "%s, %s %d, YOLD %d",
|
||||
day_of_week(d%5), season(((d%73)==0?d-1:d)/73 ), date( d ), dyear );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ string discordianDate(in Date date) pure {
|
|||
date.dayOfYear - 1 :
|
||||
date.dayOfYear;
|
||||
|
||||
immutable dsDay = doy % 73; // Season day.
|
||||
immutable dsDay = (doy % 73)==0? 73:(doy % 73); // Season day.
|
||||
if (dsDay == 5)
|
||||
return apostle[doy / 73] ~ ", in the YOLD " ~ dYear;
|
||||
if (dsDay == 50)
|
||||
return holiday[doy / 73] ~ ", in the YOLD " ~ dYear;
|
||||
|
||||
immutable dSeas = seasons[doy / 73];
|
||||
immutable dSeas = seasons[(((doy%73)==0)?doy-1:doy) / 73];
|
||||
immutable dWday = weekday[(doy - 1) % 5];
|
||||
|
||||
return format("%s, day %s of %s in the YOLD %s",
|
||||
|
|
@ -48,6 +48,33 @@ unittest {
|
|||
"Discoflux, in the YOLD 3177");
|
||||
}
|
||||
|
||||
void main() {
|
||||
(cast(Date)Clock.currTime).discordianDate.writeln;
|
||||
void main(string args[]) {
|
||||
int yyyymmdd, day, mon, year, sign;
|
||||
if (args.length == 1) {
|
||||
(cast(Date)Clock.currTime).discordianDate.writeln;
|
||||
return;
|
||||
}
|
||||
foreach (i, arg; args) {
|
||||
if (i > 0) {
|
||||
//writef("%d: %s: ", i, arg);
|
||||
yyyymmdd = to!int(arg);
|
||||
if (yyyymmdd < 0) {
|
||||
sign = -1;
|
||||
yyyymmdd = -yyyymmdd;
|
||||
}
|
||||
else {
|
||||
sign = 1;
|
||||
}
|
||||
day = yyyymmdd % 100;
|
||||
if (day == 0) {
|
||||
day = 1;
|
||||
}
|
||||
mon = ((yyyymmdd - day) / 100) % 100;
|
||||
if (mon == 0) {
|
||||
mon = 1;
|
||||
}
|
||||
year = sign * ((yyyymmdd - day - 100*mon) / 10000);
|
||||
writefln("%s", Date(year, mon, day).discordianDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
44
Task/Discordian-date/Haskell/discordian-date-1.hs
Normal file
44
Task/Discordian-date/Haskell/discordian-date-1.hs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import Data.Time (isLeapYear)
|
||||
import Data.Time.Calendar.MonthDay (monthAndDayToDayOfYear)
|
||||
import Text.Printf (printf)
|
||||
|
||||
type Year = Integer
|
||||
type Day = Int
|
||||
type Month = Int
|
||||
|
||||
data DDate = DDate Weekday Season Day Year
|
||||
| StTibsDay Year deriving (Eq, Ord)
|
||||
|
||||
data Season = Chaos
|
||||
| Discord
|
||||
| Confusion
|
||||
| Bureaucracy
|
||||
| TheAftermath
|
||||
deriving (Show, Enum, Eq, Ord, Bounded)
|
||||
|
||||
data Weekday = Sweetmorn
|
||||
| Boomtime
|
||||
| Pungenday
|
||||
| PricklePrickle
|
||||
| SettingOrange
|
||||
deriving (Show, Enum, Eq, Ord, Bounded)
|
||||
|
||||
instance Show DDate where
|
||||
show (StTibsDay y) = printf "St. Tib's Day, %d YOLD" y
|
||||
show (DDate w s d y) = printf "%s, %s %d, %d YOLD" (show w) (show s) d y
|
||||
|
||||
fromYMD :: (Year, Month, Day) -> DDate
|
||||
fromYMD (y, m, d)
|
||||
| leap && dayOfYear == 59 = StTibsDay yold
|
||||
| leap && dayOfYear >= 60 = mkDDate $ dayOfYear - 1
|
||||
| otherwise = mkDDate dayOfYear
|
||||
where
|
||||
yold = y + 1166
|
||||
dayOfYear = monthAndDayToDayOfYear leap m d - 1
|
||||
leap = isLeapYear y
|
||||
|
||||
mkDDate dayOfYear = DDate weekday season dayOfSeason yold
|
||||
where
|
||||
weekday = toEnum $ dayOfYear `mod` 5
|
||||
season = toEnum $ dayOfYear `div` 73
|
||||
dayOfSeason = 1 + dayOfYear `mod` 73
|
||||
11
Task/Discordian-date/Haskell/discordian-date-2.hs
Normal file
11
Task/Discordian-date/Haskell/discordian-date-2.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
test = mapM_ display dates
|
||||
where
|
||||
display d = putStr (show d ++ " -> ") >> print (fromYMD d)
|
||||
dates = [(2012,2,28)
|
||||
,(2012,2,29)
|
||||
,(2012,3,1)
|
||||
,(2012,3,14)
|
||||
,(2012,3,15)
|
||||
,(2010,9,2)
|
||||
,(2010,12,31)
|
||||
,(2011,1,1)]
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
import Data.List
|
||||
import Data.Time
|
||||
import Data.Time.Calendar.MonthDay
|
||||
|
||||
seasons = words "Chaos Discord Confusion Bureaucracy The_Aftermath"
|
||||
|
||||
discordianDate (y,m,d) = do
|
||||
let doy = monthAndDayToDayOfYear (isLeapYear y) m d
|
||||
(season, dday) = divMod doy 73
|
||||
dos = dday - fromEnum (isLeapYear y && m >2)
|
||||
dDate
|
||||
| isLeapYear y && m==2 && d==29 = "St. Tib's Day, " ++ show (y+1166) ++ " YOLD"
|
||||
| otherwise = seasons!!season ++ " " ++ show dos ++ ", " ++ show (y+1166) ++ " YOLD"
|
||||
putStrLn dDate
|
||||
|
|
@ -2,7 +2,6 @@ import java.util.Calendar;
|
|||
import java.util.GregorianCalendar;
|
||||
|
||||
public class DiscordianDate {
|
||||
|
||||
final static String[] seasons = {"Chaos", "Discord", "Confusion",
|
||||
"Bureaucracy", "The Aftermath"};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,49 +1,72 @@
|
|||
/**
|
||||
* All Hail Discordia! - this script prints Discordian date using system date.
|
||||
* author: s1w_, lang: JavaScript
|
||||
* author: jklu, lang: JavaScript
|
||||
*/
|
||||
function print_ddate(mod) {
|
||||
var p;
|
||||
switch(mod || 0) {// <--choose display pattern or pass option by parameter
|
||||
default:
|
||||
case 0:/* Sweetmorn, Day 57 of the Season of Confusion, Anno Mung 3177 */ p="{0}, [Day {1} of the Season of {2}], Anno Mung {3}"; break;
|
||||
case 1:/* Sweetmorn, The 57th Day of Confusion, 3177 YOLD */ p="{0}, [The {1}th Day of {2}], {3} YOLD"; break;
|
||||
case 2:/* Sweetmorn, the 57th day of Confusion, AM 3177 */ p="{0}, [the {1}th day of {2}], AM {3}"; break;
|
||||
case 3:/* Sweetmorn / Confusion 57th / AM 3177 */ p="{0} / [{2} {1}th] / AM {3}"; break;
|
||||
}
|
||||
var ddateStr, curr, sum, extra, today, day, month, year, dSeason, dDay, season, ddate, dyear;
|
||||
var seasons = ["Chaos", "Discord", "Confusion",
|
||||
"Bureaucracy", "The Aftermath"];
|
||||
var weekday = ["Sweetmorn", "Boomtime", "Pungenday",
|
||||
"Prickle-Prickle", "Setting Orange"];
|
||||
|
||||
format = function(s, $1, $2, $3, $4) {
|
||||
if ($2 != undefined) {
|
||||
var postfix;
|
||||
switch(parseInt($2.charAt($2.length-1))) {
|
||||
case 1: postfix = '}st'; break;
|
||||
case 2: postfix = '}nd'; break;
|
||||
case 3: postfix = '}rd'; break;
|
||||
default:postfix = '}th';
|
||||
}
|
||||
return p.replace(/\}th/, postfix).replace(/(\[|\])/g, '').format($1, $2, $3, $4);
|
||||
}
|
||||
else return p.replace(/\[.*?\]/,"<span style='color:green'>{2}</span>").format($1, $2, $3, $4);
|
||||
}
|
||||
var apostle = ["Mungday", "Mojoday", "Syaday",
|
||||
"Zaraday", "Maladay"];
|
||||
|
||||
String.prototype.format = function() {
|
||||
var pattern = /\{\d+\}/g;
|
||||
var args = arguments;
|
||||
return this.replace(pattern, function(capture){ return args[capture.match(/\d+/)]; });
|
||||
}
|
||||
var holiday = ["Chaoflux", "Discoflux", "Confuflux",
|
||||
"Bureflux", "Afflux"];
|
||||
|
||||
dDay = new Array("Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange");
|
||||
dSeason = new Array("Chaos", "Discord", "Confusion", "Bureaucracy", "Aftermath");
|
||||
curr = new Date(); extra = new Array(0,3,0,3,2,3,2,3,3,2,3,2);
|
||||
today = curr.getDate(); month = curr.getMonth(); year = curr.getFullYear();
|
||||
sum = month * 28;
|
||||
for(var i=0; i<=month; i++)
|
||||
sum += extra[i];
|
||||
sum += today;
|
||||
day = (sum - 1) % 5; ddate = sum % 73;
|
||||
season = (month==1)&&(today==29) ? "St. Tib\'s Day" : dSeason[Math.floor(sum/73)];
|
||||
dyear = year+1166;
|
||||
ddateStr = ""+dDay[day]+ddate+season+dyear;
|
||||
document.write(ddateStr.replace(/(\D+)(?:(\d+)(?!St)|(?:\d+))(\D+)(\d+)/i, format));
|
||||
|
||||
Date.prototype.isLeapYear = function() {
|
||||
var year = this.getFullYear();
|
||||
if ((year & 3) !== 0) return false;
|
||||
return ((year % 100) !== 0 || (year % 400) === 0);
|
||||
};
|
||||
|
||||
// Get Day of Year
|
||||
Date.prototype.getDOY = function() {
|
||||
var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
||||
var mn = this.getMonth();
|
||||
var dn = this.getDate();
|
||||
var dayOfYear = dayCount[mn] + dn;
|
||||
if (mn > 1 && this.isLeapYear()) dayOfYear++;
|
||||
return dayOfYear;
|
||||
};
|
||||
|
||||
function discordianDate(date) {
|
||||
var y = date.getFullYear();
|
||||
var yold = y + 1166;
|
||||
var dayOfYear = date.getDOY();
|
||||
|
||||
if (date.isLeapYear()) {
|
||||
if (dayOfYear == 60)
|
||||
return "St. Tib's Day, in the YOLD " + yold;
|
||||
else if (dayOfYear > 60)
|
||||
dayOfYear--;
|
||||
}
|
||||
dayOfYear--;
|
||||
|
||||
var divDay= Math.floor(dayOfYear/73);
|
||||
|
||||
var seasonDay = (dayOfYear % 73) + 1;
|
||||
if (seasonDay == 5)
|
||||
return apostle[divDay] + ", in the YOLD " + yold;
|
||||
if (seasonDay == 50)
|
||||
return holiday[divDay] + ", in the YOLD " + yold;
|
||||
|
||||
var season = seasons[divDay];
|
||||
var dayOfWeek = weekday[dayOfYear % 5];
|
||||
|
||||
return dayOfWeek + ", day " + seasonDay + " of " +
|
||||
season + " in the YOLD " + yold;
|
||||
}
|
||||
|
||||
function test(y, m, d, result) {
|
||||
console.assert((discordianDate(new Date(y, m, d)) == result), result);
|
||||
}
|
||||
|
||||
console.log(discordianDate(new Date(Date.now())));
|
||||
test(2010, 6, 22, "Pungenday, day 57 of Confusion in the YOLD 3176");
|
||||
test(2012, 1, 28, "Prickle-Prickle, day 59 of Chaos in the YOLD 3178");
|
||||
test(2012, 1, 29, "St. Tib's Day, in the YOLD 3178");
|
||||
test(2012, 2, 1, "Setting Orange, day 60 of Chaos in the YOLD 3178");
|
||||
test(2010, 0, 5, "Mungday, in the YOLD 3176");
|
||||
test(2011, 4, 3, "Discoflux, in the YOLD 3177");
|
||||
test(2015, 9, 19, "Boomtime, day 73 of Bureaucracy in the YOLD 3181");
|
||||
|
|
|
|||
|
|
@ -1,8 +1,2 @@
|
|||
print_ddate()
|
||||
"Sweetmorn, Day 57 of the Season of Confusion, Anno Mung 3177"
|
||||
print_ddate(1)
|
||||
"Sweetmorn, The 57th Day of Confusion, 3177 YOLD"
|
||||
print_ddate(2)
|
||||
"Sweetmorn, the 57th day of Confusion, AM 3177"
|
||||
print_ddate(3)
|
||||
"Sweetmorn / Confusion 57th / AM 3177"
|
||||
console.log(discordianDate(new Date(Date.now())));
|
||||
"Prickle-Prickle, day 47 of The Aftermath in the YOLD 3181"
|
||||
|
|
|
|||
55
Task/Discordian-date/Kotlin/discordian-date.kotlin
Normal file
55
Task/Discordian-date/Kotlin/discordian-date.kotlin
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import java.util.Calendar
|
||||
import java.util.GregorianCalendar
|
||||
|
||||
enum class Season {
|
||||
Chaos, Discord, Confusion, Bureaucracy, Aftermath;
|
||||
companion object { fun from(i: Int) = values()[i / 73] }
|
||||
}
|
||||
enum class Weekday {
|
||||
Sweetmorn, Boomtime, Pungenday, Prickle_Prickle, Setting_Orange;
|
||||
companion object { fun from(i: Int) = values()[i % 5] }
|
||||
}
|
||||
enum class Apostle {
|
||||
Mungday, Mojoday, Syaday, Zaraday, Maladay;
|
||||
companion object { fun from(i: Int) = values()[i / 73] }
|
||||
}
|
||||
enum class Holiday {
|
||||
Chaoflux, Discoflux, Confuflux, Bureflux, Afflux;
|
||||
companion object { fun from(i: Int) = values()[i / 73] }
|
||||
}
|
||||
|
||||
fun GregorianCalendar.discordianDate(): String {
|
||||
val y = get(Calendar.YEAR)
|
||||
val yold = y + 1166
|
||||
|
||||
var dayOfYear = get(Calendar.DAY_OF_YEAR)
|
||||
if (isLeapYear(y)) {
|
||||
if (dayOfYear == 60)
|
||||
return "St. Tib's Day, in the YOLD " + yold
|
||||
else if (dayOfYear > 60)
|
||||
dayOfYear--
|
||||
}
|
||||
|
||||
val seasonDay = --dayOfYear % 73 + 1
|
||||
return when (seasonDay) {
|
||||
5 -> "" + Apostle.from(dayOfYear) + ", in the YOLD " + yold
|
||||
50 -> "" + Holiday.from(dayOfYear) + ", in the YOLD " + yold
|
||||
else -> "" + Weekday.from(dayOfYear) + ", day " + seasonDay + " of " + Season.from(dayOfYear) + " in the YOLD " + yold
|
||||
}
|
||||
}
|
||||
|
||||
internal fun test(y: Int, m: Int, d: Int, result: String) {
|
||||
assert(GregorianCalendar(y, m, d).discordianDate() == result)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(GregorianCalendar().discordianDate())
|
||||
|
||||
test(2010, 6, 22, "Pungenday, day 57 of Confusion in the YOLD 3176")
|
||||
test(2012, 1, 28, "Prickle-Prickle, day 59 of Chaos in the YOLD 3178")
|
||||
test(2012, 1, 29, "St. Tib's Day, in the YOLD 3178")
|
||||
test(2012, 2, 1, "Setting Orange, day 60 of Chaos in the YOLD 3178")
|
||||
test(2010, 0, 5, "Mungday, in the YOLD 3176")
|
||||
test(2011, 4, 3, "Discoflux, in the YOLD 3177")
|
||||
test(2015, 9, 19, "Boomtime, day 73 of Bureaucracy in the YOLD 3181")
|
||||
}
|
||||
37
Task/Discordian-date/Maple/discordian-date.maple
Normal file
37
Task/Discordian-date/Maple/discordian-date.maple
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
convertDiscordian := proc(year, month, day)
|
||||
local days31, days30, daysThisYear, i, dYear, dMonth, dDay, seasons, week, dayOfWeek;
|
||||
days31 := [1, 3, 5, 7, 8, 10, 12];
|
||||
days30 := [4, 6, 9, 11];
|
||||
if month < 1 or month >12 then
|
||||
error "Invalid month: %1", month;
|
||||
end if;
|
||||
if (member(month, days31) and day > 31) or (member(month, days30) and day > 30) or (month = 2 and day > 29) or day < 1 then
|
||||
error "Invalid date: %1", day;
|
||||
end if;
|
||||
dYear := year + 1166;
|
||||
if month = 2 and day = 29 then
|
||||
printf("The date is St. Tib's Day, YOLD %a.\n", dYear);
|
||||
else
|
||||
seasons := ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"];
|
||||
week := ["Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"];
|
||||
daysThisYear := 0;
|
||||
for i to month-1 do
|
||||
if member(i, days31) then
|
||||
daysThisYear := daysThisYear + 31;
|
||||
elif member(i, days30) then
|
||||
daysThisYear := daysThisYear + 30;
|
||||
else
|
||||
daysThisYear := daysThisYear + 28;
|
||||
end if;
|
||||
end do;
|
||||
daysThisYear := daysThisYear + day -1;
|
||||
dMonth := seasons[trunc((daysThisYear) / 73)+1];
|
||||
dDay := daysThisYear mod 73 +1;
|
||||
dayOfWeek := week[daysThisYear mod 5 +1];
|
||||
printf("The date is %s %s %s, YOLD %a.\n", dayOfWeek, dMonth, convert(dDay, ordinal), dYear);
|
||||
end if;
|
||||
end proc:
|
||||
|
||||
convertDiscordian (2016, 1, 1);
|
||||
convertDiscordian (2016, 2, 29);
|
||||
convertDiscordian (2016, 12, 31);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
my @seasons = ['Chaos', 'Discord', 'Confusion', 'Bureaucracy', 'The Aftermath'];
|
||||
my @days = ['Sweetmorn', 'Boomtime', 'Pungenday', 'Prickle-Prickle', 'Setting Orange'];
|
||||
my @seasons = << Chaos Discord Confusion Bureaucracy 'The Aftermath' >>;
|
||||
my @days = << Sweetmorn Boomtime Pungenday Prickle-Prickle 'Setting Orange' >>;
|
||||
sub ordinal ( Int $n ) { $n ~ ( $n % 100 == 11|12|13
|
||||
?? 'th' !! < th st nd rd th th th th th th >[$n % 10] ) }
|
||||
|
||||
|
|
|
|||
22
Task/Discordian-date/PowerShell/discordian-date.psh
Normal file
22
Task/Discordian-date/PowerShell/discordian-date.psh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
function ConvertTo-Discordian ( [datetime]$GregorianDate )
|
||||
{
|
||||
$DayOfYear = $GregorianDate.DayOfYear
|
||||
$Year = $GregorianDate.Year + 1166
|
||||
If ( [datetime]::IsLeapYear( $GregorianDate.Year ) -and $DayOfYear -eq 60 )
|
||||
{ $Day = "St. Tib's Day" }
|
||||
Else
|
||||
{
|
||||
If ( [datetime]::IsLeapYear( $GregorianDate.Year ) -and $DayOfYear -gt 60 )
|
||||
{ $DayOfYear-- }
|
||||
$Weekday = @( 'Sweetmorn', 'Boomtime', 'Pungenday', 'Prickle-Prickle', 'Setting Orange' )[(($DayOfYear - 1 ) % 5 )]
|
||||
$Season = @( 'Chaos', 'Discord', 'Confusion', 'Bureaucracy', 'The Aftermath' )[( [math]::Truncate( ( $DayOfYear - 1 ) / 73 ) )]
|
||||
$DayOfSeason = ( $DayOfYear - 1 ) % 73 + 1
|
||||
$Day = "$Weekday, $Season $DayOfSeason"
|
||||
}
|
||||
$DiscordianDate = "$Day, $Year YOLD"
|
||||
return $DiscordianDate
|
||||
}
|
||||
|
||||
ConvertTo-Discordian ([datetime]'1/5/2016')
|
||||
ConvertTo-Discordian ([datetime]'2/29/2016')
|
||||
ConvertTo-Discordian ([datetime]'12/8/2016')
|
||||
|
|
@ -1,35 +1,34 @@
|
|||
/*REXX program converts a mm/dd/yyyy Gregorian date ───► Discordian date. */
|
||||
@day.1= 'Sweetness' /*define the 1st day─of─Discordian─week*/
|
||||
@day.2= 'Boomtime' /* " " 2nd " " " " */
|
||||
@day.3= 'Pungenday' /* " " 3rd " " " " */
|
||||
@day.4= 'Prickle-Prickle' /* " " 4th " " " " */
|
||||
@day.5= 'Setting Orange' /* " " 5th " " " " */
|
||||
/*REXX program converts a mm/dd/yyyy Gregorian date ───► a Discordian date. */
|
||||
@day.1= 'Sweetness' /*define the 1st day─of─Discordian─week*/
|
||||
@day.2= 'Boomtime' /* " " 2nd " " " " */
|
||||
@day.3= 'Pungenday' /* " " 3rd " " " " */
|
||||
@day.4= 'Prickle-Prickle' /* " " 4th " " " " */
|
||||
@day.5= 'Setting Orange' /* " " 5th " " " " */
|
||||
|
||||
@seas.0= "St. Tib's day," /*define the leap─day of Discordian yr.*/
|
||||
@seas.1= 'Chaos' /* " 1st season─of─Discordian─year.*/
|
||||
@seas.2= 'Discord' /* " 2nd " " " " */
|
||||
@seas.3= 'Confusion' /* " 3rd " " " " */
|
||||
@seas.4= 'Bureaucracy' /* " 4th " " " " */
|
||||
@seas.5= 'The Aftermath' /* " 5th " " " " */
|
||||
@seas.0= "St. Tib's day," /*define the leap─day of Discordian yr.*/
|
||||
@seas.1= 'Chaos' /* " 1st season─of─Discordian─year.*/
|
||||
@seas.2= 'Discord' /* " 2nd " " " " */
|
||||
@seas.3= 'Confusion' /* " 3rd " " " " */
|
||||
@seas.4= 'Bureaucracy' /* " 4th " " " " */
|
||||
@seas.5= 'The Aftermath' /* " 5th " " " " */
|
||||
|
||||
parse arg gM '/' gD "/" gY . /*get the specified Gregorian date*/
|
||||
if gM=='' | gM=='*' then parse value date('U') with gM '/' gD "/" gY .
|
||||
parse arg gM '/' gD "/" gY . /*obtain the specified Gregorian date. */
|
||||
if gM=='' | gM=='*' then parse value date('U') with gM '/' gD "/" gY .
|
||||
|
||||
gY=left(right(date(),4),4-length(Gy))gY /*adjust for 2─digit year or none.*/
|
||||
gY=left( right( date(), 4), 4 - length(Gy) )gY /*adjust for two─digit year or none. */
|
||||
|
||||
/* [↓] day─of─year, leapyear adj.*/
|
||||
doy=date('d',gY || right(gM,2,0)right(gD,2,0), "s") - (leapyear(gY) & gM>2)
|
||||
/* [↓] day─of─year, leapyear adjust. */
|
||||
doy=date('d', gY || right(gM, 2, 0)right(gD ,2, 0), "s") - (leapyear(gY) & gM>2)
|
||||
|
||||
dW=doy//5; if dW==0 then dW=5 /*compute the Discordian weekday. */
|
||||
dS=(doy-1)%73+1 /* " " " season. */
|
||||
dD=doy//73; if dD==0 then dD=73 /*compute Discordian day─of─month.*/
|
||||
dD=dD',' /*append a comma to Discordian day*/
|
||||
if leapyear(gY) & gM=2 & gD=29 then ds=0 /*is this St. Tib's day (leapday)?*/
|
||||
if ds==0 then dD= /*adjust for Discordian leap day. */
|
||||
dW=doy//5; if dW==0 then dW=5 /*compute the Discordian weekday. */
|
||||
dS=(doy-1)%73+1 /* " " " season. */
|
||||
dD=doy//73; if dD==0 then dD=73 /* " " " day─of─month. */
|
||||
if leapyear(gY) & gM=2 & gD=29 then ds=0 /*is this St. Tib's day (leapday) ? */
|
||||
if ds==0 then dD= /*adjust for the Discordian leap day. */
|
||||
|
||||
say space(@day.dW',' @seas.dS dD gY+1166) /*display the Discordian date. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
leapyear: procedure; parse arg y /*obtain four-digit Gregorian year*/
|
||||
if y//4\==0 then return 0 /*Not ÷ by 4? Not a leapyear.*/
|
||||
return y//100\==0 | y//400==0 /*apply the 100 and 400 year rule.*/
|
||||
say space(@day.dW',' @seas.dS dD"," gY +1166) /*display Discordian date to terminal. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
leapyear: procedure; parse arg y /*obtain a four─digit Gregorian year. */
|
||||
if y//4\==0 then return 0 /*Not ÷ by 4? Then not a leapyear. */
|
||||
return y//100\==0 | y//400==0 /*apply the 100 and 400 year rules.*/
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ class DiscordianDate
|
|||
end
|
||||
end
|
||||
|
||||
@season, @day = @day_of_year.divmod(DAYS_PER_SEASON)
|
||||
@season, @day = (@day_of_year-1).divmod(DAYS_PER_SEASON)
|
||||
@day += 1 #← ↑ fixes of-by-one error (only visible at season changes)
|
||||
@year = gregorian_date.year + YEAR_OFFSET
|
||||
end
|
||||
attr_reader :year, :day
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[[2012, 2, 28], [2012, 2, 29], [2012, 3, 1], [2011, 10, 5]].each do |date|
|
||||
[[2012, 2, 28], [2012, 2, 29], [2012, 3, 1], [2011, 10, 5], [2015, 10, 19]].each do |date|
|
||||
dd = DiscordianDate.new(*date)
|
||||
puts "#{"%4d-%02d-%02d" % date} => #{dd}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,11 @@
|
|||
val DISCORDIAN_SEASONS = Array("Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath")
|
||||
package rosetta
|
||||
|
||||
import java.util.GregorianCalendar
|
||||
import java.util.Calendar
|
||||
|
||||
object DDate extends App {
|
||||
private val DISCORDIAN_SEASONS = Array("Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath")
|
||||
|
||||
// month from 1-12; day from 1-31
|
||||
def ddate(year: Int, month: Int, day: Int): String = {
|
||||
val date = new GregorianCalendar(year, month - 1, day)
|
||||
|
|
@ -8,12 +15,20 @@
|
|||
if (isLeapYear && month == 2 && day == 29) // 2 means February
|
||||
"St. Tib's Day " + dyear + " YOLD"
|
||||
else {
|
||||
var dayOfYear = date.get(Calendar.DAY_OF_YEAR)
|
||||
var dayOfYear = date.get(Calendar.DAY_OF_YEAR) - 1
|
||||
if (isLeapYear && dayOfYear >= 60)
|
||||
dayOfYear -= 1 // compensate for St. Tib's Day
|
||||
|
||||
val dday = dayOfYear % 73
|
||||
val season = dayOfYear / 73
|
||||
"%s %d, %d YOLD".format(DISCORDIAN_SEASONS(season), dday, dyear)
|
||||
"%s %d, %d YOLD".format(DISCORDIAN_SEASONS(season), dday + 1, dyear)
|
||||
}
|
||||
}
|
||||
if (args.length == 3)
|
||||
println(ddate(args(2).toInt, args(1).toInt, args(0).toInt))
|
||||
else if (args.length == 0) {
|
||||
val today = Calendar.getInstance
|
||||
println(ddate(today.get(Calendar.YEAR), today.get(Calendar.MONTH)+1, today.get(Calendar.DAY_OF_MONTH)))
|
||||
} else
|
||||
println("usage: DDate [day month year]")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
ddate(2010, 7, 22) // Confusion 57, 3176 YOLD
|
||||
ddate(2012, 2, 28) // Chaos 59, 3178 YOLD
|
||||
ddate(2012, 2, 29) // St. Tib's Day 3178 YOLD
|
||||
ddate(2012, 3, 1) // Chaos 60, 3178 YOLD
|
||||
scala rosetta.DDate 2010 7 22
|
||||
Confusion 57, 3176 YOLD
|
||||
scala rosetta.DDate 28 2 2012
|
||||
Chaos 59, 3178 YOLD
|
||||
scala rosetta.DDate 29 2 2012
|
||||
St. Tib's Day 3178 YOLD
|
||||
scala rosetta.DDate 1 3 2012
|
||||
Chaos 60, 3178 YOLD
|
||||
scala rosetta.DDate 19 10 2015
|
||||
Bureaucracy 73, 3181 YOLD
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue