Timestamp.toString

Converts this Timestamp to a string with the format YYYY-MM-DDThh:mm:ss±hh:mm.

If w writer is set, the resulting string will be written directly to it.

  1. alias toString = toISOExtString
    struct Timestamp
    @serdeIgnore
    alias toString = toISOExtString
  2. alias toISOExtString = toISOStringImp!true

Return Value

A string when not using an output range; void otherwise.

Examples

assert(Timestamp.init.toString == "0000T");
assert(Timestamp(2010, 7, 4).toString == "2010-07-04");
assert(Timestamp(1998, 12, 25).toString == "1998-12-25");
assert(Timestamp(0, 1, 5).toString == "0000-01-05");
assert(Timestamp(-4, 1, 5).toString == "-0004-01-05");

// YYYY-MM-DDThh:mm:ss±hh:mm
assert(Timestamp(2021).toString == "2021T");
assert(Timestamp(2021, 01).toString == "2021-01T", Timestamp(2021, 01).toString);
assert(Timestamp(2021, 01, 29).toString == "2021-01-29");
assert(Timestamp(2021, 01, 29, 19, 42).toString == "2021-01-29T19:42Z");
assert(Timestamp(2021, 01, 29, 12, 42, 44).withOffset(7 * 60).toString == "2021-01-29T19:42:44+07", Timestamp(2021, 01, 29, 12, 42, 44).withOffset(7 * 60).toString);
assert(Timestamp(2021, 01, 29, 12, 42, 44).withOffset(7 * 60 + 30).toString == "2021-01-29T20:12:44+07:30");

assert(Timestamp.onlyTime(7, 40).toString == "07:40Z");
assert(Timestamp.onlyTime(7, 40, 30).toString == "07:40:30Z");
assert(Timestamp.onlyTime(7, 40, 30, -3, 56).toString == "07:40:30.056Z");
// Test A.D.
assert(Timestamp(9, 12, 4).toISOExtString == "0009-12-04");
assert(Timestamp(99, 12, 4).toISOExtString == "0099-12-04");
assert(Timestamp(999, 12, 4).toISOExtString == "0999-12-04");
assert(Timestamp(9999, 7, 4).toISOExtString == "9999-07-04");
assert(Timestamp(10000, 10, 20).toISOExtString == "+10000-10-20");

// Test B.C.
assert(Timestamp(0, 12, 4).toISOExtString == "0000-12-04");
assert(Timestamp(-9, 12, 4).toISOExtString == "-0009-12-04");
assert(Timestamp(-99, 12, 4).toISOExtString == "-0099-12-04");
assert(Timestamp(-999, 12, 4).toISOExtString == "-0999-12-04");
assert(Timestamp(-9999, 7, 4).toISOExtString == "-9999-07-04");
assert(Timestamp(-10000, 10, 20).toISOExtString == "-10000-10-20");

assert(Timestamp.onlyTime(7, 40).toISOExtString == "07:40Z");
assert(Timestamp.onlyTime(7, 40, 30).toISOExtString == "07:40:30Z");
assert(Timestamp.onlyTime(7, 40, 30, -3, 56).toISOExtString == "07:40:30.056Z");

const cdate = Timestamp(1999, 7, 6);
immutable idate = Timestamp(1999, 7, 6);
assert(cdate.toISOExtString == "1999-07-06");
assert(idate.toISOExtString == "1999-07-06");

Meta