Skip to content

Commit

Permalink
add ch 8, easter
Browse files Browse the repository at this point in the history
  • Loading branch information
soniakeys committed Mar 11, 2013
1 parent 49c22b2 commit bc4605e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
// 3. Interpolation interp
// 4. Curve Fitting fit
// 7. Julian Day julian
// 8. Date of Easter easter
// 10. Dynamical Time and Universal Time deltat
// 11. The Earth's Globe globe
// 12. Sidereal Time at Greenwich sidereal
Expand Down
33 changes: 33 additions & 0 deletions easter/easter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2013 Sonia Keys
// License MIT: http://www.opensource.org/licenses/MIT

// Easter: Chapter 8, Date of Easter
package easter

// Gregorian returns month and day of Easter in the Gregorian calendar.
func Gregorian(y int) (m, d int) {
a := y % 19
b, c := y/100, y%100
d, e := b/4, b%4
f := (b + 8) / 25
g := (b - f + 1) / 3
h := (19*a + b - d - g + 15) % 30
i, k := c/4, c%4
l := (32 + 2*e + 2*i - h - k) % 7
m = (a + 11*h + 22*l) / 451
n := h + l - 7*m + 114
n, p := n/31, n%31
return n, p + 1
}

// Julian returns month and day of Easter in the Julian calendar.
func Julian(y int) (m, d int) {
a := y % 4
b := y % 7
c := y % 19
d = (19*c + 15) % 30
e := (2*a + 4*b - d + 34) % 7
f := d + e + 114
f, g := f/31, f%31
return f, g + 1
}
32 changes: 32 additions & 0 deletions easter/easter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package easter_test

import (
"fmt"
"time"

"github.com/soniakeys/meeus/easter"
)

func ExampleGregorian() {
// Example values from p. 68.
for _, y := range []int{1991, 1992, 1993, 1954, 2000, 1818} {
m, d := easter.Gregorian(y)
fmt.Println(y, ":", time.Month(m), d)
}
// Output:
// 1991 : March 31
// 1992 : April 19
// 1993 : April 11
// 1954 : April 18
// 2000 : April 23
// 1818 : March 22
}

func ExampleJulian() {
// Example value from p. 69.
y := 1243
m, d := easter.Julian(y)
fmt.Println(y, ":", time.Month(m), d)
// Output:
// 1243 : April 12
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Cross reference from chapters to package names
<tr><td>3. Interpolation</td><td>interp</td><td>under renovation</td></tr>
<tr><td>4. Curve Fitting</td><td>fit</td><td>complete</td></tr>
<tr><td>7. Julian Day</td><td>julian</td><td>complete</td></tr>
<tr><td>8. Date of Easter</td><td>easter</td><td>complete</td></tr>
<tr><td>10. Dynamical Time and Universal Time</td><td>deltat</td><td>complete</td></tr>
<tr><td>11. The Earth's Globe</td><td>globe</td><td>complete</td></tr>
<tr><td>12. Sidereal Time at Greenwich</td><td>sidereal</td><td>complete</td></tr>
Expand Down

0 comments on commit bc4605e

Please sign in to comment.