Class WorldClockText
The written forms of world time, shared by every surface that reads or writes the world
clock (the Control Panel, and available to the in-game /admin time commands) so the
two can never disagree about what a typed value means.
public static class WorldClockText
- Inheritance
-
WorldClockText
- Inherited Members
Remarks
A WORLD TIMESTAMP is the calendar epoch (Unix seconds) plus the world milliseconds, written
yyyy-MM-dd HH:mm:ss.fff in the invariant culture with no zone: it is UTC-style
arithmetic on a calendar, not anybody's local time.
A CHANGE is a signed span: +1h30m, -90s, +2d3h4m5.25s, +250ms.
Units d, h, m, s, ms, each at most once, largest first; a bare signed number is seconds.
The sign is required, which is what tells a change from a timestamp.
Fields
Format
The one output format.
public const string Format = "yyyy-MM-dd HH:mm:ss.fff"
Field Value
MaxCalendarUnixMs
The latest instant a timestamp can name: 9999-12-31 23:59:59.999, Unix ms.
public const long MaxCalendarUnixMs = 253402300799999
Field Value
MaxEpochUnixSeconds
The latest epoch representable: 9999-12-31 23:59:59, Unix seconds.
public const long MaxEpochUnixSeconds = 253402300799
Field Value
MinEpochUnixSeconds
The earliest epoch representable: 0001-01-01, Unix seconds.
public const long MinEpochUnixSeconds = -62135596800
Field Value
Methods
FormatChange(long)
Writes a span of milliseconds in the change syntax, largest unit first: +1h30m,
-1d, +0s.
public static string FormatChange(long deltaMs)
Parameters
deltaMslong
Returns
FormatTimestamp(long, long)
Formats world milliseconds as a world timestamp, or returns null when the instant falls outside the years 1–9999 (an epoch or a world time that no calendar date can name).
public static string? FormatTimestamp(long epochUnixSeconds, long worldMs)
Parameters
Returns
IsValidEpoch(long)
Whether an epoch can be written as a calendar date at all.
public static bool IsValidEpoch(long epochUnixSeconds)
Parameters
epochUnixSecondslong
Returns
TryParseChange(string?, out long, out string?)
Parses a signed change such as +1h30m, -90s or +2d3h4m5.25s into
milliseconds, rounded to the nearest millisecond.
public static bool TryParseChange(string? text, out long deltaMs, out string? error)
Parameters
textstringThe change. The sign is required.
deltaMslongThe signed change in milliseconds.
errorstringWhy it was refused, written for the person who typed it.
Returns
TryParseTimestamp(string?, long, out long, out string?)
Parses a world timestamp into world milliseconds since the epoch. Refuses an instant before the epoch (world time cannot be negative) and anything unparseable.
public static bool TryParseTimestamp(string? text, long epochUnixSeconds, out long worldMs, out string? error)
Parameters
textstringThe timestamp, in one of the accepted formats.
epochUnixSecondslongThe calendar epoch, from the world clock row.
worldMslongWorld milliseconds since the epoch.
errorstringWhy it was refused, written for the person who typed it.
Returns
TryToInstant(long, long, out DateTimeOffset)
The instant a world time names, when one exists in years 1–9999.
public static bool TryToInstant(long epochUnixSeconds, long worldMs, out DateTimeOffset instant)
Parameters
epochUnixSecondslongworldMslonginstantDateTimeOffset