Class: Pvectl::Presenters::TimeConfig

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/presenters/time_config.rb

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.

Examples:

Using with formatter

presenter = TimeConfig.new
formatter = Formatters::Table.new
output = formatter.format(time_configs, presenter)

See Also:

Constant Summary collapse

TIMESTAMP_FORMAT =

Date format for timestamp columns.

"%Y-%m-%d %H:%M:%S"

Instance Method Summary collapse

Methods inherited from Base

#extra_columns, #extra_values, #tags_array, #tags_display, #template_display, #to_description, #to_wide_row, #uptime_human, #wide_columns

Instance Method Details

#columnsArray<String>

Returns column headers for table output.

Returns:

  • (Array<String>)

    column headers



26
27
28
# File 'lib/pvectl/presenters/time_config.rb', line 26

def columns
  ["NODE", "TIMEZONE", "TIME (UTC)", "LOCAL TIME"]
end

#to_hash(model) ⇒ Hash{String => Object}

Converts TimeConfig model to a hash for JSON/YAML output.

Parameters:

Returns:

  • (Hash{String => Object})

    hash representation



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.

Parameters:

  • model (Models::TimeConfig)

    time configuration

  • _context (Hash)

    optional context (unused)

Returns:

  • (Array<String>)

    row values matching columns order



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 || "-",
    format_timestamp(model.time),
    format_timestamp(model.localtime)
  ]
end