Sha256: 033ec3607a415676cf3ea4e1fd3e232fe4a185b113cae53b7f4247a0cc8c0b4c
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
module TimepieceHelper def timepiece(location = 'UTC', type = '24') Time.zone = location hours = Time.now.in_time_zone.strftime('%H') minutes = Time.now.in_time_zone.strftime('%M') seconds = Time.now.in_time_zone.strftime('%S') if type == '12' && hours.to_i > 12 hours = hours.to_i - 12 if hours < 10 hours = '0' + hours.to_s end var = 'pm' elsif type == '12' && hours.to_i == 0 hours = 12 var = 'am' elsif type == '12' && hours.to_i == 12 var = 'pm' elsif type == '12' && hours.to_i < 12 var = 'am' end time = "<span class='timepiece-hours'>#{hours}</span>"\ "<span class='timepiece-separator tp-separator-1'>:</span>"\ "<span class='timepiece-minutes'>#{minutes}</span>"\ "<span class='timepiece-separator tp-separator-2'>:</span>"\ "<span class='timepiece-seconds'>#{seconds}</span>" if type == '12' time = time + "<span class='timepiece-abbr timepiece-abbr-#{var}'>#{var}</span>" end content_tag(:span, time.html_safe, class: 'timepiece', 'data-timezone' => location, 'data-tptype' => type) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
timepiece-0.1.2 | app/helpers/timepiece_helper.rb |