Class: Pvectl::Presenters::TimeConfig
- Defined in:
- lib/pvectl/presenters/time_config.rb,
sig/pvectl/presenters/time_config.rbs
Overview
Presenter for node time and timezone settings.
Renders both the UTC timestamp and the node's local wall clock as
human-readable strings. Proxmox returns localtime as seconds-since-epoch
interpreted as if the node's wall clock were UTC, so we format it via
Time.at(localtime).utc.strftime(...) to preserve the node's view.
Constant Summary collapse
- TIMESTAMP_FORMAT =
Date format for timestamp columns.
"%Y-%m-%d %H:%M:%S"
Instance Method Summary collapse
-
#columns ⇒ Array<String>
Returns column headers for table output.
-
#format_timestamp(epoch) ⇒ String
Formats epoch seconds as a UTC-displayed string.
-
#iso(epoch) ⇒ String?
ISO 8601 representation for JSON/YAML output.
-
#to_hash(model) ⇒ Hash{String => Object}
Converts TimeConfig model to a hash for JSON/YAML output.
-
#to_row(model, **_context) ⇒ Array<String>
Converts TimeConfig model to a table row.
Methods inherited from Base
#extra_columns, #extra_values, #format_bytes, #format_firewall, #format_firewall_rules, #format_task_history, #resource, #tags_array, #tags_display, #template_display, #to_description, #to_wide_row, #uptime_human, #wide_columns
Instance Method Details
#columns ⇒ Array<String>
Returns column headers for table output.
26 27 28 |
# File 'lib/pvectl/presenters/time_config.rb', line 26 def columns ["NODE", "TIMEZONE", "TIME (UTC)", "LOCAL TIME"] end |
#format_timestamp(epoch) ⇒ String
Formats epoch seconds as a UTC-displayed string.
Used for both the UTC time field and localtime (Proxmox encodes
the local wall clock as seconds-since-epoch interpreted as UTC, so the
same formatting produces the correct display in both cases).
69 70 71 72 73 |
# File 'lib/pvectl/presenters/time_config.rb', line 69 def (epoch) return "-" if epoch.nil? Time.at(epoch).utc.strftime(TIMESTAMP_FORMAT) end |
#iso(epoch) ⇒ String?
ISO 8601 representation for JSON/YAML output.
79 80 81 82 83 |
# File 'lib/pvectl/presenters/time_config.rb', line 79 def iso(epoch) return nil if epoch.nil? Time.at(epoch).utc.strftime("%Y-%m-%dT%H:%M:%SZ") end |
#to_hash(model) ⇒ Hash{String => Object}
Converts TimeConfig model to a hash for JSON/YAML output.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pvectl/presenters/time_config.rb', line 48 def to_hash(model) { "node" => model.node_name, "timezone" => model.timezone, "time" => model.time, "localtime" => model.localtime, "time_iso" => iso(model.time), "localtime_iso" => iso(model.localtime) } end |
#to_row(model, **_context) ⇒ Array<String>
Converts TimeConfig model to a table row.
35 36 37 38 39 40 41 42 |
# File 'lib/pvectl/presenters/time_config.rb', line 35 def to_row(model, **_context) [ model.node_name || "-", model.timezone || "-", (model.time), (model.localtime) ] end |