Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/supplement/date.rb
Constant Summary collapse
- EASTER =
"Easter"
Class Method Summary collapse
- .easter_western(year) ⇒ Object (also: easter)
Instance Method Summary collapse
- #cwstart ⇒ Object
- #d ⇒ Object
- #first_of_month ⇒ Object
- #m ⇒ Object
- #quarter ⇒ Object
- #to_a ⇒ Object
- #workday_after(n) ⇒ Object
- #wstart ⇒ Object
- #y ⇒ Object
Class Method Details
.easter_western(year) ⇒ Object Also known as: easter
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/supplement/date.rb', line 21 def easter_western year # This is after Donald E. Knuth and it works for both # Julian (1582 and before) and Gregorian (1583 and after) calendars. g = year%19 + 1 # golden number c = year/100 + 1 # century x = (3*c/4) - 12 # corrections z = (8*c+5)/25 - 5 d = 5*year/4 - x - 10 # March((-d)%7)th is Sunday e = (11*g + 20 + z - x) % 30 # moon phase e += 1 if e == 25 and g > 11 or e == 24 n = 44 - e # full moon n += 30 if n < 21 month = 3 day = n+7 - (d+n)%7 if day > 31 then month += 1 day -= 31 end civil year, month, day end |
Instance Method Details
#cwstart ⇒ Object
63 64 65 |
# File 'lib/supplement/date.rb', line 63 def cwstart self - (cwday-1) end |
#d ⇒ Object
12 |
# File 'lib/supplement/date.rb', line 12 def d ; day ; end |
#first_of_month ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/supplement/date.rb', line 67 def first_of_month if day == 1 then self else self.class.civil year, month, 1 end end |
#m ⇒ Object
11 |
# File 'lib/supplement/date.rb', line 11 def m ; month ; end |
#quarter ⇒ Object
55 56 57 |
# File 'lib/supplement/date.rb', line 55 def quarter (month-1) / 3 + 1 end |
#to_a ⇒ Object
14 |
# File 'lib/supplement/date.rb', line 14 def to_a ; [ year, month, day ] ; end |
#workday_after(n) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/supplement/date.rb', line 46 def workday_after n r = self + n case r.wday when 0 then r += 1 when 6 then r += 2 end r end |
#wstart ⇒ Object
59 60 61 |
# File 'lib/supplement/date.rb', line 59 def wstart self - wday end |
#y ⇒ Object
10 |
# File 'lib/supplement/date.rb', line 10 def y ; year ; end |