Fix some embarassing bugs in dcp::LocalTime comparisons.
authorCarl Hetherington <cth@carlh.net>
Fri, 30 Dec 2022 16:31:32 +0000 (17:31 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 30 Dec 2022 16:31:32 +0000 (17:31 +0100)
src/local_time.cc
test/local_time_test.cc

index 727583e5eaf1c1af47f1c0cd52dfa13ebb1fc311..f60fb0a615b872998f2cd895d413b027e4654008 100644 (file)
@@ -273,7 +273,7 @@ bool
 LocalTime::operator== (LocalTime const & other) const
 {
        return _year == other._year && _month == other._month && _day == other._day &&
-               _hour == other._hour && _second == other._second && _millisecond == other._millisecond &&
+               _hour == other._hour && _minute == other._minute && _second == other._second && _millisecond == other._millisecond &&
                _offset == other._offset;
 }
 
@@ -295,6 +295,9 @@ LocalTime::operator< (LocalTime const & other) const
        if (_hour != other._hour) {
                return _hour < other._hour;
        }
+       if (_minute != other._minute) {
+               return _minute < other._minute;
+       }
        if (_second != other._second) {
                return _second < other._second;
        }
@@ -319,6 +322,9 @@ LocalTime::operator>(LocalTime const & other) const
        if (_hour != other._hour) {
                return _hour > other._hour;
        }
+       if (_minute != other._minute) {
+               return _minute > other._minute;
+       }
        if (_second != other._second) {
                return _second > other._second;
        }
index 33551e46d410ebbcadbee6f96c1dbe6bcf4c5252..c38b2d5c61be6c71e2ca4c4c22c1eba782e4f740 100644 (file)
@@ -224,3 +224,11 @@ BOOST_AUTO_TEST_CASE (local_time_from_asn1_generalized_time_test)
        BOOST_CHECK_EQUAL (dcp::LocalTime::from_asn1_generalized_time("20210215165952").as_string(), "2021-02-15T16:59:52+00:00");
 }
 
+
+BOOST_AUTO_TEST_CASE(local_time_comparison_test)
+{
+       BOOST_CHECK(dcp::LocalTime("2014-01-01T10:00:00") < dcp::LocalTime("2014-01-01T10:05:00"));
+       BOOST_CHECK(dcp::LocalTime("2014-01-01T10:05:00") > dcp::LocalTime("2014-01-01T10:00:00"));
+       BOOST_CHECK(dcp::LocalTime("2014-01-01T10:00:00") != dcp::LocalTime("2014-01-01T10:05:00"));
+}
+