Module: RailsPulse::FormattingHelper

Included in:
ApplicationHelper, Dashboard::Tables::SlowQueries, Dashboard::Tables::SlowRoutes
Defined in:
app/helpers/rails_pulse/formatting_helper.rb

Instance Method Summary collapse

Instance Method Details

#human_readable_occurred_at(occurred_at) ⇒ Object



3
4
5
6
7
8
# File 'app/helpers/rails_pulse/formatting_helper.rb', line 3

def human_readable_occurred_at(occurred_at)
  return "" unless occurred_at.present?
  time = occurred_at.is_a?(String) ? Time.parse(occurred_at) : occurred_at
  # Convert to local system timezone (same as charts use)
  time.getlocal.strftime("%b %d, %Y %l:%M %p")
end

#human_readable_summary_period(summary) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/rails_pulse/formatting_helper.rb', line 32

def human_readable_summary_period(summary)
  return "" unless summary&.period_start&.present? && summary&.period_end&.present?

  # Convert UTC times to local system timezone to match chart display
  start_time = summary.period_start.getlocal
  end_time = summary.period_end.getlocal


  case summary.period_type
  when "hour"
    start_time.strftime("%b %e %Y, %l:%M %p") + " - " + end_time.strftime("%l:%M %p")
  when "day"
    start_time.strftime("%b %e, %Y")
  end
end

#time_ago_in_words(time) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/rails_pulse/formatting_helper.rb', line 10

def time_ago_in_words(time)
  return "Unknown" if time.blank?

  # Convert to Time object if it's a string
  time = Time.parse(time.to_s) if time.is_a?(String)
  # Convert to local system timezone for consistent calculation
  time = time.getlocal

  seconds_ago = Time.now - time

  case seconds_ago
  when 0..59
    "#{seconds_ago.to_i}s ago"
  when 60..3599
    "#{(seconds_ago / 60).to_i}m ago"
  when 3600..86399
    "#{(seconds_ago / 3600).to_i}h ago"
  else
    "#{(seconds_ago / 86400).to_i}d ago"
  end
end