+
+libdcp::Time
+libdcp::operator+ (Time a, Time const & b)
+{
+ Time r;
+
+ r.t = a.t + b.t;
+ if (r.t >= 250) {
+ r.t -= 250;
+ r.s++;
+ }
+
+ r.s += a.s + b.s;
+ if (r.s >= 60) {
+ r.s -= 60;
+ r.m++;
+ }
+
+ r.m += a.m + b.m;
+ if (r.m >= 60) {
+ r.m -= 60;
+ r.h++;
+ }
+
+ r.h += a.h + b.h;
+
+ return r;
+}
+
+libdcp::Time
+libdcp::operator- (Time a, Time const & b)
+{
+ Time r;
+
+ r.t = a.t - b.t;
+ if (r.t < 0) {
+ r.t += 250;
+ r.s--;
+ }
+
+ r.s += (a.s - b.s);
+ if (r.s < 0) {
+ r.s += 60;
+ r.m--;
+ }
+
+ r.m += (a.m - b.m);
+ if (r.m < 0) {
+ r.m += 60;
+ r.h--;
+ }
+
+ r.h += (a.h - b.h);
+
+ return r;
+}
+
+float
+libdcp::operator/ (Time a, Time const & b)
+{
+ int64_t const at = a.h * 3600 * 250 + a.m * 60 * 250 + a.s * 250 + a.t;
+ int64_t const bt = b.h * 3600 * 250 + b.m * 60 * 250 + b.s * 250 + b.t;
+ return float (at) / bt;
+}
+
+/** @return A string of the form h:m:s:t */
+string
+Time::to_string () const
+{
+ stringstream str;
+ str << h << ":" << m << ":" << s << ":" << t;
+ return str.str ();
+}
+
+/** @return This time in ticks */
+int64_t
+Time::to_ticks () const
+{
+ return t + s * 25 + m * 60 * 25 + h * 60 * 60 * 25;
+}
+