42 #define ONE_BILLION 1000000000 74 return RealTime(tv.tv_sec, tv.tv_usec * 1000);
82 int year = 0, month = 0, day = 0, hour = 0, minute = 0;
87 const char *s = xsdd.c_str();
88 int len = xsdd.length();
90 bool negative =
false, afterT =
false;
95 if (i == 0) negative =
true;
103 if (isdigit(s[i]) || s[i] ==
'.') {
104 value = strtod(&s[i], &eptr);
111 case 'Y': year = int(value + 0.1);
break;
112 case 'D': day = int(value + 0.1);
break;
113 case 'H': hour = int(value + 0.1);
break;
115 if (afterT) minute = int(value + 0.1);
116 else month = int(value + 0.1);
121 case 'T': afterT =
true;
break;
128 cerr <<
"WARNING: This xsd:duration (\"" << xsdd <<
"\") contains a non-zero year.\nWith no origin and a limited data size, I will treat a year as exactly 31556952\nseconds and you should expect overflow and/or poor results." << endl;
129 t = t +
RealTime(year * 31556952, 0);
133 cerr <<
"WARNING: This xsd:duration (\"" << xsdd <<
"\") contains a non-zero month.\nWith no origin and a limited data size, I will treat a month as exactly 2629746\nseconds and you should expect overflow and/or poor results." << endl;
134 t = t +
RealTime(month * 2629746, 0);
180 if (nn == 0) out <<
"00000000";
193 std::stringstream out;
196 std::string s = out.str();
200 s = s.substr(1, s.length() - 1);
204 return s.substr(0, s.length() - 1);
210 bool negative =
false;
212 std::string ssec, snsec;
214 for (
size_t i = 0; i < s.length(); ++i) {
217 if (isspace(c))
continue;
221 if (c ==
'-') negative =
true;
222 else if (isdigit(c)) { section = 1; ssec += c; }
223 else if (c ==
'.') section = 2;
226 }
else if (section == 1) {
228 if (c ==
'.') section = 2;
229 else if (isdigit(c)) ssec += c;
232 }
else if (section == 2) {
234 if (isdigit(c)) snsec += c;
239 while (snsec.length() < 8) snsec +=
'0';
241 int sec = atoi(ssec.c_str());
242 int nsec = atoi(snsec.c_str());
271 std::stringstream out;
274 out << (
sec / 3600) <<
":";
278 out << (
sec % 3600) / 60 <<
":";
282 out << ((
sec % 60) / 10);
296 }
else if (fixedDp) {
301 }
else if (fixedDp) {
304 }
else if (fixedDp) {
308 std::string s = out.str();
318 std::stringstream out;
321 out << (
sec / 3600) <<
":";
325 out << (
sec % 3600) / 60 <<
":";
329 out << ((
sec % 60) / 10);
338 while ((n = n / 10)) {
347 int d = (f / div) % 10;
352 std::string s = out.str();
364 std::stringstream out;
367 out << (
sec / 3600) <<
":";
371 out << (
sec % 3600) / 60 <<
":";
375 out << ((
sec % 60) / 10);
384 std::string s = out.str();
392 std::string s =
"PT" +
toString(
false) +
"S";
407 int secdiv =
sec / d;
408 int secrem =
sec % d;
412 return RealTime(secdiv,
int(nsecdiv + 0.5));
437 if (rTotal == 0)
return 0.0;
438 else return lTotal/rTotal;
445 double s = time.
sec + double(time.
nsec + 1) / 1000000000.0;
446 return long(s *
double(sampleRate));
455 rt.
sec = frame / long(sampleRate);
456 frame -= rt.
sec * long(sampleRate);
457 rt.
nsec = (int)(((
double(frame) * 1000000.0) /
long(sampleRate)) * 1000.0);
static RealTime fromTimeval(const struct timeval &)
static RealTime fromString(std::string)
Convert a string as obtained from toString back to a RealTime object.
static RealTime frame2RealTime(long frame, unsigned int sampleRate)
Convert a sample frame at the given sample rate into a RealTime.
std::string toText(bool fixedDp=false) const
Return a user-readable string to the nearest millisecond, in a form like HH:MM:SS....
TimeToTextMode getTimeToTextMode() const
std::ostream & operator<<(std::ostream &out, const RealTime &rt)
std::string toXsdDuration() const
Return a string in xsd:duration format.
static RealTime fromSeconds(double sec)
static Preferences * getInstance()
RealTime operator/(int d) const
std::string toSecText() const
Return a user-readable string to the nearest second, in a form like "6s" (for less than a minute) or ...
static RealTime fromMilliseconds(int msec)
static long realTime2Frame(const RealTime &r, unsigned int sampleRate)
Convert a RealTime into a sample frame at the given sample rate.
static const RealTime zeroTime
std::string toString(bool align=false) const
Return a human-readable debug-type string to full precision (probably not a format to show to a user ...
static RealTime fromXsdDuration(std::string xsdd)
std::string toFrameText(int fps) const
Return a user-readable string in which seconds are divided into frames (presumably at a lower frame r...
RealTime operator *(int m) const
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...