1 #include <msp/strings/format.h>
9 using Msp::Time::RawTime;
11 string format_part(RawTime &value, RawTime unit, char sep, bool &first)
13 if(value<unit && first)
16 RawTime v = value/unit;
21 return Msp::format("%d", v);
24 return Msp::format("%c%02d", sep, v);
32 void operator<<(LexicalConverter &conv, const TimeDelta &td)
36 RawTime value = td.raw();
47 result += format("%dµs", value);
48 else if(value<1000000)
50 result += format("%d", value/1000);
53 result += format(".%03d", value);
59 bool unit = value<60000000LL;
60 result += format_part(value, 86400000000LL, 0, first);
61 result += format_part(value, 3600000000LL, '-', first);
62 result += format_part(value, 60000000LL, ':', first);
63 result += format_part(value, 1000000LL, ':', first);
68 result += format(".%06d", value);
70 result += format(".%03d", value/1000);
79 const TimeDelta zero(0);
80 const TimeDelta usec(1);
81 const TimeDelta msec(1000);
82 const TimeDelta sec(1000000);
83 const TimeDelta min(60*1000000);
84 const TimeDelta hour(3600*1000000LL);
85 const TimeDelta day(86400*1000000LL);
86 const TimeDelta week(7*86400*1000000LL);