class Time
Public Class Methods
current_sg_day(time_zone)
click to toggle source
# File lib/sg_common/core_ext/time/sg_time.rb, line 43 def self.current_sg_day(time_zone) now.utc.sg_day(time_zone) end
next_sg_day(time_zone)
click to toggle source
# File lib/sg_common/core_ext/time/sg_time.rb, line 47 def self.next_sg_day(time_zone) current_sg_day(time_zone) + 1.day end
Public Instance Methods
beginning_of_sg_day(time_zone)
click to toggle source
Originally beginning_of_sg_day
was available only for Date
objects. Due to common usage of Datetime for storing dates in the database, it was required to cast Time
to Date
before using beginning_of_sg_day
. For convenience beginning_of_sg_day
was added to Time
as well.
One **important caveat** is actual time of a day is ignored by this function and this function should be called only for days at midnight.
@param time_zone a string, one of ActiveSupport::TimeZone::MAPPING @raise ArgumentError if Time
is not at midnight @return beginning of SG day in UTC
(e.g. 9/10 for US, 3/4 for italy depending on daylight saving)
# File lib/sg_common/core_ext/time/sg_time.rb, line 32 def beginning_of_sg_day(time_zone) if self.utc.seconds_since_midnight != 0 fail ArgumentError, "#beginning_of_sg_day can be used only for dates! (Time #{self} has to be at midnight)" end self.utc.to_date.beginning_of_sg_day(time_zone) end
dt()
click to toggle source
# File lib/sg_common/core_ext/time/sg_time.rb, line 8 def dt strftime('%Y%m%d') end
dth()
click to toggle source
# File lib/sg_common/core_ext/time/sg_time.rb, line 12 def dth strftime('%Y%m%d%H') end
end_of_sg_day(time_zone)
click to toggle source
# File lib/sg_common/core_ext/time/sg_time.rb, line 39 def end_of_sg_day(time_zone) self.utc.to_date.end_of_sg_day(time_zone) end
sg_day(time_zone)
click to toggle source
# File lib/sg_common/core_ext/time/sg_time.rb, line 4 def sg_day(time_zone) (self - (Date::SG_TIME_OFFSET.hours - self.in_time_zone(time_zone).utc_offset)).utc.to_date end
utc_time_offset(time_zone)
click to toggle source
# File lib/sg_common/core_ext/time/sg_time.rb, line 16 def utc_time_offset(time_zone) self.sg_day(time_zone).utc_time_offset(time_zone) end