Catholic feasts whose date is relative to Easter date

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Roland Chastain
Posts: 1007
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Catholic feasts whose date is relative to Easter date

Post by Roland Chastain »

Hello! Here is a program that displays the date of some catholic feasts, whose date is relative to Easter date. Uses Oudin algorithm and julian day number.

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))
Happy Easter!
dodicat
Posts: 7987
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Catholic feasts whose date is relative to Easter date

Post by dodicat »

Happy Easter Roland.
I do not attend church.
However, as a Presbyterian, as many are in Scotland, then we would comment that Easter is not mentioned in the Bible, so it is not necessary.
Of course this saves on the expense of buying eggs.
Thank for the code.
Roland Chastain
Posts: 1007
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: Catholic feasts whose date is relative to Easter date

Post by Roland Chastain »

Thank you for your comment dodicat. :)
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Catholic feasts whose date is relative to Easter date

Post by bcohio2001 »

dodicat wrote:that Easter is not mentioned in the Bible
True. But "Easter" is the secular name for "Resurrection Day", which is in the Bible. And also relates to "Palm Sunday" and "Good Friday"
St_W
Posts: 1627
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Catholic feasts whose date is relative to Easter date

Post by St_W »

Happy Easter.
dodicat wrote:However, as a Presbyterian, as many are in Scotland, then we would comment that Easter is not mentioned in the Bible, so it is not necessary. Of course this saves on the expense of buying eggs.
I guess there's nothing about eggs in the bible either, but in any case: don't take everything literally that was written down in the bible (or whathever, Koran, ...) more than a thousand years ago. Just look at syria ("IS") ...
Post Reply