Module: LocalTimeHelper
- Defined in:
- app/helpers/local_time_helper.rb
Constant Summary collapse
- DEFAULT_FORMAT =
'%B %e, %Y %l:%M%P'
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
16 17 18 19 20 |
# File 'app/helpers/local_time_helper.rb', line 16 def local_date(time, = nil) , format = (, :format) [:format] = format || '%B %e, %Y' local_time time, end |
#local_relative_time(time, options = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/local_time_helper.rb', line 22 def local_relative_time(time, = nil) time = utc_time(time) , type = (, :type) [:data] ||= {} [:data].merge! local: type time_tag time, time.strftime(DEFAULT_FORMAT), end |
#local_time(time, options = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/local_time_helper.rb', line 4 def local_time(time, = nil) time = utc_time(time) , format = (, :format) format = find_time_format(format) [:data] ||= {} [:data].merge! local: :time, format: format time_tag time, time.strftime(format), end |
#local_time_ago(time, options = nil) ⇒ Object
32 33 34 35 36 |
# File 'app/helpers/local_time_helper.rb', line 32 def local_time_ago(time, = nil) , type = (, :type) [:type] = 'time-ago' local_relative_time time, end |
#utc_time(time_or_date) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/helpers/local_time_helper.rb', line 38 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 |