Module: TimeUtil

Included in:
IceCube
Defined in:
lib/ice_cube/time_util.rb

Constant Summary collapse

LeapYearMonthDays =
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
CommonYearMonthDays =
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

Class Method Summary collapse

Class Method Details

.days_in_month(date) ⇒ Object



14
15
16
# File 'lib/ice_cube/time_util.rb', line 14

def self.days_in_month(date)
  is_leap?(date) ? LeapYearMonthDays[date.month - 1] : CommonYearMonthDays[date.month - 1]
end

.days_in_year(date) ⇒ Object



10
11
12
# File 'lib/ice_cube/time_util.rb', line 10

def self.days_in_year(date)
  is_leap?(date) ? 366 : 365
end

.is_leap?(date) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/ice_cube/time_util.rb', line 6

def self.is_leap?(date)
  (date.year % 4 == 0 && date.year % 100 != 0) || (date.year % 400 == 0)
end