Skip to content
ConsoleMonster
Class

DatePresenter

ConsoleMonster.Presenters

Namespace
ConsoleMonster.Presenters
Assembly
ConsoleMonster
Implements
ICellPresenter
Modifiers
sealed

A point in time, absolute (in the presenter's or the context's time zone), relative to now, or both. Accepts DateTime, DateTimeOffset and ISO 8601 strings. PresentedValue.Number is the number of days from now (negative in the past), so tone rules can flag, for example, certificates that expire soon. DateTime.MinValue and DateTime.MaxValue (and values within 14 hours of them) show as "never" with no number.

Inheritance

  • object
  • DatePresenter

Constructors

public DatePresenter(DateDisplay display = Absolute, string? timestampFormat = null, TimeZoneInfo? timeZone = null) #

Creates a date presenter.

Parameters

display ConsoleMonster.Presenters.DateDisplay = Absolute optional
Absolute, relative or both (default absolute).
timestampFormat string? = null optional
The absolute format (default yyyy-MM-dd HH:mm).
timeZone System.TimeZoneInfo? = null optional
The time zone for absolute dates, or null for the context's.

Methods

public static string? ExactText(object? value) #

A point in time to the tick, in the same time zone as DatePresenter.Text (for values that differ below a millisecond).

Parameters

value object? required
A DateTime or DateTimeOffset.

Returns

string? The text, or null when the value is not a point in time.
public PresentedValue Present(object? value, PresenterContext context) #

Presents a value.

Parameters

value object? required
The raw value (may be null).
context ConsoleMonster.Presenters.PresenterContext required
Culture, clock, time zone, column statistics and the render context.

Returns

PresentedValue The presented value.
public static string Relative(TimeSpan offset) #

Formats an offset from now: just now, 45 s ago, 3 h ago, in 12 d, 2 y ago.

Parameters

offset System.TimeSpan required
The value minus now.

Returns

string The text.
public static string? Text(object? value, TimeZoneInfo? timeZone = null, bool precise = false) #

A point in time as text the same way everywhere (tables, records, titles, trees, Show-Console and the change view): ISO-style yyyy-MM-dd HH:mm in the local time zone (or timeZone), whatever the culture, so dates sort and read the same on every machine; "never" for DateTime.MinValue and DateTime.MaxValue. With precise the seconds (and milliseconds when present) are added, for two values that differ below a minute.

Parameters

value object? required
A DateTime or DateTimeOffset.
timeZone System.TimeZoneInfo? = null optional
The time zone, or null for local time.
precise bool = false optional
Whether to show seconds.

Returns

string? The text, or null when the value is not a point in time.

Properties

public DateDisplay Display { get; } #

Absolute, relative or both.

public string TimestampFormat { get; } #

The absolute format.

public TimeZoneInfo? TimeZone { get; } #

The time zone override, or null.

Fields

public const string DefaultFormat #

The absolute format every command uses by default.

Value: yyyy-MM-dd HH:mm