Adding Days to wxDateTime 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
guarib
Knows some wx things
Knows some wx things
Posts: 28
Joined: Fri Sep 16, 2005 1:05 pm
Location: Rio de Janeiro - Brazil
Contact:

Adding Days to wxDateTime

Post by guarib »

Code: Select all

wxDateTime x(1, wxDateTime::Month(1), 2006);
x+=wxDateSpan::Days(30);
Why the result is 03/02/2006 (DD/MM/YYYY) and not 31/01/2006?
guarib
Knows some wx things
Knows some wx things
Posts: 28
Joined: Fri Sep 16, 2005 1:05 pm
Location: Rio de Janeiro - Brazil
Contact:

Post by guarib »

Founded. wxDateTime::Month is a enum, so 1 is not equal to Jan but Feb.
eco
Filthy Rich wx Solver
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 »

Rather than using numbers I suggest using wxDateTime::Jan, wxDateTime::Feb, etc. because there is no guarantee that wxDateTime::Jan will always equal 0. You can also easily add directly to wxDateTime::Jan if you need to iterate through or specifiy arbitrary months.

For example

Code: Select all

for(wxDateTime::Month m = wxDateTime::Jan; m < wxDateTime::Dec; ++m) /* whatever */;

// or

assert(wxDateTime::Jan + 7 == wxDateTime::Aug);
Post Reply