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 = "#{hours}"\ ":"\ "#{minutes}"\ ":"\ "#{seconds}" if type == '12' time = time + "#{var}" end content_tag(:span, time.html_safe, class: 'timepiece', 'data-timezone' => location, 'data-tptype' => type) end end