If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
-
chris
- I live to help wx-kind

- Posts: 150
- Joined: Fri Oct 08, 2004 2:05 pm
- Location: Europe
Post
by chris » Tue Apr 11, 2006 4:18 pm
Hi all,
I'm experiencing a strange problem with wxDateTime::Now(). I'm logging some stuff to a wxTextCtrl via
Code: Select all
textctrl->AppendText(wxDateTime::Now().Format(_T("%x %X: ")+somestring);
Now to the problem: The first call to wxDateTime::Now().Format(...) is off by -10 hours; all subsequent calls display the correct time. Example:
04/11/06 08:16:03: foo
04/11/06 18:16:03: foo
04/11/06 18:16:03: foo
If I call wxDateTime::Now() once before the first wxDateTime::Now().Format(...) call it works as it should.
I'm in GMT+1 with DST, btw.
Any ideas?
Chris
this->signature=NULL;
-
protocol
- Moderator

- Posts: 680
- Joined: Wed Jan 18, 2006 6:13 pm
- Location: Dallas, TX
-
Contact:
Post
by protocol » Wed Apr 12, 2006 10:12 pm
Is your locale setup correctly on your machine?
-
chris
- I live to help wx-kind

- Posts: 150
- Joined: Fri Oct 08, 2004 2:05 pm
- Location: Europe
Post
by chris » Thu Apr 13, 2006 8:13 am
Hi protocol,
Yes, it is.
I should have mentioned this happens under wxMSW 2.6.3 (and 2.6.2), but works fine under wxGTK 2.6.3.
The strange thing is that it's off just for the very first call and then works as expected. With a badly set up locale I'd assume a permanent shift.
Chris
this->signature=NULL;
-
Phoenix_pl
- Earned a small fee

- Posts: 22
- Joined: Wed Oct 05, 2005 1:24 pm
Post
by Phoenix_pl » Thu Apr 13, 2006 9:02 am
I had the same problem. This should help you:
Code: Select all
wxDateTime now = wxDateTime::Now();
textctrl->AppendText(now.Format(_T("%x %X: ")+somestring);
It worked for me.
-
chris
- I live to help wx-kind

- Posts: 150
- Joined: Fri Oct 08, 2004 2:05 pm
- Location: Europe
Post
by chris » Thu Apr 13, 2006 9:10 am
Hi Phoenix_pl,
It's good to know I'm not the only one having this problem. Are you using wxMSW, too?
I guess it's time to post a bug to the tracker...
Chris
edit: I'm sorry, but I fail to see why that should lead to a different behaviour. It's sematically identical to the call in my first post.
this->signature=NULL;
-
Phoenix_pl
- Earned a small fee

- Posts: 22
- Joined: Wed Oct 05, 2005 1:24 pm
Post
by Phoenix_pl » Thu Apr 13, 2006 9:29 am
Yes, I'm using wxMSW.
And yes, it helps and I'm not sure why. Just try it. Also I have included some screenshots.

-
chris
- I live to help wx-kind

- Posts: 150
- Joined: Fri Oct 08, 2004 2:05 pm
- Location: Europe
Post
by chris » Thu Apr 13, 2006 10:12 am
Whoa...you are right.
I don't understand this at all.
What's the big difference between
Code: Select all
wxDateTime now = wxDateTime::Now();
textctrl->AppendText(now.Format(_T("%x %X: ")+somestring);
and
Code: Select all
textctrl->AppendText(wxDateTime::Now().Format(_T("%x %X: ")+somestring);
except that one uses an anonymus variable and the other a named variable?
At first I thought this could be some wierd compiler/runtime library issue, but I see this both on Visual C++ 7.1 and MinGW 3.4.2.
Now() is an inlined method, could that have to do something with this? Though compiling with "-fno-inline" resp. "/Ob0" didn't make a change.
This is really strange. I'd like to understand this; any ideas?
Chris
this->signature=NULL;
-
eco
- Filthy Rich wx Solver

- Posts: 203
- Joined: Tue Aug 31, 2004 7:06 pm
- Location: Behind a can of Mountain Dew
-
Contact:
Post
by eco » Thu Apr 13, 2006 7:14 pm
I tried tracing the differences between the two. I didn't see anything glaringly wrong but the path is slightly complicated to trace. wxDateTime uses the default copy constructor so I doubt the issue is there. The first main difference I would think would be that the first one creates a wxDateTime instance then Now() is called versus the latter which calls Now then creates the instance. I don't immediately see why this would be a problem. I looked into Format() and my first thought was it had something to do with GetTimeZone() in datetime.cpp but it doesn't appear to care whether a wxDateTime instances has been created, it has its own static member variable it uses to determine whether the time zone has been established yet so the ordering of Now() and construction doesn't appear to matter (if it is, indeed a problem with GetTimeZone()).
I'll ping Vadim on the mailing list (he wrote these classes) and see what he thinks.
-
chris
- I live to help wx-kind

- Posts: 150
- Joined: Fri Oct 08, 2004 2:05 pm
- Location: Europe
Post
by chris » Thu Apr 13, 2006 9:32 pm
Hi eco,
I've been thinking of a copy ctor issue, too, but
Code: Select all
wxDateTime *now=&wxDateTime::Now();
textctrl->AppendText(now->Format(_T("%x %X: ")+somestring);
works as intended without calling a copy ctor, so it can't be related to that.
And thanks for looking into this and posting to wx-dev. I really want to know what's going on here.
Chris
this->signature=NULL;
-
eco
- Filthy Rich wx Solver

- Posts: 203
- Joined: Tue Aug 31, 2004 7:06 pm
- Location: Behind a can of Mountain Dew
-
Contact:
Post
by eco » Thu Apr 13, 2006 9:38 pm
Vadim's reply:
I've just tried it here (VC7.1, HEAD) and it works as expected. I'm not in
UTC-9 of course, but I'm not in UTC neither... I have really no idea why it
doesn't work for two of you.
I suspect you may have to break out the debugger if you want to get to the bottom of the issue. I'm a bit overloaded here or else I'd give it an attempt.
-
Jamie
- Filthy Rich wx Solver

- Posts: 205
- Joined: Wed Mar 30, 2005 10:56 pm
Post
by Jamie » Fri Apr 14, 2006 3:18 am
Can you please download CVS HEAD and try again as I have committed a fix for this.
Thanks
-
chris
- I live to help wx-kind

- Posts: 150
- Joined: Fri Oct 08, 2004 2:05 pm
- Location: Europe
Post
by chris » Fri Apr 14, 2006 2:52 pm
Hi Jamie,
Yes, this is fixed for me in HEAD by your changes in datetime.cpp.
Many thanks for your time!
Chris
this->signature=NULL;
-
Peterj
- Knows some wx things

- Posts: 38
- Joined: Mon Nov 14, 2005 6:48 pm
- Location: Australia
Post
by Peterj » Sat Apr 15, 2006 11:29 am
Jamie,
While you were fixing this, did you also check out Today(). It also appears to be broken in 2.6.3 (alpha).
Code: Select all
wxDateTime defdate,tday;
tday = defdate.Today();
today = tday.FormatDate();// produces a date of 03/15/2006
today = tday.Format("%d/%m/%Y"); // produces correct date 15/04/2006
Regards,
Peter
Using Win XP, Dev C++ 4.9.9.2 wx-beta 6.9
-
Jamie
- Filthy Rich wx Solver

- Posts: 205
- Joined: Wed Mar 30, 2005 10:56 pm
Post
by Jamie » Mon Apr 17, 2006 12:53 am
Try using CVS HEAD as this should also be fixed.