The SysTime to base the string on.
The Precision to use (how many units to express the time in).
A string representing the time in the passed precision. If a precision of none is passed, the string will be empty.
import std.datetime : DateTime; import std.datetime.timezone : UTC; alias Precision = QuoteSettings.Precision; const dateTime = DateTime(2023, 11, 12, 13, 14, 15); const when = SysTime(dateTime, UTC()); { immutable actual = getTimeStringFromTimestamp(when, Precision.year); immutable expected = "2023"; assert((actual == expected), actual); } version(none) { // We have to disable this test as the month string is locale-dependent immutable actual = getTimeStringFromTimestamp(when, Precision.month); immutable expected = "Nov 2023"; assert((actual == expected), actual); } { immutable actual = getTimeStringFromTimestamp(when, Precision.day); immutable expected = "2023-11-12"; assert((actual == expected), actual); } { immutable actual = getTimeStringFromTimestamp(when, Precision.minute); immutable expected = "2023-11-12 13:14"; assert((actual == expected), actual); } { immutable actual = getTimeStringFromTimestamp(when, Precision.second); immutable expected = "2023-11-12 13:14:15"; assert((actual == expected), actual); } { immutable actual = getTimeStringFromTimestamp(when, Precision.none); assert(!actual.length, actual); }
Produces a time string from a UNIX timestamp with the provided time precision.