1 #include <msp/strings/format.h>
8 using Msp::Time::RawTime;
10 string format_part(RawTime &value, RawTime unit, char sep, bool &first)
12 if(value<unit && first)
15 RawTime v = value/unit;
20 return Msp::format("%d", v);
23 return Msp::format("%c%02d", sep, v);
31 void operator<<(LexicalConverter &conv, const TimeDelta &td)
35 RawTime value = td.raw();
46 result += format("%dµs", value);
47 else if(value<1000000)
49 result += format("%d", value/1000);
52 result += format(".%03d", value);
58 bool unit = value<60000000LL;
59 result += format_part(value, 86400000000LL, 0, first);
60 result += format_part(value, 3600000000LL, '-', first);
61 result += format_part(value, 60000000LL, ':', first);
62 result += format_part(value, 1000000LL, ':', first);
67 result += format(".%06d", value);
69 result += format(".%03d", value/1000);
78 const TimeDelta zero(0);
79 const TimeDelta usec(1);
80 const TimeDelta msec(1000);
81 const TimeDelta sec(1000000);
82 const TimeDelta min(60*1000000);
83 const TimeDelta hour(3600*1000000LL);
84 const TimeDelta day(86400*1000000LL);
85 const TimeDelta week(7*86400*1000000LL);