Abbreviated string line.
DurationStringException if individually negative values were passed.
1 import std.conv : to; 2 import std.exception : assertThrown; 3 import core.time : days, hours, minutes, seconds; 4 5 { 6 enum line = "30"; 7 immutable actual = abbreviatedDuration(line); 8 immutable expected = 30.seconds; 9 assert((actual == expected), actual.to!string); 10 } 11 { 12 enum line = "30s"; 13 immutable actual = abbreviatedDuration(line); 14 immutable expected = 30.seconds; 15 assert((actual == expected), actual.to!string); 16 } 17 { 18 enum line = "1h30s"; 19 immutable actual = abbreviatedDuration(line); 20 immutable expected = 1.hours + 30.seconds; 21 assert((actual == expected), actual.to!string); 22 } 23 { 24 enum line = "5h"; 25 immutable actual = abbreviatedDuration(line); 26 immutable expected = 5.hours; 27 assert((actual == expected), actual.to!string); 28 } 29 { 30 enum line = "1d12h39m40s"; 31 immutable actual = abbreviatedDuration(line); 32 immutable expected = 1.days + 12.hours + 39.minutes + 40.seconds; 33 assert((actual == expected), actual.to!string); 34 } 35 { 36 enum line = "1d4s"; 37 immutable actual = abbreviatedDuration(line); 38 immutable expected = 1.days + 4.seconds; 39 assert((actual == expected), actual.to!string); 40 } 41 { 42 enum line = "30s"; 43 immutable actual = abbreviatedDuration(line); 44 immutable expected = 30.seconds; 45 assert((actual == expected), actual.to!string); 46 } 47 { 48 enum line = "-30s"; 49 immutable actual = abbreviatedDuration(line); 50 immutable expected = (-30).seconds; 51 assert((actual == expected), actual.to!string); 52 } 53 { 54 import core.time : Duration; 55 enum line = string.init; 56 immutable actual = abbreviatedDuration(line); 57 immutable expected = Duration.zero; 58 assert((actual == expected), actual.to!string); 59 } 60 { 61 enum line = "s"; 62 assertThrown(abbreviatedDuration(line)); 63 } 64 { 65 enum line = "1d1h1m1z"; 66 assertThrown(abbreviatedDuration(line)); 67 } 68 { 69 enum line = "2h-30m"; 70 assertThrown(abbreviatedDuration(line)); 71 }
Constructs a Duration from a string, assumed to be in a *d*h*m*s pattern.