Module: Karafka::Web::Ui::Helpers::TimeHelper
- Included in:
- Base
- Defined in:
- lib/karafka/web/ui/helpers/time_helper.rb
Overview
Helper with time-related methods
Instance Method Summary collapse
-
#human_readable_time(seconds) ⇒ String
Converts raw second count into human readable form like “12.2 minutes”.
-
#poll_state_with_change_time_label(state, state_ch) ⇒ String
Span tag with label and title with change time if present.
-
#relative_time(time) ⇒ String
Relative time tag for timeago.js.
-
#time_with_label(time) ⇒ String
Span tag with raw timestamp as a title and time as a value.
Instance Method Details
#human_readable_time(seconds) ⇒ String
Converts raw second count into human readable form like “12.2 minutes”. etc based on number of seconds
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/karafka/web/ui/helpers/time_helper.rb', line 29 def human_readable_time(seconds) case seconds when 0..59 "#{seconds.round(2)} seconds" when 60..3_599 minutes = seconds / 60.0 "#{minutes.round(2)} minutes" when 3_600..86_399 hours = seconds / 3_600.0 "#{hours.round(2)} hours" else days = seconds / 86_400.0 "#{days.round(2)} days" end end |
#poll_state_with_change_time_label(state, state_ch) ⇒ String
Returns span tag with label and title with change time if present.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/karafka/web/ui/helpers/time_helper.rb', line 49 def poll_state_with_change_time_label(state, state_ch) year_in_seconds = 131_556_926 state_ch_in_seconds = state_ch / 1_000.0 # If state is active, there is no date of change if state == 'active' %( <span class="badge #{kafka_state_badge(state)}">#{state}</span> ) elsif state_ch_in_seconds > year_in_seconds %( <span class="badge #{kafka_state_badge(state)}" title="until manual resume" > #{state} </span> ) else %( <span class="badge #{kafka_state_badge(state)} time-title" title="#{Time.now + state_ch_in_seconds}" > #{state} </span> ) end end |
#relative_time(time) ⇒ String
Returns relative time tag for timeago.js.
11 12 13 14 |
# File 'lib/karafka/web/ui/helpers/time_helper.rb', line 11 def relative_time(time) stamp = Time.at(time).getutc.iso8601(3) %(<time class="ltr" dir="ltr" title="#{stamp}" datetime="#{stamp}">#{time}</time>) end |
#time_with_label(time) ⇒ String
Returns span tag with raw timestamp as a title and time as a value.
18 19 20 21 22 |
# File 'lib/karafka/web/ui/helpers/time_helper.rb', line 18 def time_with_label(time) stamp = (time.to_f * 1000).to_i %(<span title="#{stamp}">#{time}</span>) end |