Module: FeCoreExt::CoreExt::Date
- Included in:
- Date
- Defined in:
- lib/fe_core_ext/core_ext/date.rb
Instance Method Summary collapse
- #end_of_month? ⇒ Boolean
- #nth_weekday(nth, weekday) ⇒ Object
- #range(duration) ⇒ Object
- #to_time_range ⇒ Object
Instance Method Details
#end_of_month? ⇒ Boolean
10 11 12 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 10 def end_of_month? self == end_of_month end |
#nth_weekday(nth, weekday) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 22 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
14 15 16 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 14 def range(duration) Range.new(*[self + duration, self].minmax) end |
#to_time_range ⇒ Object
18 19 20 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 18 def to_time_range Range.new(beginning_of_day, end_of_day) end |