[ wxwindows-Bugs-1771668 ] wxDateTime::Subtract is off by one hour

SourceForge.net noreply at sourceforge.net
Wed Dec 5 06:22:25 PST 2007


Bugs item #1771668, was opened at 2007-08-10 06:41
Message generated for change (Comment added) made by andrewziem
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1771668&group_id=9863

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Other
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: ZamFear (zamfear)
Assigned to: Nobody/Anonymous (nobody)
Summary: wxDateTime::Subtract is off by one hour

Initial Comment:
the wxDateTime function
wxTimeSpan Subtract(const wxDateTime& dt) const
appears to be off by one hour.

I use wxDateTime::Subtract to subtract one wxDateTime from another.  Both are constructed from tm stucts.  Using either wxTimeSpan::Format or wxTimeSpan::GetHour, the reported difference between the two times is one hour too low (eg 11:00am - 9:00am would only show a difference of 1 hour).

I currently get around this by adding wxTimeSpan::Hour() to my result, which corrects it, except when w1 > w2 and there is less than one hour between w1 and w2 (the result is positive when it should be negative).

I am using wxMSW-2.8.4, ANSI release build, MinGW GCC version 3.4.2.


----------------------------------------------------------------------

Comment By: Andrew Ziem (andrewziem)
Date: 2007-12-05 07:22

Message:
Logged In: YES 
user_id=500759
Originator: NO

I am not reproducing the bug with wxGTK SVN and GCC 4.1.2 on Fedora 7.  
In fact, there is a test case  DateTimeTestCase::TestTimeSet() that should
cover this.  ZamFear, if you run the test case (test.exe DateTimeTestCase),
does it pass for you?

----------------------------------------------------------------------

Comment By: ZamFear (zamfear)
Date: 2007-08-16 14:03

Message:
Logged In: YES 
user_id=1864809
Originator: YES

Problem partially lies in the wxDateTime::wxDateTime(const struct tm&)
constructor.  Attached is a sample which demonstrates the issue.
Two wxDateTime objects are created, one with the tm constructor, the other
with the wxDateTime(day, month, year, hour, minute, second, millisecond)
constructor.  Even though both are based off the same tm struct, they
report different values from the GetHour() method.
(See wxDateTimeTestFrame::OnPaint in wxDateTimeTestMain.cpp)

I've switched over to the D/M/Y constructor in my project and almost
everything works normally now.  There's still the issue of (what should be)
a negative result from wxDateTime::Subtract showing as positive when
there's less than one hour between the two times.
File Added: wxDateTimeTest.zip

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1771668&group_id=9863




More information about the wx-dev mailing list