if (mday < 0) {
boost::gregorian::date d(GetEndOfMonthDay(reference->tm_year + 1900, mon + 1)); //TODO: Refactor this mess into full Boost.DateTime
+ //Depending on the number, we need to substract specific days (counting starts at 0).
+ d = d - boost::gregorian::days(mday * -1 - 1);
+
*begin = boost::gregorian::to_tm(d);
begin->tm_hour = 0;
begin->tm_min = 0;
if (mday < 0) {
boost::gregorian::date d(GetEndOfMonthDay(reference->tm_year + 1900, mon + 1)); //TODO: Refactor this mess into full Boost.DateTime
+ //Depending on the number, we need to substract specific days (counting starts at 0).
+ d = d - boost::gregorian::days(mday * -1 - 1);
+
// End date is one day in the future, starting 00:00:00
d = d + boost::gregorian::days(1);
BOOST_CHECK_EQUAL(begin, expectedBegin);
BOOST_CHECK_EQUAL(end, expectedEnd);
+ //-----------------------------------------------------
+ // Third last day of the month
+ timestamp = "day -3";
+ tm_ref.tm_year = 2019 - 1900;
+ tm_ref.tm_mon = 7 - 1;
+
+ expectedBegin = boost::posix_time::ptime(boost::gregorian::date(2019, 7, 29), boost::posix_time::time_duration(0, 0, 0));
+
+ expectedEnd = boost::posix_time::ptime(boost::gregorian::date(2019, 7, 30), boost::posix_time::time_duration(0, 0, 0));
+
+ // Run Tests
+ LegacyTimePeriod::ParseTimeSpec(timestamp, &tm_beg, &tm_end, &tm_ref);
+
+ // Compare times
+ begin = boost::posix_time::ptime_from_tm(tm_beg);
+ end = boost::posix_time::ptime_from_tm(tm_end);
+
+ BOOST_CHECK_EQUAL(begin, expectedBegin);
+ BOOST_CHECK_EQUAL(end, expectedEnd);
+
//-----------------------------------------------------
// Leap year with the last day of the month
timestamp = "day -1";