Ticket URL: <
http://trac.wxwidgets.org/ticket/14704#comment:3>
#14704: New function to get difference of two wxDateTime objects as a wxDateSpan
-------------------------+--------------------------------------------------
Reporter: jonasr | Owner:
Type: enhancement | Status: confirmed
Priority: normal | Milestone:
Component: base | Version:
Keywords: wxDateTime | Blockedby:
Patch: 1 | Blocking:
-------------------------+--------------------------------------------------
Comment(by jonasr):
Writing the test I noted that arithmetics with the resulting wxDateSpan
gives wrong results.
Consider this:
{{{
wxDateTime dt1(11, wxDateTime::Jan, 1996);
wxDateTime dt2(5, wxDateTime::Jun, 1998);
wxDateSpan diff = dt2.DiffAsDateSpan(dt1);
// now diff has years=1, months=28, weeks=125, days=0
wxDateTime dt3 = dt1 + diff;
// now dt3 = 2001-10-02, so dt3 != dt2
}}}
This is because DiffAsDateSpan fills all fields that it can, so calls to
GetYears()/GetMonths()/GetDays() etc. returns correctly for the diff.
But wxDateSpan::Add(const wxDateSpan&) uses all fields for adding, so it
effectivly adds the span four times.
This maybe is somewhat unexpected, so i make a not of it in the
documentation.
This means that writing a test that checks arithmetics is not possible, so
the only thing I can think of is testing that the calculation of
year/month/week/day is correct, hope that's ok.
--
Ticket URL: <
http://trac.wxwidgets.org/ticket/14704#comment:3>