Duration.toString

Returns the total number of the given units in this Duration. So, unlike split, it does not strip out the larger units.

  1. void toString(SinkT sink)
  2. string toString()
    struct Duration
    @safe pure const scope nothrow
    string
    toString
    ()

Examples

assert(Duration.zero.toString() == "0 hnsecs");
assert(weeks(5).toString() == "5 weeks");
assert(days(2).toString() == "2 days");
assert(hours(1).toString() == "1 hour");
assert(minutes(19).toString() == "19 minutes");
assert(seconds(42).toString() == "42 secs");
assert(msecs(42).toString() == "42 ms");
assert(usecs(27).toString() == "27 μs");
assert(hnsecs(5).toString() == "5 hnsecs");

assert(seconds(121).toString() == "2 minutes and 1 sec");
assert((minutes(5) + seconds(3) + usecs(4)).toString() ==
       "5 minutes, 3 secs, and 4 μs");

assert(seconds(-42).toString() == "-42 secs");
assert(usecs(-5239492).toString() == "-5 secs, -239 ms, and -492 μs");
assert(dur!"weeks"(12).total!"weeks" == 12);
assert(dur!"weeks"(12).total!"days" == 84);

assert(dur!"days"(13).total!"weeks" == 1);
assert(dur!"days"(13).total!"days" == 13);

assert(dur!"hours"(49).total!"days" == 2);
assert(dur!"hours"(49).total!"hours" == 49);

assert(dur!"nsecs"(2007).total!"hnsecs" == 20);
assert(dur!"nsecs"(2007).total!"nsecs" == 2000);

Meta