Fix incorrect coalesce() output when one input range is wholly
[dcpomatic.git] / src / lib / dcpomatic_time_coalesce.h
index e6e16641ef7e65091993dbe1d4e1b892fac0eeae..56f82bcb680932b1bb8ff86a263dddf594093892 100644 (file)
@@ -32,11 +32,11 @@ std::list<TimePeriod<T> > coalesce (std::list<TimePeriod<T> > periods)
        do {
                coalesced.clear ();
                did_something = false;
-               for (typename std::list<TimePeriod<T> >::const_iterator i = periods.begin(); i != periods.end(); ++i) {
-                       typename std::list<TimePeriod<T> >::const_iterator j = i;
+               for (auto i = periods.begin(); i != periods.end(); ++i) {
+                       auto j = i;
                        ++j;
                        if (j != periods.end() && (i->overlap(*j) || i->to == j->from)) {
-                               coalesced.push_back (TimePeriod<T> (i->from, j->to));
+                               coalesced.push_back(TimePeriod<T>(std::min(i->from, j->from), std::max(i->to, j->to)));
                                did_something = true;
                                ++i;
                        } else {