Version 3 of Calculating the Date of Easter

Updated 2004-03-04 11:44:23

A little calculator to get the date of Easter in various years using an algorithm from the Astronomy FAQ. MNO

 #!/bin/sh
 # next line restarts with tclsh \
        exec tclsh $0 ${1+"$@"}
 #
 # Author: Mark Oakden http://wiki.tcl.tk/MNO
 # Version: 1.0
 #
 # calculate Easter Sunday using the algorithm given at 
 # http://www.faqs.org/faqs/astronomy/faq/part3
 #
 # assumes Gregorian calendar
 #
 proc easterdate { year } {
     #
     # G is "golden number"
     #
     set G [expr $year % 19 + 1]
     #
     # H is intermediate in calculating C
     #
     set H [expr int($year / 100)]
     #
     # C is "century term"
     #
     set C [expr -$H + int($H/4) + int(8*($H+11)/25)]
     #
     # first we need the paschal full moon.
     # the following is in days before april 19 with a couple of exceptions
     #
     set rawdays [expr (11*$G+$C) % 30]
     #
     # exceptions if rawdays = 0 use days=1
     # if rawdays = 1 and G >= 12 use days=2
     # else use days=rawdays
     #
     if { $rawdays == 0 } {
        set days 1
     } elseif { $rawdays == 1 && $G >= 12} {
        set days 2
     } else {
        set days $rawdays
     }
     #
     # now find the day that this falls on:-
     #
     set apr19 [clock scan "19 April $year 12:00"]
     # %w is week day number Sun=0 
     set pfmweekdaynum [clock format [expr $apr19 - $days*24*60*60] \
            -format "%w"]
     #
     # Easter sunday is the next Sunday _strictly_ after PFM, so
     # if pfmweekday is sunday, we want 7 days after pfm
     # if pfmweekday is monday, we want 6 days after pfm etc.
     # i.e. we want to take (7-pfmweekdaynum) days after pfm
     #
     set easterdate [expr $apr19 - ($days - 7 + $pfmweekdaynum)*24*60*60]

     return $easterdate
 }

 for { set i 1995 } { $i <= 2015 } { incr i } {
     puts "Easter Sunday in $i will be on [clock format [easterdate $i] -format {%b %d}]"
 }

PT writes: In a strange twist of fate - the very day this was posted a collegue wished to know this date for 2004. Tcl wins the day!


Category Package