Module: FeCoreExt::CoreExt::DateMethods

Included in:
Date
Defined in:
lib/fe_core_ext/core_ext/date.rb

Instance Method Summary collapse

Instance Method Details

#end_of_month?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/fe_core_ext/core_ext/date.rb', line 9

def end_of_month?
  self == end_of_month
end

#nth_weekday(nth, weekday) ⇒ Object



21
22
23
24
25
26
# File 'lib/fe_core_ext/core_ext/date.rb', line 21

def nth_weekday(nth, weekday)
  first_day = Date.new(year, month, 1)
  weekdays_hash = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 }
  weekday_dates = (first_day..first_day.end_of_month).select { |d| d.wday == weekdays_hash[weekday] }
  weekday_dates[nth - 1]
end

#range(duration) ⇒ Object



13
14
15
# File 'lib/fe_core_ext/core_ext/date.rb', line 13

def range(duration)
  Range.new(*[self + duration, self].minmax)
end

#to_time_rangeObject



17
18
19
# File 'lib/fe_core_ext/core_ext/date.rb', line 17

def to_time_range
  Range.new(beginning_of_day, end_of_day)
end