DatePresenter
ConsoleMonster.Presenters
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
- Absolute, relative or both (default absolute).
- timestampFormat string? = null
- The absolute format (default yyyy-MM-dd HH:mm).
- timeZone System.TimeZoneInfo? = null
- 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?
- 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?
- The raw value (may be null).
- context ConsoleMonster.Presenters.PresenterContext
- Culture, clock, time zone, column statistics and the render context.
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
- 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?
- A DateTime or DateTimeOffset.
- timeZone System.TimeZoneInfo? = null
- The time zone, or null for local time.
- precise bool = false
- Whether to show seconds.
Returns
string? The text, or null when the value is not a point in time.Inherited Methods
Properties
Fields
public const string DefaultFormat #The absolute format every command uses by default.
yyyy-MM-dd HH:mm