Module: UserTimezone::DetectsTimezone::LocalInstanceMethods
- Defined in:
- lib/user_timezone/detects_timezone.rb
Instance Method Summary collapse
-
#current_time ⇒ Time
What time is it for this user?.
-
#detect_timezone ⇒ String
Uses the configured address fields to return a timezone value such as “America/Chicago”.
-
#detect_timezone! ⇒ Object
Detects the timezone using the self.#detect_timezone then sets the value into the local timezone field (as configured).
-
#utc_offset ⇒ String
(also: #gmt_offset)
Gets he GMT offset that ruby likes (such as -05:00) in +/-HH:MM form.
Instance Method Details
#current_time ⇒ Time
Returns What time is it for this user?.
52 53 54 |
# 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 ⇒ String
Returns Uses the configured address fields to return a timezone value such as “America/Chicago”.
27 28 29 |
# File 'lib/user_timezone/detects_timezone.rb', line 27 def detect_timezone self.class.timezone_detector.detect(self) end |
#detect_timezone! ⇒ Object
Detects the timezone using the self.#detect_timezone then sets the value into the local timezone field (as configured)
36 37 38 |
# File 'lib/user_timezone/detects_timezone.rb', line 36 def detect_timezone! self.send(self.class.timezone_detector..as, self.detect_timezone) end |
#utc_offset ⇒ String Also known as: gmt_offset
Returns Gets he GMT offset that ruby likes (such as -05:00) in +/-HH:MM form.
42 43 44 45 46 47 |
# 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 |