date_easter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +29 -0
- data/lib/date_easter.rb +91 -0
- data/test/t01fast.rb +142 -0
- data/test/t02stress.rb +54 -0
- metadata +49 -0
data/README
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= date_easter: calculate the day upon which Easter Sunday falls
|
2
|
+
-----
|
3
|
+
|
4
|
+
|
5
|
+
== OVERVIEW
|
6
|
+
-----
|
7
|
+
This module calculates the date upon which Easter falls, a date upon
|
8
|
+
which many holidays in the Western world depend. It extends the
|
9
|
+
Date class available in the Ruby standard library, adding the
|
10
|
+
class method Date::easter(year) and the instance method easter().
|
11
|
+
|
12
|
+
|
13
|
+
== BUGS
|
14
|
+
-----
|
15
|
+
Julian / Orthodox easter calculations are not yet implemented.
|
16
|
+
|
17
|
+
|
18
|
+
== LICENSE
|
19
|
+
-----
|
20
|
+
This program is free software! You can copy, modify, share and
|
21
|
+
distribute it under the same license as Ruby itself.
|
22
|
+
|
23
|
+
|
24
|
+
== AUTHOR
|
25
|
+
-----
|
26
|
+
Rick Scott
|
27
|
+
rick@shadowspar.dyndns.org
|
28
|
+
|
29
|
+
Patches, feature requests, and bug reports are welcome.
|
data/lib/date_easter.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# date_easter: calculate the day upon which Easter Sunday falls
|
2
|
+
#
|
3
|
+
# This program is free software! You can copy, modify, share and
|
4
|
+
# distribute it under the same license as Ruby itself.
|
5
|
+
#
|
6
|
+
# Rick Scott
|
7
|
+
# rick@shadowspar.dyndns.org
|
8
|
+
#
|
9
|
+
# Tue Nov 28 22:57:01 EST 2006
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# == Overview
|
13
|
+
#
|
14
|
+
# This module calculates the date upon which Easter falls, a date
|
15
|
+
# upon which many holidays in the Western world depend.
|
16
|
+
# It extends the Date class available in the Ruby standard library,
|
17
|
+
# adding the class method Date::easter(year) and the instance
|
18
|
+
# method easter(). It returns the correct date of Easter Sunday for
|
19
|
+
# the Gregorian calendar years 1583 to 4099.
|
20
|
+
#
|
21
|
+
# == Background
|
22
|
+
#
|
23
|
+
# Determining when Easter falls is a somewhat arcane process,
|
24
|
+
# largely due to the numerous adjustments that have been made to
|
25
|
+
# the Gregorian calendar in an attempt to `fit together' the
|
26
|
+
# cycles of the sun, moon, and earth. Detailed discussion here
|
27
|
+
# would be somewhat pointless in light of the far superior
|
28
|
+
# resources available online -- see 'References', below, for some
|
29
|
+
# starting points.
|
30
|
+
#
|
31
|
+
# == References
|
32
|
+
#
|
33
|
+
# http://en.wikipedia.org/wiki/Computus
|
34
|
+
# http://www.phys.uu.nl/~vgent/easter/easter_text2a.htm
|
35
|
+
# http://users.chariot.net.au/~gmarts/eastcalc.htm
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
require 'date'
|
40
|
+
|
41
|
+
class Date
|
42
|
+
|
43
|
+
# :call-seq:
|
44
|
+
# Date::easter(year) => easter_sunday_Date
|
45
|
+
#
|
46
|
+
# Return the Date upon which Easter Sunday falls in _year_.
|
47
|
+
# The Gregorian calendar is used.
|
48
|
+
def self.easter(year)
|
49
|
+
unless year.is_a? Numeric
|
50
|
+
raise TypeError, "year must be Numeric"
|
51
|
+
end
|
52
|
+
|
53
|
+
if year < 1583
|
54
|
+
raise ArgumentError, "Years before 1583 not supported"
|
55
|
+
elsif year > 4099
|
56
|
+
raise ArgumentError, "Years after 4099 not supported"
|
57
|
+
end
|
58
|
+
|
59
|
+
golden_number = (year % 19) + 1
|
60
|
+
century = (year / 100) + 1
|
61
|
+
julian_epact = (11 * (golden_number -1)) % 30
|
62
|
+
solar_correction = (3 * century) / 4
|
63
|
+
lunar_correction = ((8 * century) + 5) / 25
|
64
|
+
|
65
|
+
gregorian_epact =
|
66
|
+
(julian_epact - solar_correction + lunar_correction + 8) % 30
|
67
|
+
|
68
|
+
days_fm_ve_to_pfm = (23 - gregorian_epact) % 30
|
69
|
+
|
70
|
+
if gregorian_epact == 24 or gregorian_epact == 25 && golden_number > 11
|
71
|
+
days_fm_ve_to_pfm -= 1
|
72
|
+
end
|
73
|
+
|
74
|
+
vernal_equinox = Date.new(year, 3, 21)
|
75
|
+
paschal_full_moon = vernal_equinox + days_fm_ve_to_pfm
|
76
|
+
|
77
|
+
days_to_sunday = 7 - paschal_full_moon.wday
|
78
|
+
|
79
|
+
easter_sunday = paschal_full_moon + days_to_sunday
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
# :call-seq:
|
84
|
+
# ref.easter() => easter_sunday_Date
|
85
|
+
#
|
86
|
+
# Return the Date of Easter Sunday for the year in which _ref_
|
87
|
+
# falls. The Gregorian calendar is used.
|
88
|
+
def easter
|
89
|
+
Date::easter(self.year)
|
90
|
+
end
|
91
|
+
end
|
data/test/t01fast.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
# t01fast.rb: abbreviated test suite for date_easter
|
2
|
+
#
|
3
|
+
# This program is free software! You can copy, modify, share and
|
4
|
+
# distribute it under the same license as Ruby itself.
|
5
|
+
#
|
6
|
+
# Rick Scott
|
7
|
+
# rick@shadowspar.dyndns.org
|
8
|
+
#
|
9
|
+
# Wed Nov 29 21:21:16 EST 2006
|
10
|
+
#
|
11
|
+
# for rationale on choosing these dates, have a look at:
|
12
|
+
# http://en.wikipedia.org/wiki/Epoch_%28reference_date%29
|
13
|
+
# http://www.theiet.org/publicaffairs/scs/problemdates.cfm
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
require 'date_easter'
|
17
|
+
|
18
|
+
|
19
|
+
class TC_Correctness < Test::Unit::TestCase
|
20
|
+
def test_correctness
|
21
|
+
test_dates = %w{
|
22
|
+
10 04 1583
|
23
|
+
01 04 1584
|
24
|
+
07 04 1602
|
25
|
+
02 04 1752
|
26
|
+
|
27
|
+
04 04 1858
|
28
|
+
02 04 1899
|
29
|
+
15 04 1900
|
30
|
+
07 04 1901
|
31
|
+
03 04 1904
|
32
|
+
|
33
|
+
06 04 1969
|
34
|
+
29 03 1970
|
35
|
+
11 04 1971
|
36
|
+
10 04 1977
|
37
|
+
26 03 1978
|
38
|
+
15 04 1979
|
39
|
+
06 04 1980
|
40
|
+
|
41
|
+
19 04 1981
|
42
|
+
11 04 1982
|
43
|
+
03 04 1983
|
44
|
+
22 04 1984
|
45
|
+
07 04 1985
|
46
|
+
30 03 1986
|
47
|
+
19 04 1987
|
48
|
+
03 04 1988
|
49
|
+
26 03 1989
|
50
|
+
15 04 1990
|
51
|
+
|
52
|
+
31 03 1991
|
53
|
+
19 04 1992
|
54
|
+
11 04 1993
|
55
|
+
03 04 1994
|
56
|
+
16 04 1995
|
57
|
+
07 04 1996
|
58
|
+
30 03 1997
|
59
|
+
12 04 1998
|
60
|
+
04 04 1999
|
61
|
+
23 04 2000
|
62
|
+
|
63
|
+
15 04 2001
|
64
|
+
31 03 2002
|
65
|
+
20 04 2003
|
66
|
+
11 04 2004
|
67
|
+
27 03 2005
|
68
|
+
16 04 2006
|
69
|
+
08 04 2007
|
70
|
+
23 03 2008
|
71
|
+
12 04 2009
|
72
|
+
04 04 2010
|
73
|
+
|
74
|
+
24 04 2011
|
75
|
+
08 04 2012
|
76
|
+
31 03 2013
|
77
|
+
20 04 2014
|
78
|
+
05 04 2015
|
79
|
+
27 03 2016
|
80
|
+
16 04 2017
|
81
|
+
01 04 2018
|
82
|
+
21 04 2019
|
83
|
+
12 04 2020
|
84
|
+
|
85
|
+
04 04 2021
|
86
|
+
17 04 2022
|
87
|
+
09 04 2023
|
88
|
+
31 03 2024
|
89
|
+
20 04 2025
|
90
|
+
05 04 2026
|
91
|
+
28 03 2027
|
92
|
+
16 04 2028
|
93
|
+
01 04 2029
|
94
|
+
21 04 2030
|
95
|
+
|
96
|
+
13 04 2031
|
97
|
+
28 03 2032
|
98
|
+
17 04 2033
|
99
|
+
09 04 2034
|
100
|
+
25 03 2035
|
101
|
+
13 04 2036
|
102
|
+
05 04 2037
|
103
|
+
25 04 2038
|
104
|
+
10 04 2039
|
105
|
+
01 04 2040
|
106
|
+
|
107
|
+
21 04 2041
|
108
|
+
06 04 2042
|
109
|
+
29 03 2043
|
110
|
+
17 04 2044
|
111
|
+
09 04 2045
|
112
|
+
25 03 2046
|
113
|
+
14 04 2047
|
114
|
+
05 04 2048
|
115
|
+
18 04 2049
|
116
|
+
10 04 2050
|
117
|
+
|
118
|
+
18 04 2060
|
119
|
+
30 03 2070
|
120
|
+
07 04 2080
|
121
|
+
16 04 2090
|
122
|
+
12 04 2099
|
123
|
+
28 03 2100
|
124
|
+
17 04 2101
|
125
|
+
|
126
|
+
06 04 4098
|
127
|
+
19 04 4099
|
128
|
+
}
|
129
|
+
|
130
|
+
until test_dates.empty?
|
131
|
+
day = test_dates.shift.to_i
|
132
|
+
month = test_dates.shift.to_i
|
133
|
+
year = test_dates.shift.to_i
|
134
|
+
|
135
|
+
easter_date = Date::easter(year)
|
136
|
+
assert_equal(year, easter_date.year, "Year of Easter #{year}" )
|
137
|
+
assert_equal(month, easter_date.month, "Month of Easter #{year}")
|
138
|
+
assert_equal(day, easter_date.day , "Day of Easter #{year}" )
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
data/test/t02stress.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# t02stress.rb: stress tests for date_easter
|
2
|
+
#
|
3
|
+
# This program is free software! You can copy, modify, share and
|
4
|
+
# distribute it under the same license as Ruby itself.
|
5
|
+
#
|
6
|
+
# Rick Scott
|
7
|
+
# rick@shadowspar.dyndns.org
|
8
|
+
#
|
9
|
+
# Wed Nov 29 21:21:16 EST 2006
|
10
|
+
#
|
11
|
+
# for rationale on choosing these dates, have a look at:
|
12
|
+
# http://en.wikipedia.org/wiki/Epoch_%28reference_date%29
|
13
|
+
# http://www.theiet.org/publicaffairs/scs/problemdates.cfm
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
require 'date_easter'
|
17
|
+
|
18
|
+
|
19
|
+
class TC_Stress < Test::Unit::TestCase
|
20
|
+
def test_year_rubbish
|
21
|
+
assert_raise TypeError do
|
22
|
+
Date::easter(nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_raise TypeError do
|
26
|
+
Date::easter('asdf')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_year_toobig
|
31
|
+
assert_raise ArgumentError do
|
32
|
+
Date::easter(9999)
|
33
|
+
end
|
34
|
+
|
35
|
+
ridiculous_future_date = Date.new(12345, 12, 31)
|
36
|
+
|
37
|
+
assert_raise ArgumentError do
|
38
|
+
ridiculous_future_date.easter()
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_year_toosmall
|
43
|
+
assert_raise ArgumentError do
|
44
|
+
Date::easter(1)
|
45
|
+
end
|
46
|
+
|
47
|
+
ridiculous_ancient_date = Date.new(-1234, 12, 31)
|
48
|
+
|
49
|
+
assert_raise ArgumentError do
|
50
|
+
ridiculous_ancient_date.easter()
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: date_easter
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2006-11-30 00:00:00 -05:00
|
8
|
+
summary: Calculate the date on which Easter falls.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: rick@shadowspar.dyndns.org
|
12
|
+
homepage: http://shadowspar.dyndns.org/rick/
|
13
|
+
rubyforge_project: date_easter
|
14
|
+
description: "This module calculates the date upon which Easter falls, a date upon which many
|
15
|
+
holidays in the Western world depend. It extends the Date class available in
|
16
|
+
the Ruby standard library, adding the class method Date::easter(year) and the
|
17
|
+
instance method easter()."
|
18
|
+
autorequire:
|
19
|
+
default_executable:
|
20
|
+
bindir: bin
|
21
|
+
has_rdoc: true
|
22
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
23
|
+
requirements:
|
24
|
+
-
|
25
|
+
- ">"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.0.0
|
28
|
+
version:
|
29
|
+
platform: ruby
|
30
|
+
signing_key:
|
31
|
+
cert_chain:
|
32
|
+
post_install_message:
|
33
|
+
authors:
|
34
|
+
- Rick Scott
|
35
|
+
files:
|
36
|
+
- lib/date_easter.rb
|
37
|
+
- test/t01fast.rb
|
38
|
+
- test/t02stress.rb
|
39
|
+
- README
|
40
|
+
test_files:
|
41
|
+
- test/t01fast.rb
|
42
|
+
- test/t02stress.rb
|
43
|
+
rdoc_options: []
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
requirements: []
|
49
|
+
dependencies: []
|