Skip to content

Commit

Permalink
Save Changes Bug 792106 - Wrong dates displayed
Browse files Browse the repository at this point in the history
The first attempt to fix this, a17bc85, doesn't work because the
boost::date_time constructor gets enough information in most cases to
generate a date, just not the one we expect. This change looks for '-' in
the fourth position and if it's there assumes iso-extended format, otherwise
it assumes delimiter-less ISO without the 'T', i.e. %Y%m%d%H%M%S.
  • Loading branch information
jralls committed Jan 9, 2018
1 parent fcf8826 commit ebbcd30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 5 additions & 9 deletions libgnucash/engine/gnc-datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,12 @@ GncDateTimeImpl::GncDateTimeImpl(const std::string str) :
auto input_facet(new Facet());
std::istringstream ss(str.substr(0, tzpos));
ss.imbue(std::locale(std::locale(), input_facet));
input_facet->set_iso_extended_format();
if (str.find("-") == 4)
input_facet->set_iso_extended_format();
else /* Not in iso format, try squashed format. */
input_facet->format("%Y%m%d%H%M%S");
PTime pdt(not_a_date_time);
ss >> pdt;
if (pdt.is_special())
{
input_facet->format("%Y%m%d%H%M%S");
ss.clear(); //Reset to the beginning.
ss.seekg(0);
ss >> pdt;
}
m_time = LDT(pdt.date(), pdt.time_of_day(), tzptr,
LDTBase::NOT_DATE_TIME_ON_ERROR);
}
Expand Down Expand Up @@ -450,7 +446,7 @@ GncDateTime::GncDateTime(const time64 time) :
m_impl(new GncDateTimeImpl(time)) {}
GncDateTime::GncDateTime(const struct tm tm) :
m_impl(new GncDateTimeImpl(tm)) {}
GncDateTime::GncDateTime(const std::string str, std::string fmt) :
GncDateTime::GncDateTime(const std::string str) :
m_impl(new GncDateTimeImpl(str)) {}
GncDateTime::~GncDateTime() = default;

Expand Down
10 changes: 10 additions & 0 deletions libgnucash/engine/test/gtest-gnc-datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ TEST(gnc_datetime_constructors, test_string_constructor)
EXPECT_EQ(tm.tm_hour, 15);
EXPECT_EQ(tm.tm_min, 8);
EXPECT_EQ(tm.tm_sec, 19);
/* Squashed format from SQLite3 databases */
timestr = "20151205115703";
GncDateTime time4(timestr);
tm = time4.utc_tm();
EXPECT_EQ(tm.tm_year, 115);
EXPECT_EQ(tm.tm_mon, 11);
EXPECT_EQ(tm.tm_mday, 5);
EXPECT_EQ(tm.tm_hour,11);
EXPECT_EQ(tm.tm_min, 57);
EXPECT_EQ(tm.tm_sec, 3);
}

TEST(gnc_datetime_constructors, test_struct_tm_constructor)
Expand Down

0 comments on commit ebbcd30

Please sign in to comment.