Switch to testing on Ubuntu 16.04 and 22.04.
[libdcp.git] / src / local_time.h
index 9a19b2d5e0a5d2bb9938d5868750ea0d4038308b..c76b876cf8864feed8afe2aa5ca00a94eaa6ca5c 100644 (file)
@@ -60,6 +60,9 @@ namespace dcp {
  *  to parse strings of the required format (those that include time zones).
  *
  *  See http://www.w3.org/TR/xmlschema-2/#dateTime
+ *
+ *  Note that operator== for this class will return true for times that have different
+ *  offsets but are the same actual time.
  */
 class LocalTime
 {
@@ -89,8 +92,10 @@ public:
                , _offset(offset)
        {}
 
-       /** @return A string of the form 2013-01-05T18:06:59+04:00 or 2013-01-05T18:06:59.123+04:00 */
-       std::string as_string (bool with_millisecond = false) const;
+       /** @return A string of the form 2013-01-05T18:06:59+04:00, 2013-01-05T18:06:59.123+04:00
+        *  2013-01-05T18:06:59 or 2013-01-05T18:06:59.123
+        */
+       std::string as_string(bool with_millisecond = false, bool with_timezone = true) const;
 
        /** @return The date in the form YYYY-MM-DD */
        std::string date () const;
@@ -122,10 +127,26 @@ public:
                return _second;
        }
 
+       int millisecond() const {
+               return _millisecond;
+       }
+
+       void set_day(int d) {
+               _day = d;
+       }
+
+       void set_month(int m) {
+               _month = m;
+       }
+
        void set_year (int y) {
                _year = y;
        }
 
+       void set_offset(UTCOffset offset) {
+               _offset = offset;
+       }
+
        void add_days (int d);
        void add_months (int a);
        void add_minutes (int a);
@@ -138,7 +159,9 @@ public:
        bool operator== (LocalTime const & other) const;
        bool operator!= (LocalTime const & other) const;
        bool operator< (LocalTime const & other) const;
+       bool operator<=(LocalTime const & other) const;
        bool operator>(LocalTime const & other) const;
+       bool operator>=(LocalTime const & other) const;
 
 private:
        friend struct ::local_time_basic_test;
@@ -146,6 +169,7 @@ private:
        void set (struct tm const * tm);
        void set (boost::posix_time::ptime);
        void set_local_time_zone ();
+       dcp::LocalTime as_utc() const;
 
        /* Local time */
        int _year = 0;        ///< year