Discordian date: Difference between revisions

add Refal
(→‎{{header|PL/M}}: Get the Gregorian date from the command line)
(add Refal)
 
(4 intermediate revisions by 3 users not shown)
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 2,085 ⟶ 2,170:
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}}==
Line 4,331 ⟶ 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 4,842 ⟶ 5,060:
{{libheader|Wren-date}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
import "./fmt" for Fmt
 
var seasons = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]
2,114

edits