forked from soniakeys/meeus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters