Page 1 of 1

Adding Days to wxDateTime

Posted: Wed Mar 22, 2006 10:06 am
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?

Posted: Wed Mar 22, 2006 10:18 am
by guarib
Founded. wxDateTime::Month is a enum, so 1 is not equal to Jan but Feb.

Posted: Wed Mar 22, 2006 6:28 pm
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);