diff --git a/src/Range.cpp b/src/Range.cpp index 6ab8aebc..163e5e41 100644 --- a/src/Range.cpp +++ b/src/Range.cpp @@ -220,6 +220,17 @@ std::vector Range::subtract (const Range& other) const return results; } +//////////////////////////////////////////////////////////////////////////////// +// Returns the number of seconds between start and end. +// If the range is open, use 'now' as the end. +time_t Range::total () const +{ + if (ended ()) + return Datetime (end) - Datetime (start); + + return Datetime () - Datetime (start); +} + //////////////////////////////////////////////////////////////////////////////// std::string Range::dump () const { diff --git a/src/Range.h b/src/Range.h index 9400a508..8c3267d1 100644 --- a/src/Range.h +++ b/src/Range.h @@ -42,6 +42,7 @@ public: bool overlap (const Range&) const; Range intersect (const Range&) const; std::vector subtract (const Range&) const; + time_t total () const; std::string dump () const;