Class: Hebruby::HebrewDate
- Inherits:
-
Object
- Object
- Hebruby::HebrewDate
- Defined in:
- lib/hebruby.rb
Constant Summary collapse
- HEBREW_EPOCH =
347995.5
- MONTH_NAMES =
%w{none Nissan Iyar Sivan Tamuz Av Elul Tishrei Chesvan Kislev Tevet Shvat Adar Veadar}
- HEB_MONTH_NAMES =
[ nil, 'ניסן', 'אייר', 'סיון', 'תמוז', 'אב', 'אלול', 'תשרי', 'חשון', 'כסלו', 'טבת', 'שבט', 'אדר', 'אדר א\'', 'אדר ב\'']
- HEB_DAYS =
[ nil, 'א\'', 'ב\'', 'ג\'', 'ד\'', 'ה\'', 'ו\'', 'ז\'', 'ח\'', 'ט\'', 'י\'', 'י"א', 'י"ב', 'י"ג', 'י"ד', 'ט"ו', 'ט"ז', 'י"ז', 'י"ח', 'י"ח', 'י"ט', 'כ\'' , 'כ"א', 'כ"ב', 'כ"ג', 'כ"ד', 'כ"ה', 'כ"ו', 'כ"ז', 'כ"ט', 'ל\'' ]
- ONES =
[ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט' ]
- TENS =
[ '', 'י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ' ]
Instance Attribute Summary collapse
-
#hd ⇒ Object
Accessors for base Hebrew day, month, and year.
-
#hm ⇒ Object
Accessors for base Hebrew day, month, and year.
-
#hy ⇒ Object
Accessors for base Hebrew day, month, and year.
Class Method Summary collapse
-
.new1(hd, hm, hy) ⇒ Object
additional constructor from hebrew date to julian.
Instance Method Summary collapse
- #convert_from_hebrew ⇒ Object
- #convert_from_julian ⇒ Object
- #day ⇒ Object
-
#heb_date ⇒ Object
Provide correct complete Hebrew display date.
-
#heb_day_name ⇒ Object
Provide correct Hebrew day display name.
-
#heb_month_display_name(month) ⇒ Object
Provide correct Hebrew month display name.
-
#heb_month_name ⇒ Object
Provide correct Hebrew month display name.
-
#heb_number(num) ⇒ Object
Provide correct Hebrew number display.
-
#heb_year_name ⇒ Object
Provide correct Hebrew year display name.
-
#initialize(jd = nil) ⇒ HebrewDate
constructor
standard constructor from julian to hebrew date.
-
#jd ⇒ Object
return julian date converted from hebrew date.
-
#leap?(year) ⇒ Boolean
Is a given Hebrew year a leap year ?.
-
#month ⇒ Object
Provide correct Hebrew transliterated month display name.
-
#month_days(year, month) ⇒ Object
How many days are in a given month of a given year.
-
#month_display_name(month) ⇒ Object
Provide correct Hebrew transliterated month display name.
-
#month_name ⇒ Object
Provide correct Hebrew transliterated month display name.
-
#year ⇒ Object
return Hebrew year converted from julian date.
-
#year_days(year) ⇒ Object
How many days are in a Hebrew year ?.
-
#year_months(year) ⇒ Object
How many months are there in a Hebrew year (12 = normal, 13 = leap).
Constructor Details
#initialize(jd = nil) ⇒ HebrewDate
standard constructor from julian to hebrew date
39 40 41 42 43 44 |
# File 'lib/hebruby.rb', line 39 def initialize(jd=nil) if jd @jd = jd convert_from_julian end end |
Instance Attribute Details
#hd ⇒ Object
Accessors for base Hebrew day, month, and year
36 37 38 |
# File 'lib/hebruby.rb', line 36 def hd @hd end |
#hm ⇒ Object
Accessors for base Hebrew day, month, and year
36 37 38 |
# File 'lib/hebruby.rb', line 36 def hm @hm end |
#hy ⇒ Object
Accessors for base Hebrew day, month, and year
36 37 38 |
# File 'lib/hebruby.rb', line 36 def hy @hy end |
Class Method Details
.new1(hd, hm, hy) ⇒ Object
additional constructor from hebrew date to julian
47 48 49 50 51 52 53 54 |
# File 'lib/hebruby.rb', line 47 def self.new1(hd, hm, hy) me = new me.hd = hd me.hm = hm me.hy = hy me.convert_from_hebrew return me end |
Instance Method Details
#convert_from_hebrew ⇒ Object
134 135 136 |
# File 'lib/hebruby.rb', line 134 def convert_from_hebrew @jd = to_jd(@hy, @hm, @hd).jd end |
#convert_from_julian ⇒ Object
127 128 129 130 131 132 |
# File 'lib/hebruby.rb', line 127 def convert_from_julian dateArray = jd_to_hebrew(@jd) @hy = dateArray[0] @hm = dateArray[1] @hd = dateArray[2] end |
#day ⇒ Object
56 57 58 |
# File 'lib/hebruby.rb', line 56 def day return @hd end |
#heb_date ⇒ Object
Provide correct complete Hebrew display date
100 101 102 |
# File 'lib/hebruby.rb', line 100 def heb_date return heb_day_name + " ב" + heb_month_name + " " + heb_year_name end |
#heb_day_name ⇒ Object
Provide correct Hebrew day display name
86 87 88 |
# File 'lib/hebruby.rb', line 86 def heb_day_name return HEB_DAYS[@hd] end |
#heb_month_display_name(month) ⇒ Object
Provide correct Hebrew month display name
123 124 125 |
# File 'lib/hebruby.rb', line 123 def heb_month_display_name(month) return HEB_MONTH_NAMES[month] end |
#heb_month_name ⇒ Object
Provide correct Hebrew month display name
81 82 83 |
# File 'lib/hebruby.rb', line 81 def heb_month_name return heb_month_display_name(@hm) end |
#heb_number(num) ⇒ Object
Provide correct Hebrew number display
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/hebruby.rb', line 105 def heb_number(num) return 'ט"ו' if num == 15 return 'ט"ז' if num == 16 if num < 10 return '"' + ONES[ num % 10 ] elsif num % 10 == 0 return '"' + TENS[ num / 10 ] else return TENS[ num / 10 ] + '"' + ONES[ num % 10 ] end end |
#heb_year_name ⇒ Object
Provide correct Hebrew year display name
91 92 93 94 95 96 97 |
# File 'lib/hebruby.rb', line 91 def heb_year_name year = @hy raise RangeError, "only 5700 - 5899 supported" if year < 5700 || year >= 5900 prefix = year / 100 == 57 ? "התש" : "התת" suffix = heb_number(year % 100) full = prefix + suffix end |
#jd ⇒ Object
return julian date converted from hebrew date
71 72 73 |
# File 'lib/hebruby.rb', line 71 def jd return @jd + 1 end |
#leap?(year) ⇒ Boolean
Is a given Hebrew year a leap year ?
139 140 141 |
# File 'lib/hebruby.rb', line 139 def leap?(year) return ((year * 7) + 1).modulo(19) < 7 end |
#month ⇒ Object
Provide correct Hebrew transliterated month display name
61 62 63 |
# File 'lib/hebruby.rb', line 61 def month return @hm end |
#month_days(year, month) ⇒ Object
How many days are in a given month of a given year
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/hebruby.rb', line 154 def month_days(year, month) # First of all, dispose of fixed-length 29 day months case when (month == 2 || month == 4 || month == 6 || month == 10 || month == 13) return 29 # If it's not a leap year, Adar has 29 days when (month == 12 && !leap?(year)) then return 29 # If it's Cheshvan, days depend on length of year when month == 8 && year_days(year).modulo(10) != 5 then return 29 # Similarly, Kislev varies with the length of year when (month == 9 && (year_days(year).modulo(10) == 3)) then return 29 # Nope, it's a 30 day month else return 30 end end |
#month_display_name(month) ⇒ Object
Provide correct Hebrew transliterated month display name
118 119 120 |
# File 'lib/hebruby.rb', line 118 def month_display_name(month) return MONTH_NAMES[month] end |
#month_name ⇒ Object
Provide correct Hebrew transliterated month display name
76 77 78 |
# File 'lib/hebruby.rb', line 76 def month_name return month_display_name(@hm) end |
#year ⇒ Object
return Hebrew year converted from julian date
66 67 68 |
# File 'lib/hebruby.rb', line 66 def year return @hy end |
#year_days(year) ⇒ Object
How many days are in a Hebrew year ?
149 150 151 |
# File 'lib/hebruby.rb', line 149 def year_days(year) return to_jd(year + 1, 7, 1) - to_jd(year, 7, 1) end |
#year_months(year) ⇒ Object
How many months are there in a Hebrew year (12 = normal, 13 = leap)
144 145 146 |
# File 'lib/hebruby.rb', line 144 def year_months(year) return leap?(year) ? 13 : 12 end |