Code: Select all
' feasts.bas
' Catholic feasts, whose date is relative to Easter date.
#include "vbcompat.bi"
#include "crt.bi"
' Julian day number
' http://www.tondering.dk/claus/cal/julperiod.php
function DateToJulianDayNumber(byref aYear as const long, byref aMonth as const long, byref aDay as const long) as long
dim as long a, y, m
a = (14 - aMonth) \ 12
y = aYear + 4800 - a
m = aMonth + 12 * a - 3
return aDay + ((153 * m + 2) \ 5) + 365 * y + (y \ 4) - (y \ 100) + (y \ 400) - 32045
end function
sub JulianDayNumberToDate(byref aJulianDayNum as const long, byref aYear as long, byref aMonth as long, byref aDay as long)
dim as long a, b, c, d, e, m
a = aJulianDayNum + 32044
b = (4 * a + 3) \ 146097
c = a - (146097 * b) \ 4
d = (4 * c + 3) \ 1461
e = c - ((1461 * d) \ 4)
m = (5 * e + 2) \ 153
aDay = e - ((153 * m + 2) \ 5) + 1
aMonth = m + 3 - 12 * (m \ 10)
aYear = 100 * b + d - 4800 + m \ 10
end sub
sub ComputeRelativeDate(byref aYear1 as const long, byref aMonth1 as const long, byref aDay1 as const long, byref aDiff as const long, byref aYear2 as long, byref aMonth2 as long, byref aDay2 as long)
dim jdn as long = DateToJulianDayNumber(aYear1, aMonth1, aDay1) + aDiff
JulianDayNumberToDate(jdn, aYear2, aMonth2, aDay2)
end sub
' Oudin algorithm for Easter date computation
function Oudin(byref aYear as const long) as long
dim as long g, c, c4, e, h, k, p, q, i, b, j1, j2
g = aYear mod 19
c = aYear \ 100
c4 = c \ 4
e = (8 * c + 13) \ 25
h = (19 * g + c - c4 - e + 15) mod 30
k = h \ 28
p = 29 \ (h + 1)
q = (21 - g) \ 11
i = (k * p * q - 1) * k + h
b = aYear + aYear \ 4
j1 = b + i + 2 + c4 - c
j2 = j1 mod 7
return 28 + i - j2
end function
sub ComputeEasterDate(byref aYear as const long, byref aMonth as long, byref aDay as long)
dim lOudin as long = Oudin(aYear)
if lOudin <= 31 then
aMonth = 3
aDay = lOudin
else
aMonth = 4
aDay = lOudin - 31
end if
end sub
function FormatRelativeDate(byval aYear as long, byval aMonth as long, byval aDay as long, byref aDiff as const long) as string
ComputeRelativeDate(aYear, aMonth, aDay, aDiff, aYear, aMonth, aDay)
return Format(DateSerial(aYear, aMonth, aDay), "dd/mm/yyyy")
end function
function CurrentYear() as long
return Year(Now)
end function
enum dates
Ash = -46
Palm = -7
Easter = 0
Ascension = 39
Pentecost = 49
Trinity = 56
end enum
dim as long lYear = CurrentYear(), lMonth, lDay
ComputeEasterDate(lYear, lMonth, lDay)
printf(!"Catholic feasts, whose date is relative to Easter date,\nfor current year (%d).\n", lYear)
printf(!" Ash %s\n", FormatRelativeDate(lYear, lMonth, lDay, dates.Ash))
printf(!" Palm %s\n", FormatRelativeDate(lYear, lMonth, lDay, dates.Palm))
printf(!" Easter %s\n", FormatRelativeDate(lYear, lMonth, lDay, dates.Easter))
printf(!" Ascension %s\n", FormatRelativeDate(lYear, lMonth, lDay, dates.Ascension))
printf(!" Pentecost %s\n", FormatRelativeDate(lYear, lMonth, lDay, dates.Pentecost))
printf(!" Trinity %s\n", FormatRelativeDate(lYear, lMonth, lDay, dates.Trinity))