Class: Date
Overview
Methods for date class
Class Method Summary collapse
-
.last_week ⇒ Range
Returns a range for last week.
-
.monday(date = Date.today) ⇒ Date
Returns the monday of the current week.
-
.this_week ⇒ Range
Returns a range for this week.
-
.week(date = Date.today) ⇒ Range
Returns the week days in the current week.
Instance Method Summary collapse
-
#beginning_of_month ⇒ Date
Returns the begging of the month.
-
#end_of_month ⇒ Date
Returns the end of the month.
Class Method Details
.last_week ⇒ Range
Returns a range for last week
16 17 18 |
# File 'opal/fron/core_ext/date.rb', line 16 def last_week Date.week(Date.today - 7) end |
.monday(date = Date.today) ⇒ Date
Returns the monday of the current week
23 24 25 26 27 28 29 30 31 32 33 |
# File 'opal/fron/core_ext/date.rb', line 23 def monday(date = Date.today) today = date day = today.wday diff = case day when 0 6 when 1..6 day - 1 end today - diff end |
.this_week ⇒ Range
Returns a range for this week
9 10 11 |
# File 'opal/fron/core_ext/date.rb', line 9 def this_week Date.week(Date.today) end |
.week(date = Date.today) ⇒ Range
Returns the week days in the current week
38 39 40 41 |
# File 'opal/fron/core_ext/date.rb', line 38 def week(date = Date.today) day = monday(date) (day..day + 6) end |
Instance Method Details
#beginning_of_month ⇒ Date
Returns the begging of the month
47 48 49 |
# File 'opal/fron/core_ext/date.rb', line 47 def beginning_of_month self.class.new year, month, 1 end |
#end_of_month ⇒ Date
Returns the end of the month
54 55 56 |
# File 'opal/fron/core_ext/date.rb', line 54 def end_of_month self.class.new year, month + 1, 0 end |