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.
This commit is contained in:
josteph 2018-10-13 20:30:08 +00:00
parent 808bd59dae
commit 5e97d1505f
2 changed files with 5 additions and 8 deletions

View file

@ -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);

View file

@ -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_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());
}
if(a.get_year() < b.get_year()) {
return true;
}
return false;
}
bool operator>(const irdya_date& a, const irdya_date& b)