From 91db37daabbdc9de42e2d158408ccdf898c992ef Mon Sep 17 00:00:00 2001 From: josteph Date: Sat, 13 Oct 2018 20:30:08 +0000 Subject: [PATCH] irdya_date: Fix comparison of BW/BF years returning true for both 12 BW < 34 BW and 34 BW < 12 BW. The block on line 99 was entered for BW years, but shouldn't have been. Fixes #3187. (cherry picked from commit 5e97d1505f529c45ff8e48f694b6fd938b56e3af) --- src/tests/test_irdya_date.cpp | 1 + src/utils/irdya_datetime.cpp | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/tests/test_irdya_date.cpp b/src/tests/test_irdya_date.cpp index 1e3e4efaf45c..ee02f6876854 100644 --- a/src/tests/test_irdya_date.cpp +++ b/src/tests/test_irdya_date.cpp @@ -44,6 +44,7 @@ BOOST_AUTO_TEST_CASE(test_irdya_date_ordering) { irdya_date BW_34(irdya_date::EPOCH::BEFORE_WESNOTH, 34), BW_12(irdya_date::EPOCH::BEFORE_WESNOTH, 12), YW_40(irdya_date::EPOCH::WESNOTH, 40), YW_52(irdya_date::EPOCH::WESNOTH, 52); irdya_date BF_29(irdya_date::EPOCH::BEFORE_FALL, 29), BF_42(irdya_date::EPOCH::BEFORE_FALL, 42), AF_12(irdya_date::EPOCH::AFTER_FALL, 12), AF_102(irdya_date::EPOCH::AFTER_FALL, 102), Y0; + BOOST_CHECK(!(BW_12 < BW_34)); BOOST_CHECK(BW_34 < BW_12); BOOST_CHECK(BW_34 < YW_40); BOOST_CHECK(BW_34 < YW_52); diff --git a/src/utils/irdya_datetime.cpp b/src/utils/irdya_datetime.cpp index ad5716dee11c..414e10fb31b7 100644 --- a/src/utils/irdya_datetime.cpp +++ b/src/utils/irdya_datetime.cpp @@ -92,15 +92,11 @@ bool operator<(const irdya_date& a, const irdya_date& b) using EPOCH = irdya_date::EPOCH; // The BW and BF epochs count backward, much like BCE - if((a.get_epoch() == EPOCH::BEFORE_WESNOTH || a.get_epoch() == EPOCH::BEFORE_FALL) && a.get_year() > b.get_year()) { - return true; - } - - if(a.get_year() < b.get_year()) { - return true; + if(a.get_epoch() == EPOCH::BEFORE_WESNOTH || a.get_epoch() == EPOCH::BEFORE_FALL) { + return (a.get_year() > b.get_year()); + } else { + return (a.get_year() < b.get_year()); } - - return false; } bool operator>(const irdya_date& a, const irdya_date& b)