Duration.toString

Converts this Duration to a string.

The string is meant to be human readable, not machine parseable (e.g. whether there is an 's' on the end of the unit name usually depends on whether it's plural or not, and empty units are not included unless the Duration is zero). Any code needing a specific string format should use total or split to get the units needed to create the desired string format and create the string itself.

The format returned by toString may or may not change in the future.

struct Duration
@safe pure
string
toString
const nothrow pure @safe
()

Examples

1 assert(Duration.zero.toString() == "0 hnsecs");
2 assert(weeks(5).toString() == "5 weeks");
3 assert(days(2).toString() == "2 days");
4 assert(hours(1).toString() == "1 hour");
5 assert(minutes(19).toString() == "19 minutes");
6 assert(seconds(42).toString() == "42 secs");
7 assert(msecs(42).toString() == "42 ms");
8 assert(usecs(27).toString() == "27 μs");
9 assert(hnsecs(5).toString() == "5 hnsecs");
10 
11 assert(seconds(121).toString() == "2 minutes and 1 sec");
12 assert((minutes(5) + seconds(3) + usecs(4)).toString() ==
13        "5 minutes, 3 secs, and 4 μs");
14 
15 assert(seconds(-42).toString() == "-42 secs");
16 assert(usecs(-5239492).toString() == "-5 secs, -239 ms, and -492 μs");
Suggestion Box / Bug Report