Skip to content

Commit

Permalink
irdya_date: Fix comparison of BW/BF years returning true for both 12 …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
jostephd committed Oct 13, 2018
1 parent 808bd59 commit 5e97d15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/tests/test_irdya_date.cpp
Expand Up @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions src/utils/irdya_datetime.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit 5e97d15

Please sign in to comment.