Module: Clowk::Phlex::Charts::WebTime

Defined in:
lib/clowk/phlex/charts/web_time.rb

Overview

WebTime — the single "render this moment in the app's timezone" seam for the chart x-axis + tooltips. Uses ActiveSupport's Time.zone when present (Rails hosts), else falls back to UTC — so the lib works with or without Rails, and a host can retune the zone in one place later.

Constant Summary collapse

DEFAULT_ZONE_NAME =
"UTC"

Class Method Summary collapse

Class Method Details

.strftime(time, pattern) ⇒ Object

strftime — format a moment (Time / TimeWithZone). Never raises: returns nil on bad input so views render "—" instead of 500-ing.



23
24
25
26
27
# File 'lib/clowk/phlex/charts/web_time.rb', line 23

def strftime(time, pattern)
  time&.strftime(pattern)
rescue
  nil
end

.zone_nameObject



15
16
17
18
19
# File 'lib/clowk/phlex/charts/web_time.rb', line 15

def zone_name
  (defined?(Time.zone) && Time.zone&.name) || DEFAULT_ZONE_NAME
rescue
  DEFAULT_ZONE_NAME
end