Discordian date: Difference between revisions

add Refal
(Added Wren)
(add Refal)
 
(24 intermediate revisions by 11 users not shown)
Line 10:
This program is written to run under CP/M, and it takes a Gregorian date as an argument on the command line, in <code>DDMMYYYY</code> format.
 
<langsyntaxhighlight lang="8080asm"> ;; On the 44th day of Discord in the YOLD 3186, ddate
;; has finally come to CP/M.
bdos: equ 5 ; CP/M syscalls
Line 233:
tibsday: db 'Saint Tib',39,'s Day$'
yold: db ' in the YOLD $'
</syntaxhighlight>
</lang>
 
{{out}}
Line 260:
This code is written to compile to a <code>.COM</code> file using <code>nasm</code>.
 
<langsyntaxhighlight lang="asm"> ;; DDATE for MS-DOS (assembles using nasm)
bits 16
cpu 8086
Line 462:
xflux: db 'flux!$'
tibsday: db "Saint Tib's Day$"
yold: db ' in the YOLD $'</langsyntaxhighlight>
 
{{out}}
Line 476:
C:\>ddate 01/05/2005
Setting Orange, day 5 of Chaos in the YOLD 3171: celebrate Mungday!
</pre>
 
=={{header|Action!}}==
{{Trans|MAD}}...via PL/M
<syntaxhighlight lang="action!">
;;; Discordian date calculation - translation of MAD (via PL/M)
 
;;; returns the next number from line, the terminator is ignored
;;; pos holds the position in line and is updated to the
;;; position of the character following the trailing
;;; delimiter - if there is one
;;; pos should be set to 1 on rhe first call
INT FUNC getNumber( CHAR ARRAY line, CARD POINTER pos )
CARD value, linePos
 
linePos = pos^
value = 0
; skip spaces
WHILE linePos <= line(0) AND line(linePos) = ' DO linePos ==+ 1 OD
; get the number
WHILE linePos <= line(0) AND line(linePos) >= '0 AND line(linePos) <= '9
DO
value ==* 10
value ==+ (line(linePos) - '0)
linePos ==+ 1
OD
pos^ = linePos + 1
RETURN(value)
 
;;; get a Gregorian date and output it as a Discordian date
PROC Main()
 
DEFINE STRING_POINTER = "CARD"
 
CARD gMonth, gDay, gYear, gPos
CARD yrDay, season, day, wkDay
CHAR ARRAY gLine(256)
STRING_POINTER ARRAY holy5(5), holy50(5), disday(5), disssn(5)
INT ARRAY mlengt(13) = [ 0 0 31 59 90 120
151 181 212 243 273 304 334
]
holy5 (0) = "MUNG" holy5 (1) = "MOJO" holy5 (2) = "SYA"
holy5 (3) = "ZARA" holy5 (4) = "MALA"
holy50(0) = "CHAO" holy50(1) = "DISCO" holy50(2) = "CONFU"
holy50(3) = "BURE" holy50(4) = "AF"
disday(0) = "SWEETMORN" disday(1) = "BOOMTIME"
disday(2) = "PUNGENDAY" disday(3) = "PRICKLE-PRICKLE"
disday(4) = "SETTING ORANGE"
disssn(0) = "CHAOS" disssn(1) = "DISCORD" disssn(2) = "CONFUSION"
disssn(3) = "BUREAUCRACY" disssn(4) = "THE AFTERMATH"
 
; get the Gregorian date from the keyboard, NB: no validation
Print("Gregorian date (MM/DD/YYYY)> ")
InputS(gLine)
gPos = 1
gMonth = getNumber(gLine, @gPos)
gDay = getNumber(gLine, @gPos)
gYear = getNumber(gLine, @gPos)
 
; convert to Discordian
IF gMonth = 2 AND gDay = 29 THEN
Print("SAINT TIB'S DAY IN THE Y.O.L.D. ")PrintC(gYear+1166)
ELSE
yrDay = mlengt(gMonth)+gDay
season = yrDay/73
day = yrDay-season*73
wkDay = (yrDay-1) MOD 5
Print(disday(wkDay) )Print(", DAY ")PrintC(day)Print(" OF ")
Print(disssn(season))Print(" IN THE Y.O.L.D ")PrintC(gYear+1166)
IF day = 5 THEN
PutE()
Print("CELEBRATE ")Print(holy5(season))Print("DAY")
ELSEIF day = 50 THEN
PutE()
Print("CELEBRATE ")Print(holy50(season))Print("FLUX")
FI
FI
PutE()
 
RETURN
</syntaxhighlight>
{{out}}
<pre>
Gregorian date (MM/DD/YYYY)> 4/1/2023
SWEETMORN, DAY 18 OF DISCORD IN THE Y.O.L.D 3189
</pre>
 
Line 481 ⟶ 566:
 
discordian.adb:
<langsyntaxhighlight Adalang="ada">with Ada.Calendar.Arithmetic;
with Ada.Text_IO;
with Ada.Integer_Text_IO;
Line 684 ⟶ 769:
 
end Discordian;
</syntaxhighlight>
</lang>
 
{{Out}}
Line 695 ⟶ 780:
Setting Orange, day 26 of Bureaucracy in the YOLD 3178
Setting Orange, day 73 of The Aftermath in the YOLD 3178</pre>
 
=={{header|ALGOL 68}}==
{{Trans|ALGOL W}} which was itself, {{Trans|MAD}}
Algol 68 has variable length strings which simplifies this a lot relative to the Algol W version.
<syntaxhighlight lang="algol68">BEGIN # DISCORDIAN DATE CALCULATION - TRANSLATION OF MAD VIA ALGOL W #
INT greg, gmonth, gday, gyear;
[]STRING holys = []STRING( "MUNG", "MOJO", "SYA", "ZARA", "MALA" )[ AT 0 ];
[]STRING holys0 = []STRING( "CHAO", "DISCO", "CONFU", "BURE", "AF" )[ AT 0 ];
[]STRING disday = []STRING( "SWEETMORN", "BOOMTIME", "PUNGENday", "PRICKLE-PRICKLE", "SETTING ORANGE" )[ AT 0 ];
[]STRING disssn = []STRING( "CHAOS", "DISCORD", "CONFUSION", "BUREAUCRACY", "THE AFTERMATH" )[ AT 0 ];
[]INT mlengt = []INT( 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 )[ AT 0 ];
CHAR slash1, slash2;
# input date should contain MM/DD/YYYY in the gregorian calendar #
read( ( gmonth, slash1, gday, slash2, gyear ) );
IF slash1 /= "/" OR slash2 /= "/" THEN print( ( "Invalid date format", newline ) ); stop FI;
 
IF gmonth = 2 AND gday = 29
THEN print( ( "SAINT TIB'S DAY IN THE Y.O.L.D. ", whole( gyear + 1166, -4 ), newline ) )
ELSE
INT yrday := mlengt[ gmonth ] + gday;
INT season := yrday OVER 73;
INT day := yrday - ( season * 73 );
INT wkday := ( yrday - 1 ) MOD 5;
print( ( disday[ wkday ], ", DAY ", whole( day, -2 ), " OF ", disssn[ season ]
, " IN THE Y.O.L.D ", whole( gyear + 1166, 0 ), newline
)
);
IF day = 5 THEN print( ( "CELEBRATE ", holys[ season ], "DAY" ) )
ELIF day = 50 THEN print( ( "CELEBRATE ", holys0[ season ], "FLUX" ) )
FI
FI
END</syntaxhighlight>
{{out}}
<pre>
11/04/1167
PUNGENday, day 16 OF THE AFTERMATH IN THE Y.O.L.D 2333
 
08/15/2017
BOOMTIME, DAY 8 OF BUREAUCRACY IN THE Y.O.L.D 3183
 
12/06/2020
SETTING ORANGE, DAY 48 OF THE AFTERMATH IN THE Y.O.L.D 3186
 
07/12/1969
PUNGENday, DAY 47 OF CONFUSION IN THE Y.O.L.D 3135
 
07/05/2005
SWEETMORN, DAY 40 OF CONFUSION IN THE Y.O.L.D 3171
 
09/26/1995
PRICKLE-PRICKLE, DAY 50 OF BUREAUCRACY IN THE Y.O.L.D 3161
CELEBRATE BUREFLUX
 
11/30/2021
PRICKLE-PRICKLE, DAY 42 OF THE AFTERMATH IN THE Y.O.L.D 3187
</pre>
 
=={{header|ALGOL W}}==
{{Trans|MAD}}
Algol W doesn't have the array initialisation equivalent of MAD's VECTOR VALUES and also does not allow implicit declarations.
Algol W does not have I/O formsts or variable length strings in output, which makes this version somewhat longer.
<syntaxhighlight lang="algolw">BEGIN % DISCORDIAN DATE CALCULATION - TRANSLATION OF MAD %
INTEGER GREG, GMONTH, GDAY, GYEAR;
STRING(16) ARRAY HOLY5 ( 0 :: 4 );
STRING(16) ARRAY HOLY50 ( 0 :: 4 );
STRING(16) ARRAY DISDAY ( 0 :: 4 );
STRING(16) ARRAY DISSSN ( 0 :: 4 );
INTEGER ARRAY MLENGT ( 0 :: 12 );
INTEGER APOS;
STRING(1) SLASH1, SLASH2;
 
% WRITES A "$" TERMINATED STRING %
PROCEDURE WRITEONTEXT( STRING(16) VALUE TEXT ) ;
BEGIN
INTEGER TPOS;
TPOS := 0;
WHILE TPOS < 16 DO BEGIN
IF TEXT( TPOS // 1 ) = "$"
THEN TPOS := 32
ELSE WRITEON( TEXT( TPOS // 1 ) );
;
TPOS := TPOS + 1
END WHILE_TPOS_LT_16
END WRITEONTEXT;
 
APOS := 0;
FOR M := 0,0,31,59,90,120,151,181,212,243,273,304,334 DO BEGIN MLENGT(APOS) := M; APOS := APOS + 1 END;
HOLY5 (0) := "MUNG$";HOLY5 (1) := "MOJO$"; HOLY5 (2) := "SYA$"; HOLY5 (3) := "ZARA$"; HOLY5 (4) := "MALA$";
HOLY50(0) := "CHAO$";HOLY50(1) := "DISCO$";HOLY50(2) := "CONFU$";HOLY50(3) := "BURE$"; HOLY50(4) := "AF$";
DISDAY(0) := "SWEETMORN$"; DISDAY(1) := "BOOMTIME$"; DISDAY(2) := "PUNGENDAY$";
DISDAY(3) := "PRICKLE-PRICKLE$"; DISDAY(4) := "SETTING ORANGE$";
DISSSN(0) := "CHAOS$"; DISSSN(1) := "DISCORD$"; DISSSN(2) := "CONFUSION$";
DISSSN(3) := "BUREAUCRACY$"; DISSSN(4) := "THE AFTERMATH$";
 
% INPUT DATE SHOULD CONTAIN MM/DD/YYYY IN GREGORIAN CALENDAR %
READ( GMONTH, SLASH1, GDAY, SLASH2, GYEAR );
IF GMONTH = 2 AND GDAY = 29
THEN WRITE( I_W := 4, S_W := 0, "SAINT TIB'S DAY IN THE Y.O.L.D. ", GYEAR + 1166 )
ELSE BEGIN
INTEGER YRDAY, SEASON, DAY, WKDAY;
YRDAY := MLENGT(GMONTH)+GDAY;
SEASON := YRDAY DIV 73;
DAY := YRDAY-SEASON*73;
WKDAY := (YRDAY-1) REM 5;
WRITEONTEXT( DISDAY(WKDAY) );
WRITEON( S_W := 0, ", DAY ", I_W := 2, DAY, " OF " );
WRITEONTEXT( DISSSN(SEASON) );
WRITEON( S_W := 0, " IN THE Y.O.L.D ", I_W := 4, GYEAR + 1166 );
IF DAY = 5 THEN BEGIN
WRITE( "CELEBRATE " );WRITEONTEXT( HOLY5(SEASON) ); WRITEON( "DAY" )
END
ELSE IF DAY = 50 THEN BEGIN
WRITE( "CELEBRATE " );WRITEONTEXT( HOLY50(SEASON) ); WRITEON( "FLUX" )
END IF_FAY_EQ_5__DAY_EQ_50
END
END.</syntaxhighlight>
{{out}}
<pre>
08/15/2017
BOOMTIME, DAY 8 OF BUREAUCRACY IN THE Y.O.L.D 3183
 
12/06/2020
SETTING ORANGE, DAY 48 OF THE AFTERMATH IN THE Y.O.L.D 3186
 
07/12/1969
PUNGENDAY, DAY 47 OF CONFUSION IN THE Y.O.L.D 3135
 
01/05/2005
SETTING ORANGE, DAY 5 OF CHAOS IN THE Y.O.L.D 3171
CELEBRATE MUNGDAY
 
09/26/1995
PRICKLE-PRICKLE, DAY 50 OF BUREAUCRACY IN THE Y.O.L.D 3161
CELEBRATE BUREFLUX
 
</pre>
 
=={{header|AppleScript}}==
 
<langsyntaxhighlight lang="applescript">on gregorianToDiscordian(inputDate) -- Input: AppleScript date object.
(* Rules:
Discordian weeksyears haveare fivealigned days eachwith, and always start at the beginning of the year. There are seventy-three in a year. (73same *length 5as, =Gregorian 365years.)
DiscordianEach seasonshas have73 seventy5-threeday daysweeks each.and There5 are73-day fiveseasons. of(73 them* in5 a= year365.)
The first day of a Discordian year is also that of its first week and first season.
In leap years, an extra day called "St. Tib's Day" is inserted between days 59 and 60, the same slot as the Gregorian 29th February. It's considered to be outside the Discordian week and season, so the day after it is Setting Orange, Chaos 60, not Sweetmorn, Chaos 61. Discordian dates always correspond to particular Gregorian dates.
In leap years, an extra day called "St. Tib's Day", is inserted between days 59 and 60.
Year 1 YOLD is 1166 BC.
It's considered to be outside the calendar, so the day after it is Setting Orange, Chaos 60,
This handler is only guaranteed for AD Gregorian dates and it's the calling process's responsibility to convert any user text input from the user's format to an AS date object.
Sincenot theSweetmorn, DiscordianChaos calendar61. Year 1 YOLD is an American1166 inventionBC, but this handler's outputtakes isan inAS thedate US style: "Weekday, Season day, year".object
as its input and is only good for AD Gregorian dates. Since the Discordian calendar's an
American invention, the output here's in the US style: "Weekday, Season day, year".
*)
-- Calculate the input date's day-of-year number.
copy inputDate to startOfYear
Line 741 ⟶ 965:
end gregorianToDiscordian
 
set gregorianDateASDate to (current date)'s date string
set ASDategregorianDate to ASDate's date gregorianDatestring
set discordianDate to gregorianToDiscordian(ASDate)
return {Gregorian:gregorianDate, Discordian:discordianDate}</langsyntaxhighlight>
 
{{output}}
<presyntaxhighlight lang="applescript">{Gregorian:"TuesdaySaturday 255 FebruaryDecember 2020", Discordian:"SweetmornPrickle-Prickle, ChaosThe Aftermath 5647, 3186"}</presyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# DDATE.AWK - Gregorian to Discordian date contributed by Dan Nielsen
# syntax: GAWK -f DDATE.AWK [YYYYMMDD | YYYY-MM-DD | MM-DD-YYYY | DDMMMYYYY | YYYY] ...
Line 849 ⟶ 1,073:
errors++
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 864 ⟶ 1,088:
{{trans|PowerBASIC}}
 
<langsyntaxhighlight lang="qbasic">#INCLUDE "datetime.bi"
 
DECLARE FUNCTION julian(AS DOUBLE) AS INTEGER
Line 914 ⟶ 1,138:
NEXT
FUNCTION = tmp + DAY(d)
END FUNCTION</langsyntaxhighlight>
{{out}}
<pre>"Discordian date.exe" 19-10-2015
Line 921 ⟶ 1,145:
=={{header|Batch File}}==
{{works with|Windows XP Service Pack 3}}
<langsyntaxhighlight lang="dos">@echo off
goto Parse
 
Line 1,098 ⟶ 1,322:
 
:End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,137 ⟶ 1,361:
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"DATELIB"
PRINT "01/01/2011 -> " FNdiscordian("01/01/2011")
Line 1,174 ⟶ 1,398:
ENDIF
= Weekday$(day% MOD 5) + ", " + STR$(day% MOD 73 + 1) + " " + \
\ Season$(day% DIV 73) + ", YOLD " + STR$(year% + 1166)</langsyntaxhighlight>
{{Out}}
<pre>
Line 1,195 ⟶ 1,419:
Reads the date to convert from stdin as three separate numeric inputs (year, month, and day).
 
<langsyntaxhighlight lang="befunge">0" :raeY">:#,_&>\" :htnoM">:#,_&>04p" :yaD">:#,_$&>55+,1-:47*v
v"f I".+1%,,,,"Day I":$_:#<0#!4#:p#-4#1g4-#0+#<<_v#!*!-2g40!-<
>"o",,,/:5+*66++:4>g#<:#44#:9#+*#1-#,_$$0 v_v#!< >$ 0 "yaD " v
@,+55.+*+92"j"$_,#!>#:<", in the YOLD"*84 <.>,:^ :"St. Tib's"<
$# #"#"##"#"Chaos$Discord$Confusion$Bureaucracy$The Aftermath$</langsyntaxhighlight>
 
{{out}} (multiple runs)
Line 1,224 ⟶ 1,448:
For the source code of <code>ddate</code> in util-linux package, see [[http://jubal.westnet.com/hyperdiscordia/ddate.html]].
 
<langsyntaxhighlight Clang="c">#include <stdlib.h>
#include <stdio.h>
#include <time.h>
Line 1,295 ⟶ 1,519:
return 0;
}</langsyntaxhighlight>
 
Demonstration:
Line 1,316 ⟶ 1,540:
Prickle-Prickle, Chaos 4, YOLD 3182</pre>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
public static class DiscordianDate
Line 1,371 ⟶ 1,595:
}
 
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,393 ⟶ 1,617:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <iostream>
#include <algorithm>
Line 1,480 ⟶ 1,704:
return 0;
}
</syntaxhighlight>
</lang>
{{out}}<pre>
Enter a date (dd mm yyyy) or 0 to quit: 19 10 2015
Line 1,502 ⟶ 1,726:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(require '[clj-time.core :as tc])
 
(def seasons ["Chaos" "Discord" "Confusion" "Bureaucracy" "The Aftermath"])
Line 1,524 ⟶ 1,748:
(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))))</langsyntaxhighlight>
 
{{out}}
Line 1,540 ⟶ 1,764:
"Setting Orange, The Aftermath 73, YOLD 3179"</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">% This program needs to be merged with PCLU's "useful.lib",
% so it can use get_argv to read the command line.
%
% pclu -merge $CLUHOME/lib/useful.lib -compile cmdline.clu
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Represent a day in the Discordian calendar %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
eris_date = cluster is from_greg_y_m_d,
from_date,
get_year,
get_day,
get_season,
get_weekday,
get_day_name,
get_holyday,
get_format
greyface = 1166
% A Discordian day is either St. Tib's day
% or a day in a season
season_day = struct[season, day: int]
eris_day = oneof[st_tibs: null, season_day: season_day]
% A Discordian date is a day in a year
rep = struct[year: int, day: eris_day]
% Offset of each Gregorian month in a non-leap year
own month_offset: sequence[int] := sequence[int]$[
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
]
% Length of each Gregorian month in a non-leap year
own month_length: sequence[int] := sequence[int]$[
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
]
own week_days: sequence[string] := sequence[string]$[
"Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle",
"Setting Orange"
]
own seasons: sequence[string] := sequence[string]$[
"Chaos", "Discord", "Confusion", "Bureacuracy",
"The Aftermath"
]
own apostle_holydays: sequence[string] := sequence[string]$[
"Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"
]
own season_holydays: sequence[string] := sequence[string]$[
"Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"
]
% Check if a Gregorian year is a leap year
is_leap = proc (year: int) returns (bool)
if year // 4 ~= 0 then return(false)
elseif year // 100 ~= 0 then return(true)
elseif year // 400 ~= 0 then return(false)
else return(true)
end
end is_leap
% Convert a Gregorian date to a Discordian date
from_greg_y_m_d = proc (year, month, day: int)
returns (cvt) signals (invalid)
% Make sure the month is valid
if month<1 cor month>12 then signal invalid end
% Saint Tib's Day?
if month=2 cand day=29 then
% Only valid in leap years
if ~is_leap(year) then signal invalid end
return(rep${year: year+greyface, day: eris_day$make_st_tibs(nil)})
end
% If not, make sure the day of the month is valid
if day<1 cor day>month_length[month] then signal invalid end
% The Discordian calendar doesn't consider Saint Tib's Day
% part of a season, so we can use the day number for a non-leap
% year even in a leap year
year_day: int := (day + month_offset[month]) - 1
sd: season_day := season_day${
season: year_day / 73 + 1,
day: year_day // 73 + 1
}
return(rep${year: year+greyface,
day: eris_day$make_season_day(sd)})
end from_greg_y_m_d
% Convert a CLU 'date' object to a Discordian date (ignoring the time)
from_date = proc (d: date) returns (cvt) signals (invalid)
return(down(from_greg_y_m_d(d.year, d.month, d.day)))
resignal invalid
end from_date
% Retrieve year, season, day, weekday number
get_year = proc (d: cvt) returns (int) return(d.year) end get_year
get_day = proc (d: cvt) returns (int) signals (st_tibs)
tagcase d.day
tag st_tibs: signal st_tibs
tag season_day (s: season_day): return(s.day)
end
end get_day
get_season = proc (d: cvt) returns (int) signals (st_tibs)
tagcase d.day
tag st_tibs: signal st_tibs
tag season_day (s: season_day): return(s.season)
end
end get_season
get_weekday = proc (d: cvt) returns (int) signals (st_tibs)
day: int := up(d).day resignal st_tibs
season: int := up(d).season resignal st_tibs
weekday: int := ( (season-1)*73 + (day-1) ) // 5 + 1
return( weekday )
end get_weekday
% Retrieve formatted day in year
get_day_name = proc (d: cvt) returns (string)
begin
fmt: stream := stream$create_output()
stream$puts(fmt, week_days[up(d).weekday])
stream$puts(fmt, ", day " || int$unparse(up(d).day))
stream$puts(fmt, " of " || seasons[up(d).season])
return(stream$get_contents(fmt))
end except when st_tibs:
return("St. Tib's Day")
end
end get_day_name
% Retrieve holyday name if there is one
get_holyday = proc (d: cvt) returns (string) signals (no_holyday)
begin
if up(d).day = 5 then return(apostle_holydays[up(d).season])
elseif up(d).day = 50 then return(season_holydays[up(d).season])
else signal no_holyday
end
end except when st_tibs:
signal no_holyday % St. Tib's Day is not a normal holyday
end
end get_holyday
% Retrieve long format
get_format = proc (d: cvt) returns (string)
fmt: stream := stream$create_output()
stream$puts(fmt, up(d).day_name)
stream$puts(fmt, " in the YOLD ")
stream$puts(fmt, int$unparse(up(d).year))
stream$puts(fmt, ": celebrate " || up(d).holyday) except when no_holyday: end
return(stream$get_contents(fmt))
end get_format
end eris_date
 
% Parse a date string (MM/DD/YYYY) and return a date object
parse_date = proc (s: string) returns (date) signals (bad_format)
begin
parts: array[int] := array[int]$[]
while true do
slash: int := string$indexc('/', s)
if slash=0 then
array[int]$addh(parts, int$parse(s))
break
else
array[int]$addh(parts, int$parse(string$substr(s, 1, slash-1)))
s := string$rest(s, slash+1)
end
end
if array[int]$size(parts) ~= 3 then signal bad_format end
return(date$create(parts[2], parts[1], parts[3], 0, 0, 0))
end resignal bad_format
end parse_date
 
% Read date(s) from the command line, or use the current date,
% and convert to the Discordian date
start_up = proc ()
po: stream := stream$primary_output()
args: sequence[string] := get_argv()
dates: array[date] := array[date]$[]
if sequence[string]$empty(args) then
% No argument - use today's date
stream$puts(po, "Today is ")
array[date]$addh(dates, now())
else
% There are argument(s) - parse each of them
for arg: string in sequence[string]$elements(args) do
array[date]$addh(dates, parse_date(arg))
end
end
% Convert all dates
for d: date in array[date]$elements(dates) do
stream$putl(po, eris_date$from_date(d).format)
end
end start_up</syntaxhighlight>
{{out}}
<pre>$ ./ddate
Today is Boomtime, day 45 of The Aftermath in the YOLD 3187
 
$ ./ddate 4/27/2020 9/26/1995 2/29/1996 7/22/2011 1/5/2005
Boomtime, day 44 of Discord in the YOLD 3186
Prickle-Prickle, day 50 of Bureacuracy in the YOLD 3161: celebrate Bureflux
St. Tib's Day in the YOLD 3162
Pungenday, day 57 of Confusion in the YOLD 3177
Setting Orange, day 5 of Chaos in the YOLD 3171: celebrate Mungday</pre>
=={{header|D}}==
 
<langsyntaxhighlight lang="d">import std.stdio, std.datetime, std.conv, std.string;
immutable seasons = ["Chaos", "Discord", "Confusion",
Line 1,621 ⟶ 2,057:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>$ ./ddate 20100722 20120228 20120229 20120301 20100105 20110503 20151019 00000101 -11660101
Line 1,633 ⟶ 2,069:
Sweetmorn, day 1 of Chaos in the YOLD 1166
Sweetmorn, day 1 of Chaos in the YOLD 0</pre>
 
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| System.DateUtils}}
{{Trans|D}} Partial translation of D.
<syntaxhighlight lang="delphi">
program Discordian_date;
 
{$APPTYPE CONSOLE}
 
uses
System.SysUtils,
System.DateUtils;
 
type
TDateTimeHelper = record helper for TDateTime
const
seasons: array of string = ['Chaos', 'Discord', 'Confusion', 'Bureaucracy',
'The Aftermath'];
weekday: array of string = ['Sweetmorn', 'Boomtime', 'Pungenday',
'Prickle-Prickle', 'Setting Orange'];
apostle: array of string = ['Mungday', 'Mojoday', 'Syaday', 'Zaraday', 'Maladay'];
holiday: array of string = ['Chaoflux', 'Discoflux', 'Confuflux',
'Bureflux', 'Afflux'];
function DiscordianDate(): string;
end;
 
{ TDateTimeHelper }
 
function TDateTimeHelper.DiscordianDate: string;
var
isLeapYear: boolean;
begin
isLeapYear := IsInLeapYear(self);
var dYear := (YearOf(self) + 1166).ToString;
if isLeapYear and (MonthOf(self) = 2) and (dayof(self) = 29) then
exit('St. Tib''s Day, in the YOLD ' + dYear);
 
var doy := DayOfTheYear(self);
if isLeapYear and (doy >= 60) then
doy := doy - 1;
 
var dsDay := doy mod 73;
 
if dsDay = 0 then
dsDay := 73;
 
if dsDay = 5 then
exit(apostle[doy div 73] + ', in the YOLD ' + dYear);
 
if dsDay = 50 then
exit(holiday[doy div 73] + ', in the YOLD ' + dYear);
 
var dSeas: string;
 
if (doy mod 73) = 0 then
dSeas := seasons[(doy - 1) div 73]
else
dSeas := seasons[doy div 73];
 
var dWday := weekday[(doy - 1) mod 5];
 
Result := format('%s, day %d of %s in the YOLD %s', [dWday, dsDay, dSeas, dYear]);
 
end;
 
procedure Test();
begin
Assert(EncodeDate(2010, 7, 22).DiscordianDate =
'Pungenday, day 57 of Confusion in the YOLD 3176');
Assert(EncodeDate(2012, 2, 28).DiscordianDate =
'Prickle-Prickle, day 59 of Chaos in the YOLD 3178');
Assert(EncodeDate(2012, 2, 29).DiscordianDate = 'St. Tib''s Day, in the YOLD 3178');
Assert(EncodeDate(2012, 3, 1).DiscordianDate =
'Setting Orange, day 60 of Chaos in the YOLD 3178');
Assert(EncodeDate(2010, 1, 5).DiscordianDate = 'Mungday, in the YOLD 3176');
Assert(EncodeDate(2011, 5, 3).DiscordianDate = 'Discoflux, in the YOLD 3177');
writeln('OK');
end;
 
var
dt: TDateTime;
i: Integer;
 
begin
if ParamCount = 0 then
begin
writeln(now.DiscordianDate);
readln;
halt;
end;
 
for i := 1 to ParamCount do
begin
if not TryStrToDate(ParamStr(i), dt) then
Continue;
writeln(dt.DiscordianDate);
end;
 
readln;
end.</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
seasons$[] = [ "Chaos" "Discord" "Confusion" "Bureaucracy" "The Aftermath" ]
weekday$[] = [ "Sweetmorn" "Boomtime" "Pungenday" "Prickle-Prickle" "Setting Orange" ]
apostle$[] = [ "Mungday" "Mojoday" "Syaday" "Zaraday" "Maladay" ]
holiday$[] = [ "Chaoflux" "Discoflux" "Confuflux" "Bureflux" "Afflux" ]
#
func leap x .
return if x mod 400 = 0 or x mod 4 = 0 and x mod 100 <> 0
.
func day_of_year y m d .
days[] = [ 31 28 31 30 31 30 31 31 30 31 30 31 ]
repeat
m -= 1
until m = 0
d += days[m]
if m = 2 and leap y = 1
d += 1
.
.
return d
.
func$ ddate y m d .
doy = day_of_year y m d
dyear = y + 1166
if leap y = 1 and m = 2 and d = 29
return "St. Tib's Day, in the YOLD " & dyear
.
if leap y = 1 and doy >= 60
doy -= 1
.
dsday = doy mod1 73
dseason = doy div1 73
r$ = weekday$[doy mod1 5] & ", day " & dsday & " of " & seasons$[dseason]
r$ &= " in the YOLD " & dyear & "."
if dsday = 5
r$ &= " Celebrate " & apostle$[dseason] & "!"
elif dsday = 50
r$ &= " Celebrate " & holiday$[dseason] & "!"
.
return r$
.
proc show d$ . .
a[] = number strsplit d$ "-"
write d$ & " --> "
print ddate a[1] a[2] a[3]
.
show "2016-01-05"
show "2016-02-28"
show "2016-02-29"
show "2016-03-01"
show "2016-12-31"
show "2025-03-19"
show substr timestr systime 1 10
</syntaxhighlight>
 
=={{header|Euphoria}}==
{{trans|D}}
<langsyntaxhighlight lang="euphoria">function isLeapYear(integer year)
return remainder(year,4)=0 and remainder(year,100)!=0 or remainder(year,400)=0
end function
Line 1,694 ⟶ 2,287:
today = date()
today[YEAR] += 1900
puts(1, discordianDate(today))</langsyntaxhighlight>
 
=={{header|F Sharp|F#}}==
 
<langsyntaxhighlight lang="fsharp">open System
 
let seasons = [| "Chaos"; "Discord"; "Confusion"; "Bureaucracy"; "The Aftermath" |]
Line 1,723 ⟶ 2,316:
|> Seq.iter(fun (s,d) -> printfn "%s is %s" s (ddate d))
0
</syntaxhighlight>
</lang>
{{out}}
<pre>2012-02-28 is Chaos 59, 3178 YOLD
Line 1,732 ⟶ 2,325:
2015-10-20 is The Aftermath 1, 3181 YOLD</pre>
 
=={{header|FORTRANFortran}}==
<syntaxhighlight lang="fortran">
<lang FORTRAN>
program discordianDate
implicit none
Line 1,932 ⟶ 2,525:
end if
end function Pleapyear
</syntaxhighlight>
</lang>
<pre>
compiled as ddate.
Line 1,945 ⟶ 2,538:
Celebrate for today is St. Tibbs Day in the YOLD 3186
</pre>
 
 
=={{header|FreeBASIC}}==
{{trans|BASIC}}
<langsyntaxhighlight lang="freebasic">#Include "datetime.bi"
 
meses:
Line 2,005 ⟶ 2,597:
cDiscordiano("15/07/2019")
cDiscordiano("19/03/2025")
Sleep</langsyntaxhighlight>
{{out}}
<pre>
Line 2,024 ⟶ 2,616:
=={{header|Go}}==
A package modeled after the time package in the Go standard library
<langsyntaxhighlight lang="go">package ddate
 
import (
Line 2,156 ⟶ 2,748:
}
return
} </langsyntaxhighlight>
Example program using above package
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,200 ⟶ 2,792:
fmt.Fprintf(os.Stderr, "usage: %s [+format] [day month year]\n", os.Args[0])
os.Exit(1)
}</langsyntaxhighlight>
{{Out}}
<pre>
Line 2,211 ⟶ 2,803:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Time (isLeapYear)
import Data.Time.Calendar.MonthDay (monthAndDayToDayOfYear)
import Text.Printf (printf)
Line 2,254 ⟶ 2,846:
weekday = toEnum $ dayOfYear `mod` 5
season = toEnum $ dayOfYear `div` 73
dayOfSeason = 1 + dayOfYear `mod` 73</langsyntaxhighlight>
 
Examples:
 
<langsyntaxhighlight lang="haskell">test = mapM_ display dates
where
display d = putStr (show d ++ " -> ") >> print (fromYMD d)
Line 2,268 ⟶ 2,860:
,(2010,9,2)
,(2010,12,31)
,(2011,1,1)]</langsyntaxhighlight>
 
<pre>λ> test
Line 2,293 ⟶ 2,885:
=={{header|Icon}} and {{header|Unicon}}==
This version is loosely based on a modified translation of the original ddate.c and like the original the leap year functionality is Julian not Gregorian.
<langsyntaxhighlight Iconlang="icon">link printf
 
procedure main()
Line 2,347 ⟶ 2,939:
ddate.sday || " of " || seasons[ddate.season])) ||
" in the YOLD " || ddate.year
end</langsyntaxhighlight>
 
{{Out}}
Line 2,364 ⟶ 2,956:
 
=={{header|J}}==
<langsyntaxhighlight lang="j">require'dates'
leap=: _1j1 * 0 -/@:= 4 100 400 |/ {.@]
bs=: ((#:{.) + 0 j. *@[ * {:@]) +.
disc=: ((1+0 73 bs[ +^:(58<]) -/@todayno@(,: 1 1,~{.)@]) ,~1166+{.@])~ leap</langsyntaxhighlight>
 
Example use:
 
<syntaxhighlight lang="text"> disc 2012 2 28
3178 1 59
disc 2012 2 29
Line 2,386 ⟶ 2,978:
3181 4 73
disc 2000 3 13
3166 1 72j1</langsyntaxhighlight>
 
see [[Talk:Discordian_date|talk page]]. But, in essence, this version uses season ordinals with a single imaginary day after the 59th of the first season, on leap years. This is implemented so that that imaginary day has been passed for all remaining days of a leap year.
Line 2,392 ⟶ 2,984:
=={{header|Java}}==
 
<langsyntaxhighlight lang="java">import java.util.Calendar;
import java.util.GregorianCalendar;
 
Line 2,451 ⟶ 3,043:
assert (discordianDate(new GregorianCalendar(y, m, d)).equals(result));
}
}</langsyntaxhighlight>
 
{{Out}}
Line 2,458 ⟶ 3,050:
=={{header|JavaScript}}==
 
<langsyntaxhighlight lang="javascript">
/**
* All Hail Discordia! - this script prints Discordian date using system date.
Line 2,577 ⟶ 3,169:
 
module.exports = discordianDate;
</syntaxhighlight>
</lang>
 
Example use:
 
<langsyntaxhighlight lang="javascript">
console.log(discordianDate(new Date(Date.now())));
"Boomtime, the 2nd day of Chaos in the YOLD 3183"
</syntaxhighlight>
</lang>
 
look at [http://www.cs.cmu.edu/~tilt/principia/body.html#applecorps calendar];
Line 2,590 ⟶ 3,182:
 
=={{header|JotaCode}}==
<langsyntaxhighlight lang="jotacode">@print(
"Today is ",
@let(1,@add(@switch(@time("mon"),
Line 2,624 ⟶ 3,216:
", YOLD ",
@add(@time("year"),3066))
)),".")</langsyntaxhighlight>
 
=={{header|jq}}==
'''Adapted from [[#Wren]]'''
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''
 
'''Also works with fq, a Go implementation of a large subset of jq'''
<syntaxhighlight lang=jq>
### Gregorian calendar
def isLeapYear(y):
y%4 == 0 and ((y%100 != 0) or (y%400 == 0));
 
### Discordian calendar
def seasons: ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"];
 
def weekdays: ["Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"];
 
def apostles: ["Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"];
 
def holidays: ["Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"];
 
# Input: {year, dayOfYear}
def discordian(date):
date.year as $y
| " in the YOLD \($y + 1166)." as $yold
| { doy: date.dayOfYear, holyday: ""}
| if isLeapYear($y) and (.doy == 60) then "St. Tib's Day" + $yold
else if isLeapYear($y) and (.doy > 60) then .doy += -1 else . end
| .doy += -1
| .seasonDay = ((.doy % 73) + 1)
| .seasonNr = ((.doy/73)|floor)
| .weekdayNr = .doy % 5
| if .seasonDay == 5 then .holyday = " Celebrate \(apostles[.seasonNr])!"
elif .seasonDay == 50 then .holyday = " Celebrate \(holidays[.seasonNr])!"
else .
end
| .season = seasons[.seasonNr]
| .dow = weekdays[.weekdayNr]
| "\(.dow), day \(.seasonDay) of \(.season)\($yold)\(.holyday)"
end ;
 
def dates: [
"2010-01-01",
"2010-01-05",
"2011-02-19",
"2012-02-28",
"2012-02-29",
"2012-03-01",
"2013-03-19",
"2014-05-03",
"2015-05-31",
"2016-06-22",
"2016-07-15",
"2017-08-12",
"2018-09-19",
"2018-09-26",
"2019-10-24",
"2020-12-08",
"2020-12-31"
];
 
dates[]
| (strptime("%Y-%m-%d")
| {year: .[0], dayOfYear: (1 + .[-1])}) as $dt
| "\(.) = \(discordian($dt))"
</syntaxhighlight>
{{output}}
As for [[#Wren|Wren]].
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Dates
 
function discordiandate(year::Integer, month::Integer, day::Integer)
Line 2,662 ⟶ 3,322:
@show discordiandate(2017, 08, 15)
@show discordiandate(1996, 02, 29)
@show discordiandate(1996, 02, 19)</langsyntaxhighlight>
 
{{out}}
Line 2,671 ⟶ 3,331:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">import java.util.Calendar
import java.util.GregorianCalendar
 
Line 2,725 ⟶ 3,385:
test(2011, 4, 3, "Discoflux, in the YOLD 3177")
test(2015, 9, 19, "Boomtime, day 73 of Bureaucracy in the YOLD 3181")
}</langsyntaxhighlight>
 
=={{header|MAD}}==
 
<syntaxhighlight lang="mad"> R DISCORDIAN DATE CALCULATION
R
R PUNCH CARD SHOULD CONTAIN -
R MM/DD/YYYY
R IN GREGORIAN CALENDAR
NORMAL MODE IS INTEGER
VECTOR VALUES MLENGT =
0 0,0,31,59,90,120,151,181,212,243,273,304,334
VECTOR VALUES TIBS =
0 $31HSAINT TIBS DAY IN THE Y.O.L.D. ,I4*$
VECTOR VALUES DISDAT =
0 $C,6H, DAY ,I2,S1,3HOF ,C,S1,16HIN THE Y.O.L.D. ,I4*$
VECTOR VALUES DISDAY = $SWEETMORN$, $BOOMTIME$,
0 $PUNGENDAY$, $PRICKLE-PRICKLE$, $SETTING ORANGE$
VECTOR VALUES DISSSN = $CHAOS$, $DISCORD$,
0 $CONFUSION$, $BUREAUCRACY$, $THE AFTERMATH$
VECTOR VALUES CLDAY = $10HCELEBRATE ,C,3HDAY*$
VECTOR VALUES CLFLUX = $10HCELEBRATE ,C,4HFLUX*$
VECTOR VALUES HOLY5 = $MUNG$,$MOJO$,$SYA$,$ZARA$,$MALA$
VECTOR VALUES HOLY50 = $CHAO$,$DISCO$,$CONFU$,$BURE$,$AF$
READ FORMAT GREG,GMONTH,GDAY,GYEAR
VECTOR VALUES GREG = $2(I2,1H/),I4*$
 
WHENEVER GMONTH.E.2 .AND. GDAY.E.29
PRINT FORMAT TIBS, GYEAR + 1166
OTHERWISE
YRDAY = MLENGT(GMONTH)+GDAY
SEASON = YRDAY/73
DAY = YRDAY-SEASON*73
WKDAY = (YRDAY-1)-(YRDAY-1)/5*5
PRINT FORMAT DISDAT, DISDAY(WKDAY), DAY,
0 DISSSN(SEASON), GYEAR + 1166
WHENEVER DAY.E.5
PRINT FORMAT CLDAY, HOLY5(SEASON)
OR WHENEVER DAY.E.50
PRINT FORMAT CLFLUX, HOLY50(SEASON)
END OF CONDITIONAL
END OF CONDITIONAL
END OF PROGRAM</syntaxhighlight>
 
{{out}}
 
<pre>01/05/2005
SETTING ORANGE, DAY 5 OF CHAOS IN THE Y.O.L.D. 3171
CELEBRATE MUNGDAY
 
09/26/1995
PRICKLE-PRICKLE, DAY 50 OF BUREAUCRACY IN THE Y.O.L.D. 3161
CELEBRATE BUREFLUX
 
02/29/1996
SAINT TIBS DAY IN THE Y.O.L.D. 3162
 
12/05/2020
PRICKLE-PRICKLE, DAY 47 OF THE AFTERMATH IN THE Y.O.L.D. 3186</pre>
 
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">convertDiscordian := proc(year, month, day)
local days31, days30, daysThisYear, i, dYear, dMonth, dDay, seasons, week, dayOfWeek;
days31 := [1, 3, 5, 7, 8, 10, 12];
Line 2,764 ⟶ 3,488:
convertDiscordian (2016, 1, 1);
convertDiscordian (2016, 2, 29);
convertDiscordian (2016, 12, 31);</langsyntaxhighlight>
{{out}}
<pre>
Line 2,773 ⟶ 3,497:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">DiscordianDate[y_, m_, d_] := Module[{year = ToString[y + 1166], month = m, day = d},
 
DMONTHS = {"Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"};
Line 2,787 ⟶ 3,511:
Print["Today is ", DDAYS[[Mod[dday,4] + 1]],", ",DMONTHS[[season+1]]," ",dday,", YOLD ",year]
];
]</langsyntaxhighlight>
{{Out}}
<pre>DiscordianDate[2012,2,28]
Line 2,797 ⟶ 3,521:
DiscordianDate[2012,3,1]
-> Today is Setting Orange, Chaos 60, YOLD 3178</pre>
 
=={{header|Nim}}==
We use a DateTime object as intermediate representation.
<syntaxhighlight lang="nim">import times, strformat
 
const
 
DiscordianOrigin = -1166
SaintTibsDay = "St. Tib’s Day"
 
type
 
Season = enum
sCha = (1, "Chaos"), sDis = "Discord", sCon = "Confusion",
sBur = "Bureaucracy", sAft = "The Aftermath"
 
ErisianWeekDay = enum
eSwe = "Sweetmorn", eBoo = "Boomtime", ePun = "Pungenday",
ePri = "Prickle-Prickle", eSet = "Setting Orange"
 
SeasonDayRange = range[1..73]
 
# Description of a discordian date.
DiscordianDate = object
year: int
yearday: YeardayRange
case isSaintTibsDay: bool
of false:
seasondayZero: int
seasonZero: int
weekday: ErisianWeekDay
else:
nil
 
#---------------------------------------------------------------------------------------------------
 
proc toDiscordianDate(gdate: DateTime): DiscordianDate =
## Convert a DateTime to a discordian date.
## All the time fields are ignored.
 
# Create the object.
result = DiscordianDate(isSaintTibsDay: gdate.isLeapDay)
 
# The yearday field is unchanged.
result.yearday = gdate.yearday
 
# The year is simply translated.
result.year = gdate.year - DiscordianOrigin
 
# For remaining fields, we must take in account leap years.
if not result.isSaintTibsDay:
var yearday = result.yearday
if gdate.year.isLeapYear and result.yearday > 59:
dec yearday
# Now, we have simply to use division and modulo using the corrected yearday.
result.seasonZero = yearday div SeasonDayRange.high
result.seasondayZero = yearday mod SeasonDayRange.high
result.weekday = ErisianWeekDay(yearday mod 5)
 
#---------------------------------------------------------------------------------------------------
 
proc `$`(date: DiscordianDate): string =
## Convert a discordian date to a string.
if date.isSaintTibsDay:
result = SaintTibsDay
else:
result = fmt"{date.weekday}, {Season(date.seasonZero + 1)} {date.seasondayZero + 1}"
result &= fmt", {date.year} YOLD"
 
#---------------------------------------------------------------------------------------------------
 
proc showDiscordianDate(year, month, day: Natural) =
## Show the discordian date corresponding to a gregorian date.
let gdate = initDateTime(year = year, month = Month(month), monthday = day,
hour = 0, minute = 0, second = 0)
echo gdate.format("YYYY-MM-dd"), ": ", $gdate.toDiscordianDate()
 
#———————————————————————————————————————————————————————————————————————————————————————————————————
 
showDiscordianDate(2100, 12, 31)
showDiscordianDate(2012, 02, 28)
showDiscordianDate(2012, 02, 29)
showDiscordianDate(2012, 03, 01)
showDiscordianDate(2010, 07, 22)
showDiscordianDate(2012, 09, 02)
showDiscordianDate(2012, 12, 31)</syntaxhighlight>
 
{{out}}
<pre>2100-12-31: Setting Orange, The Aftermath 73, 3266 YOLD
2012-02-28: Prickle-Prickle, Chaos 59, 3178 YOLD
2012-02-29: St. Tib’s Day, 3178 YOLD
2012-03-01: Setting Orange, Chaos 60, 3178 YOLD
2010-07-22: Pungenday, Confusion 57, 3176 YOLD
2012-09-02: Setting Orange, Bureaucracy 26, 3178 YOLD
2012-12-31: Setting Orange, The Aftermath 73, 3178 YOLD</pre>
 
=={{header|Pascal}}==
<syntaxhighlight lang="pascal">
<lang Pascal>
program ddate;
{
Line 2,959 ⟶ 3,778:
WriteLn(Eris);
end.
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,975 ⟶ 3,794:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use 5.010;
use strict;
use warnings;
Line 3,008 ⟶ 3,827:
say "$_ is " . ddate($_) for qw< 2010-07-22 2012-02-28 2012-02-29 2012-03-01 >;
</syntaxhighlight>
</lang>
{{out}}
<pre>2010-07-22 is Pungenday, the 57th day of Confusion in the YOLD 3176
Line 3,017 ⟶ 3,836:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>constant seasons = {"Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"}
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
constant weekday = {"Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"}
<span style="color: #008080;">constant</span> <span style="color: #000000;">seasons</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Chaos"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Discord"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Confusion"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Bureaucracy"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"The Aftermath"</span><span style="color: #0000FF;">},</span>
constant apostle = {"Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"}
<span style="color: #000000;">weekday</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Sweetmorn"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Boomtime"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Pungenday"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Prickle-Prickle"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Setting Orange"</span><span style="color: #0000FF;">},</span>
constant holiday = {"Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"}
<span style="color: #000000;">apostle</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Mungday"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Mojoday"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Syaday"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Zaraday"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Maladay"</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">holiday</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Chaoflux"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Discoflux"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Confuflux"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Bureflux"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Afflux"</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">discordianDate</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">dt</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dt</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">leap</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">is_leap_year</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">doy</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">day_of_year</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">dyear</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1166</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">leap</span> <span style="color: #008080;">and</span> <span style="color: #000000;">m</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">and</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">29</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">return</span> <span style="color: #008000;">"St. Tib's Day, in the YOLD "</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">dyear</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">leap</span> <span style="color: #008080;">and</span> <span style="color: #000000;">doy</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">60</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">doy</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">dsday</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">doy</span><span style="color: #0000FF;">,</span><span style="color: #000000;">73</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">dseason</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">doy</span><span style="color: #0000FF;">/</span><span style="color: #000000;">73</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">dsday</span><span style="color: #0000FF;">=</span><span style="color: #000000;">5</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">apostle</span><span style="color: #0000FF;">[</span><span style="color: #000000;">dseason</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">&</span> <span style="color: #008000;">", in the YOLD "</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">dyear</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">dsday</span><span style="color: #0000FF;">=</span><span style="color: #000000;">50</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">holiday</span><span style="color: #0000FF;">[</span><span style="color: #000000;">dseason</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">&</span> <span style="color: #008000;">", in the YOLD "</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">dyear</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">dseas</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">seasons</span><span style="color: #0000FF;">[</span><span style="color: #000000;">dseason</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">dwday</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">weekday</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">doy</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%s, day %d of %s in the YOLD %s"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">dwday</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dsday</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dseas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dyear</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #000080;font-style:italic;">-- test code</span>
function discordianDate(sequence dt)
string dyear, dseas, dwday
integer leap, doy, dsday,dseason
integer {y,m,d} = dt
dyear = sprintf("%d",y+1166)
leap = is_leap_year(y)
if leap and m=2 and d=29 then
return "St. Tib's Day, in the YOLD " & dyear
end if
<span style="color: #004080;">sequence</span> <span style="color: #000000;">dt</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">2015</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">}</span>
doy = day_of_year(y,m,d)-1
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
if leap and doy>=60 then
<span style="color: #004080;">atom</span> <span style="color: #000000;">oneday</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
doy -= 1
<span style="color: #7060A8;">set_timedate_formats</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"DD/MM/YYYY"</span><span style="color: #0000FF;">})</span>
end if
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">5</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dt</span><span style="color: #0000FF;">),</span><span style="color: #000000;">discordianDate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dt</span><span style="color: #0000FF;">)})</span>
dsday = remainder(doy,73)+1
<span style="color: #000000;">dt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">adjust_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">oneday</span><span style="color: #0000FF;">*</span><span style="color: #000000;">72</span><span style="color: #0000FF;">)</span>
dseason = floor(doy/73+1)
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dt</span><span style="color: #0000FF;">),</span><span style="color: #000000;">discordianDate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dt</span><span style="color: #0000FF;">)})</span>
if dsday=5 then
<span style="color: #000000;">dt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">adjust_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">oneday</span><span style="color: #0000FF;">)</span>
return apostle[dseason] & ", in the YOLD " & dyear
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
elsif dsday=50 then
<!--</syntaxhighlight>-->
return holiday[dseason] & ", in the YOLD " & dyear
end if
dseas = seasons[dseason]
dwday = weekday[remainder(doy,5)+1]
return sprintf("%s, day %d of %s in the YOLD %s", {dwday, dsday, dseas, dyear})
end function</lang>
test code
<lang Phix>sequence dt = {2015,1,1,0,0,0,0,0}
include timedate.e
atom oneday = timedelta(days:=1)
set_timedate_formats({"DD/MM/YYYY: "})
for i=1 to 5 do
?format_timedate(dt)&discordianDate(dt)
dt = adjust_timedate(dt,oneday*72)
?format_timedate(dt)&discordianDate(dt)
dt = adjust_timedate(dt,oneday)
end for</lang>
{{out}}
<pre>
Line 3,078 ⟶ 3,896:
 
 
<syntaxhighlight lang="php">
<lang PHP>
<?php
$Anerisia = array(31,28,31,30,31,30,31,31,30,31,30,31);
Line 3,161 ⟶ 3,979:
 
?>
</syntaxhighlight>
</lang>
 
{{Out}}
Line 3,179 ⟶ 3,997:
=={{header|PicoLisp}}==
{{trans|Python}}
<langsyntaxhighlight PicoLisplang="picolisp">(de disdate (Year Month Day)
(let? Date (date Year Month Day)
(let (Leap (date Year 2 29) D (- Date (date Year 1 1)))
Line 3,192 ⟶ 4,010:
(inc (% D 73))
", YOLD "
(+ Year 1166) ) ) ) ) )</langsyntaxhighlight>
 
=={{header|Pike}}==
Pike includes a Discordian calendar.
dates can be converted from any calendar to any other.
<langsyntaxhighlight Pikelang="pike">> Calendar.Discordian.now()->format_ext_ymd();
Result: "Pungenday, 59 Bureaucracy 3177"
> Calendar.Discordian.Day(Calendar.Day(2011,11,11))->format_ext_ymd();
Line 3,204 ⟶ 4,022:
Result: "Setting Orange, 23 The Aftermath 3177"
> Calendar.Day((Calendar.Discordian.Month()+1)->day(1));
Result: Day(Thu 20 Oct 2011)</langsyntaxhighlight>
 
=={{header|PL/M}}==
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<br>Based on:{{Trans|MAD}}...via Algol W
<syntaxhighlight lang="plm">
100H: /* DISCORDIAN DATE CALCULATION - TRANSLATION OF MAD (VIA ALGOL W) */
 
/* CP/M SYSTEM CALL AND I/O ROUTINES */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
 
/* COMMAND LINE */
DECLARE CL$ADDR LITERALLY '80H'; /* ADDRESS OF THE COMMAND LINE */
DECLARE CL$PTR ADDRESS; /* POINTER TO THE CURRENT COMMAND LINE CHAR */
DECLARE CL$CHAR BASED CL$PTR BYTE; /* CURRENT COMMAND LINE CHARACTER */
DECLARE CL$LEN ADDRESS; /* LENGTH OF THE COMMAND LINE */
 
/* INITIALISES THE COMMAND LINE VARIABLES */
CL$INIT: PROCEDURE;
CL$PTR = CL$ADDR;
CL$LEN = CL$CHAR;
CL$PTR = CL$PTR + 1;
END CL$INIT;
 
/* READS A NUMBER FROM THE COMMAND LINE, THE TERMINATOR IS IGNORED */
CL$NUMBER: PROCEDURE ADDRESS;
DECLARE N ADDRESS;
N = 0;
DO WHILE CL$PTR <= ( CL$ADDR + CL$LEN ) AND CL$CHAR = ' ';
CL$PTR = CL$PTR + 1;
END;
DO WHILE CL$PTR <= ( CL$ADDR + CL$LEN ) AND CL$CHAR >= '0'
AND CL$CHAR <= '9';
N = ( N * 10 ) + ( CL$CHAR - '0' );
CL$PTR = CL$PTR + 1;
END;
CL$PTR = CL$PTR + 1; /* SKIP THE CHARACTER THAT TERMINATED THE NUMBER */
RETURN N;
END CL$NUMBER;
 
/* TASK */
 
DECLARE HOLY5 ( 5 )ADDRESS;
DECLARE HOLY50 ( 5 )ADDRESS;
DECLARE DISDAY ( 5 )ADDRESS;
DECLARE DISSSN ( 5 )ADDRESS;
DECLARE MLENGT ( 13 )ADDRESS
INITIAL( 0, 0, 31, 59, 90, 120
, 151, 181, 212, 243, 273, 304, 334
);
HOLY5 (0) = .'MUNG$'; HOLY5 (1) = .'MOJO$'; HOLY5 (2) = .'SYA$';
HOLY5 (3) = .'ZARA$'; HOLY5 (4) = .'MALA$';
HOLY50(0) = .'CHAO$'; HOLY50(1) = .'DISCO$'; HOLY50(2) = .'CONFU$';
HOLY50(3) = .'BURE$'; HOLY50(4) = .'AF$';
DISDAY(0) = .'SWEETMORN$'; DISDAY(1) = .'BOOMTIME$';
DISDAY(2) = .'PUNGENDAY$'; DISDAY(3) = .'PRICKLE-PRICKLE$';
DISDAY(4) = .'SETTING ORANGE$';
DISSSN(0) = .'CHAOS$'; DISSSN(1) = .'DISCORD$'; DISSSN(2) = .'CONFUSION$';
DISSSN(3) = .'BUREAUCRACY$'; DISSSN(4) = .'THE AFTERMATH$';
 
/* GET THE GREGORIAN DATE FROM THE COMMAND LINE, NB: NO VALIDATION */
DECLARE ( GMONTH, GDAY, GYEAR ) ADDRESS; /* MUST BE IN MM/DD/YYYY FORMAT */
CALL CL$INIT;
GMONTH = CL$NUMBER; GDAY = CL$NUMBER; GYEAR = CL$NUMBER;
CALL PR$NUMBER( GMONTH );CALL PR$CHAR( '/' );CALL PR$NUMBER( GDAY );
CALL PR$CHAR( '/');CALL PR$NUMBER( GYEAR );CALL PR$NL;
 
/* CONVERT AND PRINT THE DATE */
IF GMONTH = 2 AND GDAY = 29
THEN DO;
CALL PR$STRING( .'SAINT TIB''S DAY IN THE Y.O.L.D. $' );
CALL PR$NUMBER( GYEAR + 1166 );
END;
ELSE DO;
DECLARE ( YRDAY, SEASON, DAY, WKDAY ) ADDRESS;
YRDAY = MLENGT(GMONTH)+GDAY;
SEASON = YRDAY / 73;
DAY = YRDAY-SEASON*73;
WKDAY = (YRDAY-1) MOD 5;
CALL PR$STRING( DISDAY(WKDAY) );
CALL PR$STRING( .', DAY $' );
CALL PR$NUMBER( DAY );
CALL PR$STRING( .' OF $' );
CALL PR$STRING( DISSSN(SEASON) );
CALL PR$STRING( .' IN THE Y.O.L.D $' );
CALL PR$NUMBER( GYEAR + 1166 );
IF DAY = 5 THEN DO;
CALL PR$NL;
CALL PR$STRING( .'CELEBRATE $' );
CALL PR$STRING( HOLY5(SEASON) );
CALL PR$STRING( .'DAY$' );
END;
ELSE IF DAY = 50 THEN DO;
CALL PR$NL;
CALL PR$STRING( .'CELEBRATE $' );
CALL PR$STRING( HOLY50(SEASON) );
CALL PR$STRING( .'FLUX$' );
END;
END;
CALL PR$NL;
 
EOF
</syntaxhighlight>
{{out}}
With the command line: <code>DISCORD 03/29/2023</code>:
<pre>
3/29/2023
PUNGENDAY, DAY 15 OF DISCORD IN THE Y.O.L.D 3189
</pre>
 
=={{header|PowerBASIC}}==
<langsyntaxhighlight lang="powerbasic">#COMPILE EXE
#DIM ALL
 
Line 3,271 ⟶ 4,213:
 
? result
END FUNCTION</langsyntaxhighlight>
 
=={{header|PowerShell}}==
{{works with|powershell|2}}
<langsyntaxhighlight lang="powershell">
function ConvertTo-Discordian ( [datetime]$GregorianDate )
{
Line 3,298 ⟶ 4,240:
ConvertTo-Discordian ([datetime]'2/29/2016')
ConvertTo-Discordian ([datetime]'12/8/2016')
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,308 ⟶ 4,250:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">% See https://en.wikipedia.org/wiki/Discordian_calendar
 
main:-
Line 3,387 ⟶ 4,329:
holy_day(3, 50, 'Bureflux').
holy_day(4, 5, 'Maladay').
holy_day(4, 50, 'Afflux').</langsyntaxhighlight>
 
{{out}}
Line 3,400 ⟶ 4,342:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">Procedure.s Discordian_Date(Y, M, D)
Protected DoY=DayOfYear(Date(Y,M,D,0,0,0)), Yold$=Str(Y+1166)
Dim S.s(4)
Line 3,413 ⟶ 4,355:
EndIf
ProcedureReturn S(DoY/73)+" "+Str(DoY%73)+", Yold "+Yold$
EndProcedure</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">import datetime, calendar
 
DISCORDIAN_SEASONS = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]
Line 3,433 ⟶ 4,375:
season, dday = divmod(day_of_year, 73)
return "%s %d, YOLD %d" % (DISCORDIAN_SEASONS[season], dday + 1, year + 1166)
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
{{trans|D}}
 
<langsyntaxhighlight lang="racket">#lang racket/base
;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;;; Derived from 'D' Implementation
Line 3,488 ⟶ 4,430:
(check-equal? (discordian/ymd 2010 1 5) "Mungday, in the YOLD 3176")
(check-equal? (discordian/ymd 2011 5 3) "Discoflux, in the YOLD 3177"))
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~FIN</langsyntaxhighlight>
 
{{Out}}
Line 3,497 ⟶ 4,439:
{{Works with|rakudo|2015-11-04}}
<!-- Hi ‎Grondilu! Keep up the good work! -->
<syntaxhighlight lang="raku" perl6line>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
Line 3,522 ⟶ 4,464:
 
say "$_ is {.&ddate}" for < 2010-07-22 2012-02-28 2012-02-29 2012-03-01 >;
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,530 ⟶ 4,472:
2012-03-01 is Setting Orange, the 60th day of Chaos in the YOLD 3178
</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
, <Numb <Arg 1>>: s.GY
, <Numb <Arg 2>>: s.GM
, <Numb <Arg 3>>: s.GD
, <DisDate s.GY s.GM s.GD>: {
True e.Desc = <Prout e.Desc>;
False = <Prout 'Invalid input'>;
};
};
 
DisDate {
s.GY 2 29, <IsLeapYear s.GY>: True =
True 'St. Tib\'s day in the YOLD ' <Symb <+ 1166 s.GY>>;
 
s.GY s.GM s.GD, <Compare s.GM 1>: '-' = False;
s.GY s.GM s.GD, <Compare s.GM 12>: '+' = False;
s.GY s.GM s.GD, <Compare s.GD 1>: '-' = False;
s.GY s.GM s.GD, <Compare s.GD <Item s.GM <MonthLength>>>: '+' = False;
 
s.GY s.GM s.GD,
<+ <Item s.GM <MonthOffset>> s.GD>: s.DOY,
<Divmod <- s.DOY 1> 73>: (s.DS1) s.DD1,
<+ s.DS1 1>: s.DS,
<+ s.DD1 1>: s.DD,
<+ <Mod <- s.DOY 1> 5> 1>: s.DWD,
 
<Item s.DWD <Weekday>>: (e.Weekday),
<Item s.DS <Seasons>>: (e.Season),
 
e.Weekday ', day ' <Symb s.DD> ' of '
e.Season ' in the YOLD ' <Symb <+ 1166 s.GY>>: e.Desc,
s.DD: {
5, <Item s.DS <Holy5>>: (e.H) = True e.Desc ': celebrate ' e.H;
50, <Item s.DS <Holy50>>: (e.H) = True e.Desc ': celebrate ' e.H;
s.X = True e.Desc;
};
};
 
Item {
1 t.I e.X = t.I;
s.N t.I e.X = <Item <- s.N 1> e.X>;
};
 
IsLeapYear {
s.GY, <Mod s.GY 4>: 0 = True;
s.GY, <Mod s.GY 100>: 0 = False;
s.GY, <Mod s.GY 400>: 0 = True;
s.GY = False;
};
 
MonthOffset { = 0 31 59 90 120 151 181 212 243 273 304 334; };
MonthLength { = 31 28 31 30 31 30 31 31 30 31 30 31; };
 
Weekday { = ('Sweetmorn') ('Boomtime') ('Pungenday')
('Prickle-Prickle') ('Setting Orange'); };
 
Seasons { = ('Chaos') ('Discord') ('Confusion') ('Bureaucracy')
('The Aftermath'); };
 
Holy5 { = ('Mungday') ('Mojoday') ('Syaday') ('Zaraday') ('Maladay'); };
Holy50 { = ('Chaoflux') ('Discoflux') ('Confuflux')
('Bureflux') ('Afflux'); };</syntaxhighlight>
{{out}}
<pre>$ refgo ddate 2010 7 22
Pungenday, day 57 of Confusion in the YOLD 3176
$ refgo ddate 2012 2 28
Prickle-Prickle, day 59 of Chaos in the YOLD 3178
$ refgo ddate 2012 2 29
St. Tib's day in the YOLD 3178
$ refgo ddate 2012 3 1
Setting Orange, day 60 of Chaos in the YOLD 3178
$ refgo ddate 2010 1 5
Setting Orange, day 5 of Chaos in the YOLD 3176: celebrate Mungday
$ refgo ddate 2011 5 3
Pungenday, day 50 of Discord in the YOLD 3177: celebrate Discoflux</pre>
 
=={{header|REXX}}==
Line 3,537 ⟶ 4,556:
 
If the Gregorian date is omitted or specified as an asterisk &nbsp; ('''*'''), &nbsp; the current date is used.
<langsyntaxhighlight lang="rexx">/*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 " " " " */
Line 3,570 ⟶ 4,589:
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.*/</langsyntaxhighlight>
{{out|input|text=&nbsp; when using the (various) following inputs of:}}
<pre>
Line 3,592 ⟶ 4,611:
Boomtime, Bureaucracy 73, 3181
Setting Orange, The Aftermath 73, 3266
</pre>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
≪ '''IF''' DUP2 R→C (29,2) == '''THEN''' DROP2 0
'''ELSE'''
'''IF''' DUP 1 == '''THEN''' DROP
'''ELSE'''
{ 31 59 90 120 151 181 212 243 273 304 334 }
SWAP 1 - GET +
'''END END'''
≫ ‘'''DQtm'''’ STO
≪ 1166 + ROT ROT '''DQtm'''
'''IF''' DUP '''THEN'''
1 - { "Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange" }
OVER 5 MOD 1 + GET ", " +
SWAP { "Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath" }
OVER 73 / IP RND 1 + GET " " +
SWAP 73 MOD 1 + →STR + +
'''ELSE''' DROP "St. Tib's Day" '''END'''
", YoLD " + SWAP →STR +
≫ ‘'''DDATE'''’ STO
{{in}}
<pre>
19,1,2023 DDATE
29,2,2024 DDATE
25,12,800 DDATE
</pre>
{{out}}
<pre>
3: "Prickle-Prickle, Chaos 19, YoLD 3189"
2: "St. Tib's Day, YoLD 3190"
1: "Prickle-Prickle, The Aftermath 67, YoLD 1966"
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require 'date'
 
class DiscordianDate
Line 3,639 ⟶ 4,692:
%Q{#{@st_tibs ? "St. Tib's Day" : "%s, %s %d" % [weekday, season, day]}, #{year} YOLD}
end
end</langsyntaxhighlight>
 
Testing:
<langsyntaxhighlight lang="ruby">[[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</langsyntaxhighlight>
{{Out}}
<pre>2012-02-28 => Prickle-Prickle, Chaos 59, 3178 YOLD
Line 3,663 ⟶ 4,716:
permission of the author.
 
<langsyntaxhighlight lang="rust">extern crate chrono;
 
use chrono::NaiveDate;
Line 3,734 ⟶ 4,787:
format!("{}{}", s, suffix)
}
</syntaxhighlight>
</lang>
 
{{Out}}<pre>$ ./ddate -1166-1-1
Line 3,758 ⟶ 4,811:
 
{{trans|Python}}
<langsyntaxhighlight lang="scala">package rosetta
 
import java.util.GregorianCalendar
Line 3,791 ⟶ 4,844:
} else
println("usage: DDate [day month year]")
}</langsyntaxhighlight>
Test:
<langsyntaxhighlight lang="scala">scala rosetta.DDate 2010 7 22
Confusion 57, 3176 YOLD
scala rosetta.DDate 28 2 2012
Line 3,803 ⟶ 4,856:
scala rosetta.DDate 19 10 2015
Bureaucracy 73, 3181 YOLD
</syntaxhighlight>
</lang>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "time.s7i";
Line 3,858 ⟶ 4,911:
writeln("Discordian date computation works.");
end if;
end func;</langsyntaxhighlight>
 
{{out}}
Line 3,868 ⟶ 4,921:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">require('Time::Piece');
 
var seasons = %w(Chaos Discord Confusion Bureaucracy The\ Aftermath);
Line 3,898 ⟶ 4,951:
%w(2010-07-22 2012-02-28 2012-02-29 2012-03-01).each { |ymd|
say "#{ymd} is #{ddate(ymd)}"
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,908 ⟶ 4,961:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
let monthDays = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
Line 3,954 ⟶ 5,007:
showDiscordianDate(year: 2019, month: 7, day: 15)
showDiscordianDate(year: 2025, month: 3, day: 19)
showDiscordianDate(year: 2017, month: 12, day: 8)</langsyntaxhighlight>
 
{{out}}
Line 3,967 ⟶ 5,020:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
proc disdate {year month day} {
# Get the day of the year
Line 3,989 ⟶ 5,042:
incr year 1166
return "$season $dos, $year YOLD"
}</langsyntaxhighlight>
Demonstrating:
<langsyntaxhighlight lang="tcl">puts [disdate 2010 7 22]; # Today
puts [disdate 2012 2 28]
puts [disdate 2012 2 29]
puts [disdate 2012 3 1]</langsyntaxhighlight>
{{Out}}
<pre>
Line 4,007 ⟶ 5,060:
{{libheader|Wren-date}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./date" for Date
import "./fmt" for Fmt
 
var seasons = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]
Line 4,058 ⟶ 5,111:
var dt = Date.parse(date)
System.print("%(date) = %(discordian.call(dt))")
}</langsyntaxhighlight>
 
{{out}}
Line 4,083 ⟶ 5,136:
=={{header|zkl}}==
{{trans|D}}
<langsyntaxhighlight lang="zkl">fcn discordianDate(y,m,d){
var [const]
seasons=T("Chaos","Discord","Confusion","Bureaucracy","The Aftermath"),
Line 4,103 ⟶ 5,156:
dWday:=weekday[(doy - 1)%5];
"%s, day %s of %s in the YOLD %s".fmt(dWday,dsDay,dSeas,dYear);
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">foreach y,m,d in (T(T(2010,7,22), T(2012,2,28), T(2012,2,29), T(2012,3,1),
T(2010,1, 5), T(2011,5, 3))){
"%d-%02d-%02d is -->%s".fmt(y,m,d,discordianDate(y,m,d)).println();
}</langsyntaxhighlight>
{{out}}
<pre>
2,095

edits