module TimepieceHelper def timepiece(location = 'UTC', type: '24', lead: 'none', abbr_sep: 'none', id: '') # Note: On the inclusion of IDs, you should /not/ display them if none is given - HTML compliance. 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 = hours.to_i if hours > 12 hours = hours - 12 var = 'pm' elsif hours == 0 hours = 12 var = 'am' elsif hours == 12 var = 'pm' elsif hours < 12 var = 'am' end if hours < 10 if lead == '0' || lead == 'zero' hours = '0' + hours.to_s elsif lead == '_' || lead == 'space' hours = ' ' + hours.to_s end end if abbr_sep == '.' var = var.gsub(/([apm])/, '\1.') end 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, 'data-lead' => lead, 'data-abbr_separator' => abbr_sep, 'id' => (id unless id.blank?)) end def analog(location = 'UTC', id: '', size: '10em') 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 hours.to_i >= 6 && hours.to_i < 18 time_of_day_class = 'timepiece-analog-day' else time_of_day_class = 'timepiece-analog-night' end if hours.to_i >= 12 var = 'pm' elsif hours.to_i < 12 var = 'am' end hours_angle = (hours.to_i * 30) + (minutes.to_i / 2) minutes_angle = minutes.to_i * 6 seconds_angle = seconds.to_i * 6 time = "