Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/date_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.months_between(date1, date2) ⇒ Object

return array with one entry for each month between date1 and date2 (inclusive)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/date_helper.rb', line 10

def self.months_between(date1, date2)
  months = []
  if date2 < date1
    start_date = Date.civil(date2.year, date2.month, 1)
    end_date = Date.civil(date1.year, date1.month, 1)
  else
    start_date = Date.civil(date1.year, date1.month, 1)
    end_date = Date.civil(date2.year, date2.month, 1)
  end

  while (start_date < end_date)
    months << start_date
    start_date = start_date >>1
  end

  months << end_date
end

.utc_times(dates) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/date_helper.rb', line 29

def self.utc_times(dates)
  result = Array.new
  for date in dates
    result << date.to_utc_time
  end
  result
end

Instance Method Details

#to_utc_timeObject

return a Time object at 00:00:00 UTC on the given Date



39
40
41
# File 'lib/date_helper.rb', line 39

def to_utc_time
  Time.utc(self.year,self.month,self.day)
end