Add operator< for LocalTime.
authorCarl Hetherington <cth@carlh.net>
Fri, 14 Sep 2018 20:21:47 +0000 (21:21 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 14 Sep 2018 20:21:47 +0000 (21:21 +0100)
src/local_time.cc
src/local_time.h

index 647ff35dd45e2032775a75ff9c7a2b62f2a13f34..401bd9d749d6ba6a593078c8082a832fbbc4494d 100644 (file)
@@ -212,6 +212,27 @@ LocalTime::operator== (LocalTime const & other) const
                _tz_hour == other._tz_hour && _tz_minute == other._tz_minute;
 }
 
+bool
+LocalTime::operator< (LocalTime const & other) const
+{
+       if (_year != other._year) {
+               return _year < other._year;
+       }
+       if (_month != other._month) {
+               return _month < other._month;
+       }
+       if (_day != other._day) {
+               return _day < other._day;
+       }
+       if (_hour != other._hour) {
+               return _hour < other._hour;
+       }
+       if (_second != other._second) {
+               return _second < other._second;
+       }
+       return _millisecond < other._millisecond;
+}
+
 bool
 LocalTime::operator!= (LocalTime const & other) const
 {
index d213b898f5371e9589254c8c0fe3db6e21d3e69a..ad55ad5a8ee372d959d31019db76804c44e1920e 100644 (file)
@@ -68,6 +68,7 @@ public:
 
        bool operator== (LocalTime const & other) const;
        bool operator!= (LocalTime const & other) const;
+       bool operator< (LocalTime const & other) const;
 
 private:
        friend class ::local_time_test;