Discordian date: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (→{{header|C sharp}}: Regularize header markup to recommended on category page) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
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.
<
;; 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>
{{out}}
Line 260:
This code is written to compile to a <code>.COM</code> file using <code>nasm</code>.
<
bits 16
cpu 8086
Line 462:
xflux: db 'flux!$'
tibsday: db "Saint Tib's Day$"
yold: db ' in the YOLD $'</
{{out}}
Line 481:
discordian.adb:
<
with Ada.Text_IO;
with Ada.Integer_Text_IO;
Line 684:
end Discordian;
</syntaxhighlight>
{{Out}}
Line 699:
{{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.
<
INT greg, gmonth, gday, gyear;
[]STRING holys = []STRING( "MUNG", "MOJO", "SYA", "ZARA", "MALA" )[ AT 0 ];
Line 727:
FI
FI
END</
{{out}}
<pre>
Line 757:
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.
<
INTEGER GREG, GMONTH, GDAY, GYEAR;
STRING(16) ARRAY HOLY5 ( 0 :: 4 );
Line 812:
END IF_FAY_EQ_5__DAY_EQ_50
END
END.</
{{out}}
<pre>
Line 836:
=={{header|AppleScript}}==
<
(*
Discordian years are aligned with, and the same length as, Gregorian years.
Line 883:
set gregorianDate to ASDate's date string
set discordianDate to gregorianToDiscordian(ASDate)
return {Gregorian:gregorianDate, Discordian:discordianDate}</
{{output}}
<
=={{header|AWK}}==
<syntaxhighlight 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 988:
errors++
}
</syntaxhighlight>
{{Out}}
<pre>
Line 1,003:
{{trans|PowerBASIC}}
<
DECLARE FUNCTION julian(AS DOUBLE) AS INTEGER
Line 1,053:
NEXT
FUNCTION = tmp + DAY(d)
END FUNCTION</
{{out}}
<pre>"Discordian date.exe" 19-10-2015
Line 1,060:
=={{header|Batch File}}==
{{works with|Windows XP Service Pack 3}}
<
goto Parse
Line 1,237:
:End
</syntaxhighlight>
{{out}}
<pre>
Line 1,276:
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
PRINT "01/01/2011 -> " FNdiscordian("01/01/2011")
Line 1,313:
ENDIF
= Weekday$(day% MOD 5) + ", " + STR$(day% MOD 73 + 1) + " " + \
\ Season$(day% DIV 73) + ", YOLD " + STR$(year% + 1166)</
{{Out}}
<pre>
Line 1,334:
Reads the date to convert from stdin as three separate numeric inputs (year, month, and day).
<
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$</
{{out}} (multiple runs)
Line 1,363:
For the source code of <code>ddate</code> in util-linux package, see [[http://jubal.westnet.com/hyperdiscordia/ddate.html]].
<
#include <stdio.h>
#include <time.h>
Line 1,434:
return 0;
}</
Demonstration:
Line 1,456:
=={{header|C sharp|C#}}==
<
public static class DiscordianDate
Line 1,510:
}
}</
{{out}}
<pre>
Line 1,532:
=={{header|C++}}==
<
#include <iostream>
#include <algorithm>
Line 1,619:
return 0;
}
</syntaxhighlight>
{{out}}<pre>
Enter a date (dd mm yyyy) or 0 to quit: 19 10 2015
Line 1,641:
=={{header|Clojure}}==
<
(def seasons ["Chaos" "Discord" "Confusion" "Bureaucracy" "The Aftermath"])
Line 1,663:
(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))))</
{{out}}
Line 1,680:
=={{header|CLU}}==
<
% so it can use get_argv to read the command line.
%
Line 1,879:
stream$putl(po, eris_date$from_date(d).format)
end
end start_up</
{{out}}
<pre>$ ./ddate
Line 1,893:
=={{header|D}}==
<
immutable seasons = ["Chaos", "Discord", "Confusion",
Line 1,972:
}
}
}</
{{out}}
<pre>$ ./ddate 20100722 20120228 20120229 20120301 20100105 20110503 20151019 00000101 -11660101
Line 1,989:
{{libheader| System.DateUtils}}
{{Trans|D}} Partial translation of D.
<syntaxhighlight lang="delphi">
program Discordian_date;
Line 2,084:
readln;
end.</
=={{header|Euphoria}}==
{{trans|D}}
<
return remainder(year,4)=0 and remainder(year,100)!=0 or remainder(year,400)=0
end function
Line 2,146:
today = date()
today[YEAR] += 1900
puts(1, discordianDate(today))</
=={{header|F Sharp|F#}}==
<
let seasons = [| "Chaos"; "Discord"; "Confusion"; "Bureaucracy"; "The Aftermath" |]
Line 2,175:
|> Seq.iter(fun (s,d) -> printfn "%s is %s" s (ddate d))
0
</syntaxhighlight>
{{out}}
<pre>2012-02-28 is Chaos 59, 3178 YOLD
Line 2,185:
=={{header|Fortran}}==
<syntaxhighlight lang="fortran">
program discordianDate
implicit none
Line 2,384:
end if
end function Pleapyear
</syntaxhighlight>
<pre>
compiled as ddate.
Line 2,400:
=={{header|FreeBASIC}}==
{{trans|BASIC}}
<
meses:
Line 2,456:
cDiscordiano("15/07/2019")
cDiscordiano("19/03/2025")
Sleep</
{{out}}
<pre>
Line 2,475:
=={{header|Go}}==
A package modeled after the time package in the Go standard library
<
import (
Line 2,607:
}
return
} </
Example program using above package
<
import (
Line 2,651:
fmt.Fprintf(os.Stderr, "usage: %s [+format] [day month year]\n", os.Args[0])
os.Exit(1)
}</
{{Out}}
<pre>
Line 2,662:
=={{header|Haskell}}==
<
import Data.Time.Calendar.MonthDay (monthAndDayToDayOfYear)
import Text.Printf (printf)
Line 2,705:
weekday = toEnum $ dayOfYear `mod` 5
season = toEnum $ dayOfYear `div` 73
dayOfSeason = 1 + dayOfYear `mod` 73</
Examples:
<
where
display d = putStr (show d ++ " -> ") >> print (fromYMD d)
Line 2,719:
,(2010,9,2)
,(2010,12,31)
,(2011,1,1)]</
<pre>λ> test
Line 2,744:
=={{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.
<
procedure main()
Line 2,798:
ddate.sday || " of " || seasons[ddate.season])) ||
" in the YOLD " || ddate.year
end</
{{Out}}
Line 2,815:
=={{header|J}}==
<
leap=: _1j1 * 0 -/@:= 4 100 400 |/ {.@]
bs=: ((#:{.) + 0 j. *@[ * {:@]) +.
disc=: ((1+0 73 bs[ +^:(58<]) -/@todayno@(,: 1 1,~{.)@]) ,~1166+{.@])~ leap</
Example use:
<syntaxhighlight lang="text"> disc 2012 2 28
3178 1 59
disc 2012 2 29
Line 2,837:
3181 4 73
disc 2000 3 13
3166 1 72j1</
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,843:
=={{header|Java}}==
<
import java.util.GregorianCalendar;
Line 2,902:
assert (discordianDate(new GregorianCalendar(y, m, d)).equals(result));
}
}</
{{Out}}
Line 2,909:
=={{header|JavaScript}}==
<
/**
* All Hail Discordia! - this script prints Discordian date using system date.
Line 3,028:
module.exports = discordianDate;
</syntaxhighlight>
Example use:
<
console.log(discordianDate(new Date(Date.now())));
"Boomtime, the 2nd day of Chaos in the YOLD 3183"
</syntaxhighlight>
look at [http://www.cs.cmu.edu/~tilt/principia/body.html#applecorps calendar];
Line 3,041:
=={{header|JotaCode}}==
<
"Today is ",
@let(1,@add(@switch(@time("mon"),
Line 3,075:
", YOLD ",
@add(@time("year"),3066))
)),".")</
=={{header|Julia}}==
<
function discordiandate(year::Integer, month::Integer, day::Integer)
Line 3,113:
@show discordiandate(2017, 08, 15)
@show discordiandate(1996, 02, 29)
@show discordiandate(1996, 02, 19)</
{{out}}
Line 3,122:
=={{header|Kotlin}}==
{{trans|Java}}
<
import java.util.GregorianCalendar
Line 3,176:
test(2011, 4, 3, "Discoflux, in the YOLD 3177")
test(2015, 9, 19, "Boomtime, day 73 of Bureaucracy in the YOLD 3181")
}</
=={{header|MAD}}==
<
R
R PUNCH CARD SHOULD CONTAIN -
Line 3,223:
END OF CONDITIONAL
END OF CONDITIONAL
END OF PROGRAM</
{{out}}
Line 3,243:
=={{header|Maple}}==
<
local days31, days30, daysThisYear, i, dYear, dMonth, dDay, seasons, week, dayOfWeek;
days31 := [1, 3, 5, 7, 8, 10, 12];
Line 3,279:
convertDiscordian (2016, 1, 1);
convertDiscordian (2016, 2, 29);
convertDiscordian (2016, 12, 31);</
{{out}}
<pre>
Line 3,288:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
DMONTHS = {"Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"};
Line 3,302:
Print["Today is ", DDAYS[[Mod[dday,4] + 1]],", ",DMONTHS[[season+1]]," ",dday,", YOLD ",year]
];
]</
{{Out}}
<pre>DiscordianDate[2012,2,28]
Line 3,315:
=={{header|Nim}}==
We use a DateTime object as intermediate representation.
<
const
Line 3,397:
showDiscordianDate(2010, 07, 22)
showDiscordianDate(2012, 09, 02)
showDiscordianDate(2012, 12, 31)</
{{out}}
Line 3,409:
=={{header|Pascal}}==
<syntaxhighlight lang="pascal">
program ddate;
{
Line 3,569:
WriteLn(Eris);
end.
</syntaxhighlight>
{{Out}}
<pre>
Line 3,585:
=={{header|Perl}}==
{{trans|Raku}}
<
use strict;
use warnings;
Line 3,618:
say "$_ is " . ddate($_) for qw< 2010-07-22 2012-02-28 2012-02-29 2012-03-01 >;
</syntaxhighlight>
{{out}}
<pre>2010-07-22 is Pungenday, the 57th day of Confusion in the YOLD 3176
Line 3,627:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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>
Line 3,669:
<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: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 3,687:
<syntaxhighlight lang="php">
<?php
$Anerisia = array(31,28,31,30,31,30,31,31,30,31,30,31);
Line 3,770:
?>
</syntaxhighlight>
{{Out}}
Line 3,788:
=={{header|PicoLisp}}==
{{trans|Python}}
<
(let? Date (date Year Month Day)
(let (Leap (date Year 2 29) D (- Date (date Year 1 1)))
Line 3,801:
(inc (% D 73))
", YOLD "
(+ Year 1166) ) ) ) ) )</
=={{header|Pike}}==
Pike includes a Discordian calendar.
dates can be converted from any calendar to any other.
<
Result: "Pungenday, 59 Bureaucracy 3177"
> Calendar.Discordian.Day(Calendar.Day(2011,11,11))->format_ext_ymd();
Line 3,813:
Result: "Setting Orange, 23 The Aftermath 3177"
> Calendar.Day((Calendar.Discordian.Month()+1)->day(1));
Result: Day(Thu 20 Oct 2011)</
=={{header|PowerBASIC}}==
<
#DIM ALL
Line 3,880:
? result
END FUNCTION</
=={{header|PowerShell}}==
{{works with|powershell|2}}
<
function ConvertTo-Discordian ( [datetime]$GregorianDate )
{
Line 3,907:
ConvertTo-Discordian ([datetime]'2/29/2016')
ConvertTo-Discordian ([datetime]'12/8/2016')
</syntaxhighlight>
{{out}}
<pre>
Line 3,917:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<
main:-
Line 3,996:
holy_day(3, 50, 'Bureflux').
holy_day(4, 5, 'Maladay').
holy_day(4, 50, 'Afflux').</
{{out}}
Line 4,009:
=={{header|PureBasic}}==
<
Protected DoY=DayOfYear(Date(Y,M,D,0,0,0)), Yold$=Str(Y+1166)
Dim S.s(4)
Line 4,022:
EndIf
ProcedureReturn S(DoY/73)+" "+Str(DoY%73)+", Yold "+Yold$
EndProcedure</
=={{header|Python}}==
<
DISCORDIAN_SEASONS = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]
Line 4,042:
season, dday = divmod(day_of_year, 73)
return "%s %d, YOLD %d" % (DISCORDIAN_SEASONS[season], dday + 1, year + 1166)
</syntaxhighlight>
=={{header|Racket}}==
{{trans|D}}
<
;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;;; Derived from 'D' Implementation
Line 4,097:
(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</
{{Out}}
Line 4,106:
{{Works with|rakudo|2015-11-04}}
<!-- Hi Grondilu! Keep up the good work! -->
<syntaxhighlight lang="raku"
my @days = << Sweetmorn Boomtime Pungenday Prickle-Prickle 'Setting Orange' >>;
sub ordinal ( Int $n ) { $n ~ ( $n % 100 == 11|12|13
Line 4,131:
say "$_ is {.&ddate}" for < 2010-07-22 2012-02-28 2012-02-29 2012-03-01 >;
</syntaxhighlight>
{{out}}
Line 4,146:
If the Gregorian date is omitted or specified as an asterisk ('''*'''), the current date is used.
<
@day.1= 'Sweetness' /*define the 1st day─of─Discordian─week*/
@day.2= 'Boomtime' /* " " 2nd " " " " */
Line 4,179:
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.*/</
{{out|input|text= when using the (various) following inputs of:}}
<pre>
Line 4,204:
=={{header|Ruby}}==
<
class DiscordianDate
Line 4,248:
%Q{#{@st_tibs ? "St. Tib's Day" : "%s, %s %d" % [weekday, season, day]}, #{year} YOLD}
end
end</
Testing:
<
dd = DiscordianDate.new(*date)
puts "#{"%4d-%02d-%02d" % date} => #{dd}"
end</
{{Out}}
<pre>2012-02-28 => Prickle-Prickle, Chaos 59, 3178 YOLD
Line 4,272:
permission of the author.
<
use chrono::NaiveDate;
Line 4,343:
format!("{}{}", s, suffix)
}
</syntaxhighlight>
{{Out}}<pre>$ ./ddate -1166-1-1
Line 4,367:
{{trans|Python}}
<
import java.util.GregorianCalendar
Line 4,400:
} else
println("usage: DDate [day month year]")
}</
Test:
<
Confusion 57, 3176 YOLD
scala rosetta.DDate 28 2 2012
Line 4,412:
scala rosetta.DDate 19 10 2015
Bureaucracy 73, 3181 YOLD
</syntaxhighlight>
=={{header|Seed7}}==
<
include "time.s7i";
Line 4,467:
writeln("Discordian date computation works.");
end if;
end func;</
{{out}}
Line 4,477:
=={{header|Sidef}}==
{{trans|Perl}}
<
var seasons = %w(Chaos Discord Confusion Bureaucracy The\ Aftermath);
Line 4,507:
%w(2010-07-22 2012-02-28 2012-02-29 2012-03-01).each { |ymd|
say "#{ymd} is #{ddate(ymd)}"
}</
{{out}}
<pre>
Line 4,517:
=={{header|Swift}}==
<
let monthDays = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
Line 4,563:
showDiscordianDate(year: 2019, month: 7, day: 15)
showDiscordianDate(year: 2025, month: 3, day: 19)
showDiscordianDate(year: 2017, month: 12, day: 8)</
{{out}}
Line 4,576:
=={{header|Tcl}}==
<
proc disdate {year month day} {
# Get the day of the year
Line 4,598:
incr year 1166
return "$season $dos, $year YOLD"
}</
Demonstrating:
<
puts [disdate 2012 2 28]
puts [disdate 2012 2 29]
puts [disdate 2012 3 1]</
{{Out}}
<pre>
Line 4,616:
{{libheader|Wren-date}}
{{libheader|Wren-fmt}}
<
import "/fmt" for Fmt
Line 4,667:
var dt = Date.parse(date)
System.print("%(date) = %(discordian.call(dt))")
}</
{{out}}
Line 4,692:
=={{header|zkl}}==
{{trans|D}}
<
var [const]
seasons=T("Chaos","Discord","Confusion","Bureaucracy","The Aftermath"),
Line 4,712:
dWday:=weekday[(doy - 1)%5];
"%s, day %s of %s in the YOLD %s".fmt(dWday,dsDay,dSeas,dYear);
}</
<
T(2010,1, 5), T(2011,5, 3))){
"%d-%02d-%02d is -->%s".fmt(y,m,d,discordianDate(y,m,d)).println();
}</
{{out}}
<pre>
|