Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/data/time.rb

Overview

Extension of the ruby Time class to provide necessary operations on a Time object

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.days_in_month(year, month) ⇒ Integer

singleton method to determine the number of days for the actual month and year

Parameters:

  • year (Integer)

    the considered year

  • month (Integer)

    the considered month

Returns:

  • (Integer)

    the required day of the month



19
20
21
# File 'lib/data/time.rb', line 19

def self.days_in_month(year, month)
  Date.new(year, month, -1).day
end

Instance Method Details

#get_int_wdayInteger

determines the day of the week, with a week starting on monday and ending on sunday and values in [0,6]

monday == 0
...
sunday == 6

Returns:

  • (Integer)

    the week day of the actual Time object



29
30
31
32
33
# File 'lib/data/time.rb', line 29

def get_int_wday
  int_wday = self.wday - 1
  return int_wday if (int_wday >= 0)
  return 6
end

#next_monthTime

determines the start of the next month, based on the actual value

Returns:

  • (Time)

    a new Time object stating the first day of the next month



9
10
11
12
# File 'lib/data/time.rb', line 9

def next_month
  return Time.new(year, month + 1) if (month < 12)
  return Time.new(year+1, 1)        if (month == 12)
end