OpenVMS Source-Code Demos

WCSM_CALC_EASTER_N_GOOD_FRIDAY.FUN

	!========================================================================
	! Title  : wcsm_calc_easter_n_good_friday_106.fun
	! Author : Neil Rieck
	! Created: 1996.06.06
	! Purpose: Calculate the date of EASTER SUNDAY and GOOD FRIDAY
	!========================================================================
	! parameter 1:	stamp$	= ccyymmddHHMMSS
	!		stamp$	= blank, then use today's year
	! parameter 2:	sw% 	= 0 (return Easter Sunday)
	!		sw%	= 1 (return Good Friday)
	!========================================================================
	function string wcsm_calc_easter_n_good_friday(string stamp$, long sw%)
	!
	option type=explicit							! no kid stuff
	!
	external string function wcsm_dt_stamp()				!
	!
	declare	string	year$						,	!		&
		long	year						,	!		&
			A						,	!		&
			B						,	!		&
			C						,	!		&
			D						,	!		&
			E						,	!		&
			F						,	!		&
			G						,	!		&
			H						,	!		&
			I						,	!		&
			K						,	!		&
			L						,	!		&
			M						,	!		&
			P						,	!		&
			Q						,	!		&
			my_Month					,	!		&
			my_Day							!
	!========================================================================
	!	main
	!========================================================================
	if len(stamp$) = 0 then							! if no date was specified then...
	    year$ = left$(wcsm_dt_stamp, 4)					! use today's year
	else									! else
	    year$ = left$(stamp$, 4)						! use year of passed parameter
	end if									!
	!
	!	<<< calculate the date of Easter for the year provided >>>
	!
	when error in								!
	    year = integer( year$ )						! convert string to a number
	use									! if not numeric
	    year = -1								! force an error
	end when								!
	!
	!	this algorithm has legal limits so test them now
	!
	select year								!
	    case <= 1582							! Gregorian Calendar Reform (1582)
		wcsm_calc_easter_n_good_friday = ""				! return nothing
		goto fini							!
	end select								!
	!-----------------------------------------------------------------------------
	!	Easter is the Sunday after the Paschal Full Moon
	!-----------------------------------------------------------------------------
	!
	!	Algorithm by Jean Baptiste Joseph Delambre
	!	------------------------------------------
	!	A = Mod(Year / 19)
	!	B = Int(Year / 100)
	!	C = Mod(Year / 100)
	!	D = Int(B / 4)
	!	E = Mod(B / 4)
	!	F = Int[(B + 8) / 25]
	!	G = Int[(B - F + 1) / 3]
	!	H = Mod[(19xA + B - D - G + 15) / 30]
	!	I = Int(C / 4)
	!	K = Mod(C / 4)
	!	L = Mod[(32 + 2xE + 2xI - H - K) / 7]
	!	M = Int[(A + 11xH + 22xL) / 451]
	!	P = Int[(H + L - 7xM + 114) / 31]
	!	Q = Mod[(H + L - 7xM + 114) / 31]
	!
	!	note: some algorithms mess up years like: 1974, 1984, 1994, etc.
	!
	!	sample run:
	!	----------------
	!	19900415 correct
	!	19910331 correct
	!	19920419 correct
	!	19930411 correct
	!	19940403 correct
	!	19950416 correct
	!-----------------------------------------------------------------------------
	A = Mod(Year , 19)							! golden number
	B = Int(Year / 100)							!
	C = Mod(Year , 100)							!
	D = Int(B / 4)								!
	E = Mod(B , 4)								!
	F = Int((B + 8) / 25)							!
	G = Int((B - F + 1) / 3)						!
	H = Mod((19 * A + B - D - G + 15) , 30)					!
	I = Int(C / 4)								!
	K = Mod(C , 4)								!
	L = Mod((32 + 2 * E + 2 * I - H - K) , 7)				!
	M = Int((A + 11 * H + 22 * L) / 451)					!
	P = Int((H + L - 7 * M + 114) / 31)					! month# (starts at 1)
	Q = Mod((H + L - 7 * M + 114) , 31)					! day# (starts at zero)
	!
	my_month = P								!
	my_day = Q + 1								!
	!
	if sw% = 0 then								! Easter Sunday
	    wcsm_calc_easter_n_good_friday = year$ + format$(my_Month,"<0>#") + format$(my_Day,"<0>#")
	else									! Good Friday
	    gosub move_back_one_day						!
	    gosub move_back_one_day						!
	    wcsm_calc_easter_n_good_friday = year$ + format$(my_Month,"<0>#") + format$(my_Day,"<0>#")
	end if									!
	goto fini								!
	!
	!	<<< move back one day >>>
	!
	! note:	since we only call this twice,
	!	and the lower bound will always be the Spring Equinox (March 21),
	!	don't worry about falling back into February
	!
	move_back_one_day:							!
	my_Day = my_Day - 1							! go back one day
	if my_Day = 0 then							! oops, can't have day zero
	    my_Month	= 3							! set month to 3 (March)
	    my_Day	= 31							! March only has 31 days
	end if									!
	return									!
	!
	!	<<< that's all folks >>>
	!
	fini:									!
	end function								!

Back to OpenVMS
Back to OpenVMS Demo Index
Back to Home
Neil Rieck
Kitchener - Waterloo - Cambridge, Ontario, Canada.