Fix erroneous reports of unresolved assets when checking OV/VF pairs.
[libdcp.git] / src / dcp_time.cc
index 526c784c95b09bff127aba1900d501281972a5d6..acc9723f99045a242822e1d94cde67c2c6d36334 100644 (file)
@@ -39,6 +39,7 @@
 #include "dcp_time.h"
 #include "exceptions.h"
 #include "compose.hpp"
+#include "dcp_assert.h"
 #include <boost/algorithm/string.hpp>
 #include <boost/optional.hpp>
 #include <iostream>
@@ -208,11 +209,7 @@ dcp::operator< (Time const & a, Time const & b)
                return a.s < b.s;
        }
 
-       if ((a.e * b.tcr) != (b.e * a.tcr)) {
-               return (a.e * b.tcr) < (b.e * a.tcr);
-       }
-
-       return true;
+       return (a.e * b.tcr) < (b.e * a.tcr);
 }
 
 bool
@@ -230,11 +227,7 @@ dcp::operator> (Time const & a, Time const & b)
                return a.s > b.s;
        }
 
-       if ((a.e * b.tcr) != (b.e * a.tcr)) {
-               return (a.e * b.tcr) > (b.e * a.tcr);
-       }
-
-       return true;
+       return (a.e * b.tcr) > (b.e * a.tcr);
 }
 
 ostream &
@@ -330,18 +323,15 @@ dcp::operator/ (Time a, Time const & b)
 string
 Time::as_string (Standard standard) const
 {
-       locked_stringstream str;
-       str << setw(2) << setfill('0') << h << ":"
-           << setw(2) << setfill('0') << m << ":"
-           << setw(2) << setfill('0') << s << ":";
+       char buffer[64];
 
        if (standard == SMPTE) {
-               str << setw(2) << setfill('0') << e;
+               snprintf (buffer, sizeof(buffer), "%02d:%02d:%02d:%02d", h, m, s, e);
        } else {
-               str << setw(3) << setfill('0') << e;
+               snprintf (buffer, sizeof(buffer), "%02d:%02d:%02d:%03d", h, m, s, e);
        }
 
-       return str.str ();
+       return buffer;
 }
 
 /** @param tcr_ Timecode rate with which the return value should be counted.
@@ -367,5 +357,22 @@ Time::as_seconds () const
 Time
 Time::rebase (int tcr_) const
 {
-       return Time (h, m, s, floor (float (e) * tcr_ / tcr), tcr_);
+       long int e_ = lrintf (float (e) * tcr_ / tcr);
+       int s_ = s;
+       if (e_ >= tcr_) {
+               e_ -= tcr_;
+               ++s_;
+       }
+       int m_ = m;
+       if (s_ >= 60) {
+               s_ -= 60;
+               ++m_;
+       }
+       int h_ = h;
+       if (m_ >= 60) {
+               m_ -= 60;
+               ++h_;
+       }
+
+       return Time (h_, m_, s_, e_, tcr_);
 }