module UserTimezone::DetectsTimezone::LocalInstanceMethods
Public Instance Methods
current_time()
click to toggle source
@return [Time] What time is it for this user?
# File lib/user_timezone/detects_timezone.rb, line 52 def current_time Time.now.utc.getlocal(utc_offset) unless utc_offset.nil? end
detect_timezone()
click to toggle source
@return [String] Uses the configured address fields to return a timezone value such as “America/Chicago”
# File lib/user_timezone/detects_timezone.rb, line 27 def detect_timezone self.class.timezone_detector.detect(self) end
detect_timezone!()
click to toggle source
Detects the timezone using the self.#detect_timezone then sets the value into the local timezone field (as configured) @see detect_timezone
# File lib/user_timezone/detects_timezone.rb, line 36 def detect_timezone! self.send(self.class.timezone_detector.options.as, self.detect_timezone) end
utc_offset()
click to toggle source
@return [String] Gets he GMT offset that ruby likes (such as -05:00) in +/-HH:MM form
# File lib/user_timezone/detects_timezone.rb, line 42 def utc_offset offset = self.class.timezone_detector.detect(self, 'utc_offset') return nil if offset.nil? offset_val = offset.to_i (offset_val < 0 ? '-' : '+') + Time.at(offset_val.abs.to_i).utc.strftime("%H:%M") end
Also aliased as: gmt_offset