3 This file is part of libmspcore
4 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/strings/format.h>
16 using Msp::Time::RawTime;
18 string format_part(RawTime &value, RawTime unit, char sep, bool &first)
20 if(value<unit && first)
23 RawTime v = value/unit;
28 return Msp::format("%d", v);
31 return Msp::format("%c%02d", sep, v);
39 void operator<<(LexicalConverter &conv, const TimeDelta &td)
43 RawTime value = td.raw();
54 result += format("%dµs", value);
55 else if(value<1000000)
57 result += format("%d", value/1000);
60 result += format(".%03d", value);
66 bool unit = value<60000000LL;
67 result += format_part(value, 86400000000LL, 0, first);
68 result += format_part(value, 3600000000LL, '-', first);
69 result += format_part(value, 60000000LL, ':', first);
70 result += format_part(value, 1000000LL, ':', first);
75 result += format(".%06d", value);
77 result += format(".%03d", value/1000);