From bc4605ea15dabb1756ce6617c7c54f41e61bb5aa Mon Sep 17 00:00:00 2001 From: Sonia Keys Date: Mon, 11 Mar 2013 15:27:25 -0400 Subject: [PATCH] add ch 8, easter --- doc.go | 1 + easter/easter.go | 33 +++++++++++++++++++++++++++++++++ easter/easter_test.go | 32 ++++++++++++++++++++++++++++++++ readme.md | 1 + 4 files changed, 67 insertions(+) create mode 100644 easter/easter.go create mode 100644 easter/easter_test.go diff --git a/doc.go b/doc.go index 85c9d3c..17ca347 100644 --- a/doc.go +++ b/doc.go @@ -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 diff --git a/easter/easter.go b/easter/easter.go new file mode 100644 index 0000000..0c6202d --- /dev/null +++ b/easter/easter.go @@ -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 +} diff --git a/easter/easter_test.go b/easter/easter_test.go new file mode 100644 index 0000000..a5fd395 --- /dev/null +++ b/easter/easter_test.go @@ -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 +} diff --git a/readme.md b/readme.md index be2f826..97bf8f5 100644 --- a/readme.md +++ b/readme.md @@ -17,6 +17,7 @@ Cross reference from chapters to package names 3. Interpolationinterpunder renovation 4. Curve Fittingfitcomplete 7. Julian Dayjuliancomplete + 8. Date of Eastereastercomplete 10. Dynamical Time and Universal Timedeltatcomplete 11. The Earth's Globeglobecomplete 12. Sidereal Time at Greenwichsiderealcomplete