diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-12-30 17:31:32 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-12-30 17:31:32 +0100 |
| commit | 5b3a20274b3c3c05825a153580aae6a16feecb7d (patch) | |
| tree | da156b250bb33b7cd4f99527c3498000f4535200 | |
| parent | ce50486bd2af2a0875f02771dd202f9dd45fc599 (diff) | |
Fix some embarassing bugs in dcp::LocalTime comparisons.
| -rw-r--r-- | src/local_time.cc | 8 | ||||
| -rw-r--r-- | test/local_time_test.cc | 8 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/local_time.cc b/src/local_time.cc index 727583e5..f60fb0a6 100644 --- a/src/local_time.cc +++ b/src/local_time.cc @@ -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; } diff --git a/test/local_time_test.cc b/test/local_time_test.cc index 33551e46..c38b2d5c 100644 --- a/test/local_time_test.cc +++ b/test/local_time_test.cc @@ -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")); +} + |
