wxDateTime Setting month fails 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
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

wxDateTime Setting month fails

Post by raananb »

The code below is supposed to set the embedded_Calendar one month back from the current month. It works for January (setting to December of the previous year), but the SetMonth statement raises an "invalid broken down date/time" error message. GetMonth() gives the correct month : 9 for 2018-10-31.

It compiles with no errors with today's Trunk on Windows 10, using Visual Studio 2017 Community.

Code: Select all

wxDateTime calendarToday = embedded_Calendar->GetDate();

if (m_data.PreviousMonth)
{ 
    if (calendarToday.GetMonth() == 0)
    { // january - set to dec and year-1
        calendarToday.SetMonth(wxDateTime::Dec);
        calendarToday.SetYear((int) (calendarToday.GetYear() - 1));
    }
    else
    { // set to month-1
       calendarToday.SetMonth(wxDateTime::Month(calendarToday.GetMonth() - 1));
    }

    embedded_Calendar->SetDate(calendarToday);
}
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

Re: wxDateTime Setting month fails

Post by raananb »

Problem gone when SetMonth() is replaced by Set() as follows:

Code: Select all

calendarToday.Set(1, wxDateTime::Month(calendarToday.GetMonth() - 1), calendarToday.GetYear());
Post Reply