Class: Date

Inherits:
Object show all
Defined in:
opal/fron/core_ext/date.rb

Overview

Methods for date class

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.last_weekRange

Returns a range for last week

Returns:

  • (Range)

    The days as range



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

Returns:

  • (Date)

    The date



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_weekRange

Returns a range for this week

Returns:

  • (Range)

    The days as range



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

Returns:

  • (Range)

    The days as range



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_monthDate

Returns the begging of the month

Returns:

  • (Date)

    The date



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_monthDate

Returns the end of the month

Returns:

  • (Date)

    The date



54
55
56
# File 'opal/fron/core_ext/date.rb', line 54

def end_of_month
  self.class.new year, month + 1, 0
end