The OpenD Programming Language

Timestamp.opCast

Decomposes Timestamp to an algebraic type. Supported types up to T.stringof equivalence:

  • Year
  • YearMonth
  • YearMonthDay
  • Date
  • date
  • TimeOfDay
  • DateTime
  • SysTime
  • Timestamp as fallback type
  1. T opCast()
    struct Timestamp
    const
    T
    opCast
    (
    T
    )
    ()
    if (
    __traits(hasMember, T, "AllowedTypes")
    )
  2. T opCast()

Throws

an exception if timestamp cannot be converted to an algebraic type and there is no Timestamp type in the Algebraic set.

Examples

import core.time : hnsecs, minutes, Duration;
import mir.algebraic;
import mir.date: Date; // Can be other Date type as well
import std.datetime.date : TimeOfDay, DateTime;
import std.datetime.systime : SysTime;
import std.datetime.timezone: UTC, SimpleTimeZone;

alias A = Variant!(Date, TimeOfDay, DateTime, Duration, SysTime, Timestamp, string); // non-date-time types is OK
assert(cast(A) Timestamp(1023) == Timestamp(1023)); // Year isn't represented in the algebraic, use fallback type
assert(cast(A) Timestamp.onlyTime(7, 40, 30) == TimeOfDay(7, 40, 30));
assert(cast(A) Timestamp(1982, 4, 1, 20, 59, 22) == DateTime(1982, 4, 1, 20, 59, 22));

auto dt = DateTime(1982, 4, 1, 20, 59, 22);
auto tz = new immutable SimpleTimeZone(-330.minutes);
auto st = SysTime(dt, 1234567.hnsecs, tz);
assert(cast(A) Timestamp(st) == st);

Meta