Duration.total

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

struct Duration
@safe pure @property const nothrow @nogc
long
total
(
string units
)
()
if (
units == "weeks" ||
units == "days"
||
units == "hours"
||
units == "minutes"
||
units == "seconds"
||
units == "msecs"
||
units == "usecs"
||
units == "hnsecs"
||
units == "nsecs"
)

Examples

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);
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");

Meta