wxDateTime::Parseformat return less one month Topic is solved

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.
Post Reply
bcteh
Experienced Solver
Experienced Solver
Posts: 72
Joined: Mon Nov 27, 2006 9:56 am

wxDateTime::Parseformat return less one month

Post by bcteh » Mon Dec 18, 2006 10:22 am

Hi,

I use the below code to convert string date to wxDateTime.
The month return alway less one month.
Am i do a mistake or is this a bug in wxWidget?

Version : wxWidgets-2.6.3

wxDateTime dt;
dt.ParseFormat(wxT("17-Jan-2005 11:20:21"),wxT("%d-%b-%Y %T"));
if (dt.IsValid()) {
wxLogDebug(wxString::Format(wxT("Year=%i Month=%i Day=%i"),dt.GetYear(),dt.GetMonth(),dt.GetDay()));
}

"17-Jan-2005 11:20:21"
result : Year=2005 Month=0 Day=17
"17-Oct-2005 11:20:21"
result: Year=2005 Month=9 Day=17

Regards
Teh

S.Volkenandt
Knows some wx things
Knows some wx things
Posts: 26
Joined: Tue Nov 14, 2006 1:51 pm
Location: Duesseldorf, Germany

Post by S.Volkenandt » Mon Dec 18, 2006 10:30 am

The GetMonth method of wxDateTime returns a member of the Month enum, in which "Jan" has value 0.

benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte » Mon Dec 18, 2006 1:21 pm

You should remember that arrays in C/C++ are considered to go from 0 to n-1... We often do the same with enumerated values.
Therefore, January is 0.
:arrow: Logical.

bcteh
Experienced Solver
Experienced Solver
Posts: 72
Joined: Mon Nov 27, 2006 9:56 am

Post by bcteh » Tue Dec 19, 2006 3:40 am

In this case, after PasteFormat, to display the expected month i should
increase it by one.

dt.ParseFormat("17-Jan-2005 11:20:21",wxT("%d-%b-%Y %T"));
wxLogDebug(wxString::Format(wxT("Year=%i Month=%i Day=%i"),dt.GetYear(),dt.GetMonth()+1,dt.GetDay()));

Thank
Last edited by bcteh on Tue Dec 19, 2006 3:50 am, edited 1 time in total.

Post Reply