diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-12-30 18:12:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-12-30 18:12:52 +0100 |
| commit | 6919bfcb39c4df829edc82dcd30968a4aca3fbee (patch) | |
| tree | 1909431f491545056fee621f8a6d1bdf0f3fc596 | |
| parent | ef35f6a6c43d2be30b82ca943c56cf06f140d24d (diff) | |
Change the behaviour of LocalTime::operator== to make the same time in different time zones equal.v1.8.49
Previously different offsets would mean that the times compared as
not-equal.
| -rw-r--r-- | src/local_time.cc | 8 | ||||
| -rw-r--r-- | src/local_time.h | 3 | ||||
| -rw-r--r-- | test/local_time_test.cc | 3 |
3 files changed, 11 insertions, 3 deletions
diff --git a/src/local_time.cc b/src/local_time.cc index 9d36f76d..659d5c82 100644 --- a/src/local_time.cc +++ b/src/local_time.cc @@ -272,9 +272,11 @@ LocalTime::add_minutes (int m) bool LocalTime::operator== (LocalTime const & other) const { - return _year == other._year && _month == other._month && _day == other._day && - _hour == other._hour && _minute == other._minute && _second == other._second && _millisecond == other._millisecond && - _offset == other._offset; + auto a = as_utc(); + auto b = other.as_utc(); + + return a.year() == b.year() && a.month() == b.month() && a.day() == b.day() && + a.hour() == b.hour() && a.minute() == b.minute() && a.second() == b.second() && a.millisecond() == b.millisecond(); } diff --git a/src/local_time.h b/src/local_time.h index fdb6fc90..e1baedcc 100644 --- a/src/local_time.h +++ b/src/local_time.h @@ -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 { diff --git a/test/local_time_test.cc b/test/local_time_test.cc index 72390862..63083947 100644 --- a/test/local_time_test.cc +++ b/test/local_time_test.cc @@ -250,4 +250,7 @@ BOOST_AUTO_TEST_CASE(local_time_comparison_test) BOOST_CHECK(dcp::LocalTime("2014-10-10T10:00:01+01:00") > dcp::LocalTime("2014-10-10T10:00:00+01:00")); BOOST_CHECK(dcp::LocalTime("2014-01-01T10:00:00") != dcp::LocalTime("2014-01-01T10:05:00")); + BOOST_CHECK(dcp::LocalTime("2014-01-01T10:00:00") == dcp::LocalTime("2014-01-01T10:00:00")); + BOOST_CHECK(dcp::LocalTime("2014-01-01T10:00:00+02:00") == dcp::LocalTime("2014-01-01T08:00:00")); + BOOST_CHECK(dcp::LocalTime("2014-01-01T10:00:00+02:00") == dcp::LocalTime("2014-01-01T11:00:00+03:00")); } |
