

Task

Convert a given date from the   Gregorian calendar   to the   Discordian calendar.




#Include "datetime.bi"
 
meses:
Data "Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"
dias_laborales:
Data "Setting Orange", "Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle"
dias_previos_al_1er_mes:
'   ene feb mar abr may  jun  jul  ago  sep  oct  nov  dic
Data 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
 
Function cJuliano(d As Double) As Integer
    'no tiene en cuenta los años bisiestos (no es necesario para ddate)
    Dim tmp As Integer, i As Integer
    Restore dias_previos_al_1er_mes
    For i = 1 To Month(d)
        Read tmp
    Next i
    Function = tmp + Day(d)
End Function
 
Sub cDiscordiano(Fecha As String)
    Dim As Integer dyear, dday, j, jday
    Dim As Double tempfecha = Datevalue(Fecha)
    Dim As String ddate, dseason, dweekday
 
    dyear = Year(tempfecha) + 1166
    If (2 = Month(tempfecha)) And (29 = Day(tempfecha)) Then
        ddate = "Saint Tib's Day, " & Str(dyear) & " YOLD"
    Else
        jday = cJuliano(tempfecha)
        Restore meses
        For j = 1 To ((jday - 1) \ 73) + 1
            Read dseason
        Next j
        dday = (jday Mod 73)
        If 0 = dday Then dday = 73
        Restore dias_laborales
        For j = 1 To (jday Mod 5) + 1
            Read dweekday
        Next j
        ddate = dweekday & ", " & dseason & " " & Trim(Str(dday)) & ", " & Trim(Str(dyear)) & " YOLD"
    End If
    Print Fecha & " -> " & ddate
End Sub
 
cDiscordiano("01/01/2020")
cDiscordiano("05/01/2020")
cDiscordiano("28/02/2020")
cDiscordiano("01/03/2020")
cDiscordiano("22/07/2020")
cDiscordiano("31/12/2020")
cDiscordiano("20/04/2022")
cDiscordiano("24/05/2020")
cDiscordiano("29/02/2020")
cDiscordiano("15/07/2019")
cDiscordiano("19/03/2025")
Sleep