Class: Time

Inherits:
Object
  • Object
show all
Includes:
Hosemonkey::Time
Defined in:
lib/hosemonkey/ext/time.rb

Constant Summary

Constants included from Hosemonkey::Time

Hosemonkey::Time::COMMON_YEAR_DAYS_IN_MONTH, Hosemonkey::Time::DAYS_INTO_WEEK

Class Method Summary collapse

Methods included from Hosemonkey::Time

#advance, #change, #days_in_month, #to_short, #to_web, #to_z

Class Method Details

.local_time(*args) ⇒ Object

Wraps class method time_with_datetime_fallback with utc_or_local set to :local.



99
100
101
# File 'lib/hosemonkey/ext/time.rb', line 99

def local_time(*args)
  time_with_datetime_fallback(:local, *args)
end

.time_with_datetime_fallback(utc_or_local, year, month = 1, day = 1, hour = 0, min = 0, sec = 0, usec = 0) ⇒ Object

Copied directly from ActiveSupport Returns a new Time if requested year can be accommodated by Ruby’s Time class (i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture); otherwise returns a DateTime.



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/hosemonkey/ext/time.rb', line 106

def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
  time = ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)

  # This check is needed because Time.utc(y) returns a time object in the 2000s for 0 <= y <= 138.
  if time.year == year
    time
  else
    ::DateTime.civil_from_format(utc_or_local, year, month, day, hour, min, sec)
  end
rescue
  ::DateTime.civil_from_format(utc_or_local, year, month, day, hour, min, sec)
end

.utc_time(*args) ⇒ Object

Copied directly from ActiveSupport Wraps class method time_with_datetime_fallback with utc_or_local set to :utc.



94
95
96
# File 'lib/hosemonkey/ext/time.rb', line 94

def utc_time(*args)
  time_with_datetime_fallback(:utc, *args)
end