*/
+/** @file src/dcp_time.cc
+ * @brief A representation of time within a DCP.
+ */
+
#include <iostream>
+#include <cmath>
#include "dcp_time.h"
using namespace std;
+using namespace libdcp;
+
+Time::Time (int frame, int frames_per_second)
+ : h (0)
+ , m (0)
+ , s (0)
+ , t (0)
+{
+ float sec_float = float (frame) / frames_per_second;
+ t = (int (floor (sec_float * 1000)) % 1000) / 4;
+ s = floor (sec_float);
+
+ if (s > 60) {
+ m = s / 60;
+ s -= m * 60;
+ }
+
+ if (m > 60) {
+ h = m / 60;
+ m -= h * 60;
+ }
+}
bool
libdcp::operator== (Time const & a, Time const & b)
{
- return (a.h == b.h && a.m == b.m && a.s == b.s && a.ms == b.ms);
+ return (a.h == b.h && a.m == b.m && a.s == b.s && a.t == b.t);
}
bool
return a.s <= b.s;
}
- if (a.ms != b.ms) {
- return a.ms <= b.ms;
+ if (a.t != b.t) {
+ return a.t <= b.t;
}
return true;
ostream &
libdcp::operator<< (ostream& s, Time const & t)
{
- s << t.h << ":" << t.m << ":" << t.s << "." << t.ms;
+ s << t.h << ":" << t.m << ":" << t.s << "." << t.t;
return s;
}