Module: LocalTimeHelper
- Defined in:
- app/helpers/local_time_helper.rb
Instance Method Summary collapse
- #local_date(time, options = nil) ⇒ Object
- #local_relative_time(time, options = nil) ⇒ Object
- #local_time(time, options = nil) ⇒ Object
- #local_time_ago(time, options = nil) ⇒ Object
- #utc_time(time_or_date) ⇒ Object
Instance Method Details
#local_date(time, options = nil) ⇒ Object
14 15 16 17 18 |
# File 'app/helpers/local_time_helper.rb', line 14 def local_date(time, = nil) , format = (, :format) format, _ = find_12h_and_24h_formats(format, prefer: :date) local_time time, .merge(format: format) end |
#local_relative_time(time, options = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/local_time_helper.rb', line 20 def local_relative_time(time, = nil) time = utc_time(time) , type = (, :type) [:data] ||= {} [:data].merge! local: type time_tag time, time.strftime(LocalTime.default_time_format), end |
#local_time(time, options = nil) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'app/helpers/local_time_helper.rb', line 2 def local_time(time, = nil) time = utc_time(time) , format12 = (, :format) format12, format24 = find_12h_and_24h_formats(format12) [:data] ||= {} [:data].merge! local: :time, format: format12, format24: format24 time_tag time, time.strftime(format12), end |
#local_time_ago(time, options = nil) ⇒ Object
30 31 32 33 34 |
# File 'app/helpers/local_time_helper.rb', line 30 def local_time_ago(time, = nil) , * = (, :type) [:type] = "time-ago" local_relative_time time, end |
#utc_time(time_or_date) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/helpers/local_time_helper.rb', line 36 def utc_time(time_or_date) if time_or_date.respond_to?(:in_time_zone) time_or_date.in_time_zone.utc else time_or_date.to_time.utc end end |