Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/supplement/date.rb,
lib/supplement/date.rb

Constant Summary collapse

EASTER =
"Easter"

Class Method Summary collapse

Instance Method Summary collapse

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

#cwstartObject



63
64
65
# File 'lib/supplement/date.rb', line 63

def cwstart
  self - (cwday-1)
end

#dObject



12
# File 'lib/supplement/date.rb', line 12

def d ; day   ; end

#first_of_monthObject



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

#mObject



11
# File 'lib/supplement/date.rb', line 11

def m ; month ; end

#months_backward(n) ⇒ Object



81
82
83
84
85
# File 'lib/supplement/date.rb', line 81

def months_backward n
  res = self
  n.times { res = res.prev_month }
  res
end

#months_forward(n) ⇒ Object



75
76
77
78
79
# File 'lib/supplement/date.rb', line 75

def months_forward n
  res = self
  n.times { res = res.next_month }
  res
end

#quarterObject



55
56
57
# File 'lib/supplement/date.rb', line 55

def quarter
  (month-1) / 3 + 1
end

#to_aObject



14
# File 'lib/supplement/date.rb', line 14

def to_a ; [ year, month, day ] ; end

#to_dateObject



111
# File 'lib/supplement/date.rb', line 111

def to_date     ; self ; end

#to_datetimeObject



112
# File 'lib/supplement/date.rb', line 112

def to_datetime ; DateTime.new! Date.jd_to_ajd(jd,0,0), @of, @sg ; end

#to_timeObject



110
# File 'lib/supplement/date.rb', line 110

def to_time     ; Time.local year, mon, mday ; 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

#wstartObject



59
60
61
# File 'lib/supplement/date.rb', line 59

def wstart
  self - wday
end

#yObject



10
# File 'lib/supplement/date.rb', line 10

def y ; year  ; end