hebruby 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/LICENSE +20 -0
- data/Manifest +8 -0
- data/README +6 -0
- data/README.rdoc +26 -0
- data/Rakefile +27 -0
- data/hebruby.gemspec +31 -0
- data/lib/hebruby.rb +258 -0
- data/test/hebruby_tests.rb +200 -0
- metadata +72 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006-2009 Ron Evans
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# Hebruby is a Ruby library to convert julian dates to hebrew dates, and vice-versa.
|
2
|
+
# Written by Ron Evans (ron dot evans at gmail dot com or http://www.deadprogrammersociety.com).
|
3
|
+
# Additional code contributed by Joshua Harvey.
|
4
|
+
# Algorithm rewritten by Ken Bloom (kbloom@gmail.com) # based on ``Calendrical
|
5
|
+
# Calculations'' by Nachum Dershowitz and Edward M. Reingold, Cambridge
|
6
|
+
# University Press (1997), as implemented in emacs' lisp/calendar/cal-hebrew.el
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Hebruby
|
2
|
+
|
3
|
+
Hebruby is a Ruby library to convert julian dates to hebrew dates, and vice-versa.
|
4
|
+
Written by Ron Evans (ron dot evans at gmail dot com or http://www.deadprogrammersociety.com).
|
5
|
+
Additional code contributed by Joshua Harvey.
|
6
|
+
Algorithm rewritten by Ken Bloom (kbloom@gmail.com) # based on 'Calendrical Calculations' by Nachum Dershowitz and Edward M. Reingold, Cambridge University Press (1997), as implemented in emacs' lisp/calendar/cal-hebrew.el
|
7
|
+
|
8
|
+
= How to install
|
9
|
+
|
10
|
+
sudo gem install hebruby
|
11
|
+
|
12
|
+
= How to use:
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'hebruby'
|
16
|
+
|
17
|
+
@hb = Hebruby::HebrewDate.new(2,4,5728)
|
18
|
+
puts @hb.day # => 2
|
19
|
+
puts @hb.month # => 4
|
20
|
+
puts @hb.month_name # => Tamuz
|
21
|
+
puts @hb.heb_month_name # => תמוז
|
22
|
+
puts @hb.year # => 5728
|
23
|
+
puts @hb.heb_year_name # => התשכ"ח
|
24
|
+
puts @hb.jd # => 6/28/1968
|
25
|
+
|
26
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
Rake::RDocTask.new do |rd|
|
9
|
+
rd.main = "README.rdoc"
|
10
|
+
rd.rdoc_files += ["README.rdoc"]
|
11
|
+
rd.rdoc_files += Dir.glob("lib/**/*.rb")
|
12
|
+
rd.rdoc_dir = 'doc'
|
13
|
+
end
|
14
|
+
|
15
|
+
Rake::TestTask.new do |t|
|
16
|
+
t.pattern = File.dirname(__FILE__) + "/test/*_tests.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
Echoe.new("hebruby") do |p|
|
20
|
+
p.author = "Ron Evans"
|
21
|
+
p.summary = "Hebruby is a Ruby library to convert julian dates to hebrew dates, and vice-versa."
|
22
|
+
p.url = "http://deadprogrammersociety.com/"
|
23
|
+
# p.dependencies = ["sinatra >=0.2.2", "facebooker >=0.9.5"]
|
24
|
+
p.install_message = "*** Hebruby was installed ***"
|
25
|
+
p.include_rakefile = true
|
26
|
+
end
|
27
|
+
|
data/hebruby.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{hebruby}
|
5
|
+
s.version = "2.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Ron Evans"]
|
9
|
+
s.date = %q{2009-09-05}
|
10
|
+
s.description = %q{Hebruby is a Ruby library to convert julian dates to hebrew dates, and vice-versa.}
|
11
|
+
s.email = %q{}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/hebruby.rb", "LICENSE", "README", "README.rdoc"]
|
13
|
+
s.files = ["CHANGELOG", "lib/hebruby.rb", "LICENSE", "Rakefile", "README", "README.rdoc", "test/hebruby_tests.rb", "Manifest", "hebruby.gemspec"]
|
14
|
+
s.homepage = %q{http://deadprogrammersociety.com/}
|
15
|
+
s.post_install_message = %q{*** Hebruby was installed ***}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hebruby", "--main", "README"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{hebruby}
|
19
|
+
s.rubygems_version = %q{1.3.3}
|
20
|
+
s.summary = %q{Hebruby is a Ruby library to convert julian dates to hebrew dates, and vice-versa.}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
data/lib/hebruby.rb
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
# Hebruby is a Ruby library to convert julian dates to hebrew dates, and vice-versa.
|
2
|
+
# Written by Ron Evans (ron dot evans at gmail dot com or http://www.deadprogrammersociety.com).
|
3
|
+
# Additional code contributed by Joshua Harvey.
|
4
|
+
# Based on Javascript code from John Walker (http://www.fourmilab.ch/documents/calendar/).
|
5
|
+
# Usage:
|
6
|
+
# For julian to hebrew:
|
7
|
+
# @hb = Hebruby::HebrewDate.new(Date.new(2010, 1, 1))
|
8
|
+
# assert_equal(10, @hb.month, "Wrong month.")
|
9
|
+
# assert_equal("Tevet", @hb.month_name, "Wrong month name.")
|
10
|
+
# assert_equal(5770, @hb.year, "Wrong year.")
|
11
|
+
# assert_equal(15, @hb.day, "Wrong day.")
|
12
|
+
#
|
13
|
+
# For hebrew to julian:
|
14
|
+
# @hb = Hebruby::HebrewDate.new1(15,10,5770)
|
15
|
+
# assert_equal(Date.new(2010, 1, 1).jd, @hb.jd, "Wrong Julian date.")
|
16
|
+
|
17
|
+
require 'jcode'
|
18
|
+
$KCODE = 'u' # Always use UTF-8 internally!
|
19
|
+
|
20
|
+
module Hebruby
|
21
|
+
|
22
|
+
class HebrewDate
|
23
|
+
HEBREW_EPOCH = 347995
|
24
|
+
MONTH_NAMES = %w{none Nissan Iyar Sivan Tamuz Av Elul Tishrei Chesvan Kislev Tevet Shvat Adar Veadar}
|
25
|
+
HEB_MONTH_NAMES = [ nil, 'ניסן', 'אייר', 'סיון', 'תמוז', 'אב', 'אלול', 'תשרי',
|
26
|
+
'חשון', 'כסלו', 'טבת', 'שבט', 'אדר', 'אדר א\'', 'אדר ב\'']
|
27
|
+
HEB_DAYS = [ nil, 'א\'', 'ב\'', 'ג\'', 'ד\'', 'ה\'', 'ו\'', 'ז\'', 'ח\'', 'ט\'',
|
28
|
+
'י\'', 'י"א', 'י"ב', 'י"ג', 'י"ד', 'ט"ו', 'ט"ז', 'י"ז', 'י"ח', 'י"ח',
|
29
|
+
'י"ט', 'כ\'' , 'כ"א', 'כ"ב', 'כ"ג', 'כ"ד', 'כ"ה', 'כ"ו', 'כ"ז', 'כ"ט', 'ל\'' ]
|
30
|
+
ONES = [ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט' ]
|
31
|
+
TENS = [ '', 'י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ' ]
|
32
|
+
|
33
|
+
|
34
|
+
# Accessors for base Hebrew day, month, and year
|
35
|
+
attr_accessor :hd, :hm, :hy
|
36
|
+
|
37
|
+
# Constructor.
|
38
|
+
# When passed 1 parameter, the one parameter must either be an integer
|
39
|
+
# representing a Julian day number, or some kind of date object (e.g. Ruby's
|
40
|
+
# Date class) that responds to the +jd+ method to expose a Julian day
|
41
|
+
# number.
|
42
|
+
# When passed 3 parameters, they are +day+,+month+,+year+ of the
|
43
|
+
# Hebrew date, as integers.
|
44
|
+
def initialize(*params)
|
45
|
+
if params.size == 3
|
46
|
+
@hd = params[0]
|
47
|
+
@hm = params[1]
|
48
|
+
@hy = params[2]
|
49
|
+
convert_from_hebrew
|
50
|
+
elsif params.size == 1
|
51
|
+
jd=params[0]
|
52
|
+
if jd
|
53
|
+
if jd.is_a? Integer
|
54
|
+
@jd = jd
|
55
|
+
elsif jd.respond_to? :jd
|
56
|
+
@jd = jd.jd
|
57
|
+
end
|
58
|
+
convert_from_julian
|
59
|
+
end
|
60
|
+
else
|
61
|
+
raise ArgumentError
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def day
|
66
|
+
return @hd
|
67
|
+
end
|
68
|
+
|
69
|
+
# Provide Hebrew transliterated month display name
|
70
|
+
def month
|
71
|
+
return @hm
|
72
|
+
end
|
73
|
+
|
74
|
+
# return Hebrew year
|
75
|
+
def year
|
76
|
+
return @hy
|
77
|
+
end
|
78
|
+
|
79
|
+
# return julian day number
|
80
|
+
def jd
|
81
|
+
return @jd
|
82
|
+
end
|
83
|
+
|
84
|
+
# Provide Hebrew month name transiterated into Englsih
|
85
|
+
def month_name
|
86
|
+
return MONTH_NAMES[@hm]
|
87
|
+
end
|
88
|
+
|
89
|
+
# Provide Hebrew month name in Hebrew letters
|
90
|
+
def heb_month_name
|
91
|
+
return HEB_MONTH_NAMES[@hm]
|
92
|
+
end
|
93
|
+
|
94
|
+
# Provide Hebrew day of the month, in hebrew letters.
|
95
|
+
def heb_day_name
|
96
|
+
return HEB_DAYS[@hd]
|
97
|
+
end
|
98
|
+
|
99
|
+
# Provide Hebrew year number in hebrew letters
|
100
|
+
def heb_year_name
|
101
|
+
year = @hy
|
102
|
+
raise RangeError, "only 5700 - 5899 supported" if year < 5700 || year >= 5900
|
103
|
+
prefix = year / 100 == 57 ? "התש" : "התת"
|
104
|
+
suffix = HebrewDate.heb_number(year % 100)
|
105
|
+
full = prefix + suffix
|
106
|
+
end
|
107
|
+
|
108
|
+
# Provide Hebrew display date
|
109
|
+
def heb_date
|
110
|
+
return heb_day_name + " ב" + heb_month_name + " " + heb_year_name
|
111
|
+
end
|
112
|
+
|
113
|
+
# Return the representation in hebrew letters for a number less than 100
|
114
|
+
def self.heb_number(num)
|
115
|
+
raise ArgumentError if num>100 or num < 0
|
116
|
+
return 'ט"ו' if num == 15
|
117
|
+
return 'ט"ז' if num == 16
|
118
|
+
if num < 10
|
119
|
+
return '"' + ONES[ num % 10 ]
|
120
|
+
elsif num % 10 == 0
|
121
|
+
return '"' + TENS[ num / 10 ]
|
122
|
+
else
|
123
|
+
return TENS[ num / 10 ] + '"' + ONES[ num % 10 ]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Is a given Hebrew year a leap year ?
|
128
|
+
def self.leap?(year)
|
129
|
+
return ((year * 7) + 1).modulo(19) < 7
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
# How many months are there in a Hebrew year (12 = normal, 13 = leap)
|
134
|
+
def self.year_months(year)
|
135
|
+
return leap?(year) ? 13 : 12
|
136
|
+
end
|
137
|
+
|
138
|
+
# How many days are in a Hebrew year ?
|
139
|
+
def self.year_days(year)
|
140
|
+
return to_jd(year + 1, 7, 1) - to_jd(year, 7, 1)
|
141
|
+
end
|
142
|
+
|
143
|
+
# How many days are in a given month of a given year
|
144
|
+
def self.month_days(year, month)
|
145
|
+
# First of all, dispose of fixed-length 29 day months
|
146
|
+
case
|
147
|
+
when (month == 2 || month == 4 || month == 6 || month == 10 || month == 13)
|
148
|
+
return 29
|
149
|
+
|
150
|
+
# If it's not a leap year, Adar has 29 days
|
151
|
+
when (month == 12 && !leap?(year)) then
|
152
|
+
return 29
|
153
|
+
|
154
|
+
# If it's Cheshvan, days depend on length of year
|
155
|
+
when month == 8 && year_days(year).modulo(10) != 5 then
|
156
|
+
return 29
|
157
|
+
|
158
|
+
# Similarly, Kislev varies with the length of year
|
159
|
+
when (month == 9 && (year_days(year).modulo(10) == 3)) then
|
160
|
+
return 29
|
161
|
+
|
162
|
+
# Nope, it's a 30 day month
|
163
|
+
else
|
164
|
+
return 30
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# internal conversion method to keep fields syncronized with julian day number
|
169
|
+
def convert_from_julian
|
170
|
+
dateArray = HebrewDate.jd_to_hebrew(@jd)
|
171
|
+
@hy = dateArray[0]
|
172
|
+
@hm = dateArray[1]
|
173
|
+
@hd = dateArray[2]
|
174
|
+
end
|
175
|
+
|
176
|
+
# internal conversion method to keep fields syncronized with julian day number
|
177
|
+
def convert_from_hebrew
|
178
|
+
@jd = HebrewDate.to_jd(@hy, @hm, @hd)
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.days_in_prior_years(year)
|
182
|
+
months_elapsed = (year - 1) / 19 * 235 + # Months in complete cycles so far
|
183
|
+
12 * ((year - 1) % 19) + # Regular months in this cycle
|
184
|
+
(1 + 7 * ((year - 1) % 19)) / 19 # Leap months in this cycle
|
185
|
+
parts_elapsed = 204 + 793 * (months_elapsed % 1080)
|
186
|
+
hours_elapsed = 5 +
|
187
|
+
12 * months_elapsed +
|
188
|
+
793 * ( months_elapsed / 1080) +
|
189
|
+
parts_elapsed / 1080
|
190
|
+
parts = 1080 * (hours_elapsed % 24) + (parts_elapsed % 1080)
|
191
|
+
day = 1 + 29 * months_elapsed + hours_elapsed / 24
|
192
|
+
|
193
|
+
if parts >= 19440 or #If the new moon is at or after midday,
|
194
|
+
( day % 7 == 2 and #...or is on a Tuesday...
|
195
|
+
parts >= 9924 and # at 9 hours, 204 parts or later...
|
196
|
+
not leap?(year) # of a common year
|
197
|
+
) or
|
198
|
+
( day % 7 == 1 and #...or is on a Monday...
|
199
|
+
parts >= 16789 and # at 15 hours, 589 parts or later...
|
200
|
+
leap?(year - 1) # at the end of a leap year
|
201
|
+
)
|
202
|
+
then
|
203
|
+
day += 1 #then postpone Rosh HaShanah one day
|
204
|
+
end
|
205
|
+
|
206
|
+
#If Rosh HaShanah would occur on Sunday, Wednesday, or Friday
|
207
|
+
#Then postpone it one more day
|
208
|
+
day += 1 if [0,3,5].include?(day % 7)
|
209
|
+
|
210
|
+
return day + HEBREW_EPOCH + 1
|
211
|
+
end
|
212
|
+
|
213
|
+
# Convert hebrew date to julian day number
|
214
|
+
def self.to_jd(year, month, day)
|
215
|
+
months = year_months(year)
|
216
|
+
|
217
|
+
jd = day
|
218
|
+
|
219
|
+
if (month < 7) then
|
220
|
+
for mon in 7..months
|
221
|
+
jd += month_days(year, mon)
|
222
|
+
end
|
223
|
+
|
224
|
+
for mon in 1...month
|
225
|
+
jd += month_days(year, mon)
|
226
|
+
end
|
227
|
+
else
|
228
|
+
for mon in 7...month
|
229
|
+
jd += month_days(year, mon)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
jd += days_in_prior_years(year)
|
234
|
+
|
235
|
+
return jd
|
236
|
+
end
|
237
|
+
|
238
|
+
# Convert Julian day number to Hebrew date
|
239
|
+
# This works by making multiple calls to
|
240
|
+
# to_jd, and is this very slow
|
241
|
+
def self.jd_to_hebrew(jd)
|
242
|
+
greg_date = Date.jd(jd)
|
243
|
+
month = [nil,9,10,11,12,1,2,3,4,7,7,7,8][greg_date.month]
|
244
|
+
day = greg_date.mday
|
245
|
+
year = 3760 + greg_date.year
|
246
|
+
|
247
|
+
year += 1 while jd >= to_jd(year + 1, 7, 1)
|
248
|
+
length = year_months(year)
|
249
|
+
month = (1 + month % length) while jd > to_jd(year,month,month_days(year,month))
|
250
|
+
|
251
|
+
day = jd - to_jd(year,month,1) + 1
|
252
|
+
|
253
|
+
return [year, month, day]
|
254
|
+
end
|
255
|
+
|
256
|
+
end # class
|
257
|
+
|
258
|
+
end # module
|
@@ -0,0 +1,200 @@
|
|
1
|
+
# Unit tests for Hebruby module to convert julian dates to hebrew dates, and vice-versa
|
2
|
+
# Written by Ron Evans
|
3
|
+
# Additional code contributed by Joshua Harvey
|
4
|
+
# Based on Javascript code from John Walker (http://www.fourmilab.ch/documents/calendar/)
|
5
|
+
require 'test/unit'
|
6
|
+
require File.dirname(__FILE__)+'/../lib/hebruby'
|
7
|
+
require 'date'
|
8
|
+
|
9
|
+
class TC_MyTest2 < Test::Unit::TestCase
|
10
|
+
# def setup
|
11
|
+
# end
|
12
|
+
|
13
|
+
# def teardown
|
14
|
+
# end
|
15
|
+
|
16
|
+
#
|
17
|
+
# hebrew to julian tests
|
18
|
+
#
|
19
|
+
|
20
|
+
def test_h2j_1
|
21
|
+
@hb = Hebruby::HebrewDate.new(Date.new(2010, 1, 1))
|
22
|
+
assert_equal(10, @hb.month, "Wrong month.")
|
23
|
+
assert_equal("Tevet", @hb.month_name, "Wrong month name.")
|
24
|
+
assert_equal(5770, @hb.year, "Wrong year.")
|
25
|
+
assert_equal(15, @hb.day, "Wrong day.")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_h2j_2
|
29
|
+
@hb = Hebruby::HebrewDate.new(Date.new(2005, 1, 15))
|
30
|
+
assert_equal(11, @hb.month, "Wrong month.")
|
31
|
+
assert_equal("Shvat", @hb.month_name, "Wrong month name.")
|
32
|
+
assert_equal(5765, @hb.year, "Wrong year.")
|
33
|
+
assert_equal(5, @hb.day, "Wrong day.")
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_h2j_3
|
37
|
+
@hb = Hebruby::HebrewDate.new(Date.new(2005, 4, 10))
|
38
|
+
assert_equal(1, @hb.day, "Wrong day.")
|
39
|
+
assert_equal(1, @hb.month, "Wrong month.")
|
40
|
+
assert_equal("Nissan", @hb.month_name, "Wrong month name.")
|
41
|
+
assert_equal(5765, @hb.year, "Wrong year.")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_h2j_4
|
45
|
+
@hb = Hebruby::HebrewDate.new(Date.new(1966, 4, 10))
|
46
|
+
assert_equal(1, @hb.month, "Wrong month.")
|
47
|
+
assert_equal("Nissan", @hb.month_name, "Wrong month name.")
|
48
|
+
assert_equal(5726, @hb.year, "Wrong year.")
|
49
|
+
assert_equal(20, @hb.day, "Wrong day.")
|
50
|
+
end
|
51
|
+
|
52
|
+
#using the same date as the previous test, this time we pass
|
53
|
+
#an integer rather than a Date object
|
54
|
+
def test_julianday_integer
|
55
|
+
@hb = Hebruby::HebrewDate.new(Date.new(1966, 4, 10).jd)
|
56
|
+
assert_equal(1, @hb.month, "Wrong month.")
|
57
|
+
assert_equal("Nissan", @hb.month_name, "Wrong month name.")
|
58
|
+
assert_equal(5726, @hb.year, "Wrong year.")
|
59
|
+
assert_equal(20, @hb.day, "Wrong day.")
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_h2j_5
|
63
|
+
@hb = Hebruby::HebrewDate.new(Date.new(1998, 12, 22))
|
64
|
+
assert_equal(10, @hb.month, "Wrong month.")
|
65
|
+
assert_equal("Tevet", @hb.month_name, "Wrong month name.")
|
66
|
+
assert_equal(5759, @hb.year, "Wrong year.")
|
67
|
+
assert_equal(3, @hb.day, "Wrong day.")
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_h2j_6
|
71
|
+
@hb = Hebruby::HebrewDate.new(Date.new(1968, 6, 28))
|
72
|
+
assert_equal(4, @hb.month, "Wrong month.")
|
73
|
+
assert_equal("Tamuz", @hb.month_name, "Wrong month name.")
|
74
|
+
assert_equal(5728, @hb.year, "Wrong year.")
|
75
|
+
assert_equal(2, @hb.day, "Wrong day.")
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_h2j_7
|
79
|
+
@hb = Hebruby::HebrewDate.new(Date.new(1941, 12, 10))
|
80
|
+
assert_equal(9, @hb.month, "Wrong month.")
|
81
|
+
assert_equal("Kislev", @hb.month_name, "Wrong month name.")
|
82
|
+
assert_equal(5702, @hb.year, "Wrong year.")
|
83
|
+
assert_equal(20, @hb.day, "Wrong day.")
|
84
|
+
end
|
85
|
+
|
86
|
+
#Test the 30th of a 30-day month
|
87
|
+
def test_h2j_8
|
88
|
+
@hb = Hebruby::HebrewDate.new(Date.new(2009, 4, 24))
|
89
|
+
assert_equal(1, @hb.month, "Wrong month.")
|
90
|
+
assert_equal("Nissan", @hb.month_name, "Wrong month name.")
|
91
|
+
assert_equal(5769, @hb.year, "Wrong year.")
|
92
|
+
assert_equal(30, @hb.day, "Wrong day.")
|
93
|
+
end
|
94
|
+
#
|
95
|
+
#Test the 29th of a 29-day month
|
96
|
+
def test_h2j_9
|
97
|
+
@hb = Hebruby::HebrewDate.new(Date.new(2008, 1, 7))
|
98
|
+
assert_equal(10, @hb.month, "Wrong month.")
|
99
|
+
assert_equal("Tevet", @hb.month_name, "Wrong month name.")
|
100
|
+
assert_equal(5768, @hb.year, "Wrong year.")
|
101
|
+
assert_equal(29, @hb.day, "Wrong day.")
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_jd
|
105
|
+
orig=2454946
|
106
|
+
|
107
|
+
assert_equal(orig,Hebruby::HebrewDate.to_jd(*
|
108
|
+
Hebruby::HebrewDate.jd_to_hebrew(orig)),
|
109
|
+
"Julian day number #{orig} didn't make a round trip using class methods")
|
110
|
+
|
111
|
+
hb=Hebruby::HebrewDate.new(orig)
|
112
|
+
hb.convert_from_julian
|
113
|
+
hb.convert_from_hebrew
|
114
|
+
assert_equal(orig,hb.jd,
|
115
|
+
"Julian day number #{orig} didn't make a round trip using instance methods")
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_to_jd
|
119
|
+
assert_equal(2454944,Hebruby::HebrewDate.to_jd(5769,1,28))
|
120
|
+
assert_equal(2454945,Hebruby::HebrewDate.to_jd(5769,1,29))
|
121
|
+
assert_equal(2454946,Hebruby::HebrewDate.to_jd(5769,1,30))
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# julian to hebrew tests
|
126
|
+
#
|
127
|
+
|
128
|
+
def test_j2h_1
|
129
|
+
@hb = Hebruby::HebrewDate.new(15,10,5770)
|
130
|
+
assert_equal(15, @hb.day, "Wrong day.")
|
131
|
+
assert_equal(10, @hb.month, "Wrong month.")
|
132
|
+
assert_equal("Tevet", @hb.month_name, "Wrong month name.")
|
133
|
+
assert_equal(5770, @hb.year, "Wrong year.")
|
134
|
+
assert_equal('התש"ע', @hb.heb_year_name, "Wrong year.")
|
135
|
+
assert_equal(Date.new(2010, 1, 1).jd, @hb.jd, "Wrong Julian date.")
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_j2h_2
|
139
|
+
@hb = Hebruby::HebrewDate.new(5,11,5765)
|
140
|
+
assert_equal(5, @hb.day, "Wrong day.")
|
141
|
+
assert_equal(11, @hb.month, "Wrong month.")
|
142
|
+
assert_equal("Shvat", @hb.month_name, "Wrong month name.")
|
143
|
+
assert_equal(5765, @hb.year, "Wrong year.")
|
144
|
+
assert_equal(Date.new(2005, 1, 15).jd, @hb.jd, "Wrong Julian date.")
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_j2h_3
|
148
|
+
@hb = Hebruby::HebrewDate.new(1,1,5765)
|
149
|
+
assert_equal(1, @hb.day, "Wrong day.")
|
150
|
+
assert_equal(1, @hb.month, "Wrong month.")
|
151
|
+
assert_equal("Nissan", @hb.month_name, "Wrong month name.")
|
152
|
+
assert_equal(5765, @hb.year, "Wrong year.")
|
153
|
+
assert_equal(Date.new(2005, 4, 10).jd, @hb.jd, "Wrong Julian date.")
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_j2h_4
|
157
|
+
@hb = Hebruby::HebrewDate.new(20,1,5726)
|
158
|
+
assert_equal(20, @hb.day, "Wrong day.")
|
159
|
+
assert_equal(1, @hb.month, "Wrong month.")
|
160
|
+
assert_equal(5726, @hb.year, "Wrong year.")
|
161
|
+
assert_equal("Nissan", @hb.month_name, "Wrong month name.")
|
162
|
+
assert_equal(Date.new(1966, 4, 10).jd, @hb.jd, "Wrong Julian date.")
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_j2h_5
|
166
|
+
@hb = Hebruby::HebrewDate.new(3,10,5759)
|
167
|
+
assert_equal(3, @hb.day, "Wrong day.")
|
168
|
+
assert_equal(10, @hb.month, "Wrong month.")
|
169
|
+
assert_equal("Tevet", @hb.month_name, "Wrong month name.")
|
170
|
+
assert_equal(5759, @hb.year, "Wrong year.")
|
171
|
+
assert_equal(Date.new(1998, 12, 22).jd, @hb.jd, "Wrong Julian date.")
|
172
|
+
assert_equal(%q{ג' בטבת התשנ"ט}, @hb.heb_date)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_j2h_6
|
176
|
+
@hb = Hebruby::HebrewDate.new(2,4,5728)
|
177
|
+
assert_equal(2, @hb.day, "Wrong day.")
|
178
|
+
assert_equal(4, @hb.month, "Wrong month.")
|
179
|
+
assert_equal("Tamuz", @hb.month_name, "Wrong month name.")
|
180
|
+
assert_equal("תמוז", @hb.heb_month_name, "Wrong month name.")
|
181
|
+
assert_equal(5728, @hb.year, "Wrong year.")
|
182
|
+
assert_equal('התשכ"ח', @hb.heb_year_name, "Wrong year.")
|
183
|
+
assert_equal(Date.new(1968, 6, 28).jd, @hb.jd, "Wrong Julian date.")
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_j2h_7
|
187
|
+
@hb = Hebruby::HebrewDate.new(20,9,5702)
|
188
|
+
assert_equal(20, @hb.day, "Wrong day.")
|
189
|
+
assert_equal(9, @hb.month, "Wrong month.")
|
190
|
+
assert_equal("Kislev", @hb.month_name, "Wrong month name.")
|
191
|
+
assert_equal("כסלו", @hb.heb_month_name, "Wrong month name.")
|
192
|
+
assert_equal(5702, @hb.year, "Wrong year.")
|
193
|
+
assert_equal('התש"ב', @hb.heb_year_name, "Wrong year.")
|
194
|
+
assert_equal(Date.new(1941, 12, 10).jd, @hb.jd, "Wrong Julian date.")
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
end
|
200
|
+
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hebruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ron Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Hebruby is a Ruby library to convert julian dates to hebrew dates, and vice-versa.
|
17
|
+
email: ""
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGELOG
|
24
|
+
- lib/hebruby.rb
|
25
|
+
- LICENSE
|
26
|
+
- README
|
27
|
+
- README.rdoc
|
28
|
+
files:
|
29
|
+
- CHANGELOG
|
30
|
+
- lib/hebruby.rb
|
31
|
+
- LICENSE
|
32
|
+
- Rakefile
|
33
|
+
- README
|
34
|
+
- README.rdoc
|
35
|
+
- test/hebruby_tests.rb
|
36
|
+
- Manifest
|
37
|
+
- hebruby.gemspec
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://deadprogrammersociety.com/
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message: "*** Hebruby was installed ***"
|
43
|
+
rdoc_options:
|
44
|
+
- --line-numbers
|
45
|
+
- --inline-source
|
46
|
+
- --title
|
47
|
+
- Hebruby
|
48
|
+
- --main
|
49
|
+
- README
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "1.2"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: hebruby
|
67
|
+
rubygems_version: 1.3.3
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Hebruby is a Ruby library to convert julian dates to hebrew dates, and vice-versa.
|
71
|
+
test_files: []
|
72
|
+
|