Module: FeCoreExt::CoreExt::Date

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)


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

def end_of_month?
  self == end_of_month
end

#nth_weekday(nth, weekday) ⇒ Object



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

def nth_weekday(nth, weekday)
  first_day = Date.new(self.year, self.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



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

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

#to_time_rangeObject



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

def to_time_range
  Range.new(beginning_of_day, end_of_day)
end