+// Toggle a restricted date range to the six months centered on today's date.
+void MyPanel::LimitDateRange(bool on)
+{
+ if ( on )
+ {
+ // limit the choice of date to 3 months around today
+ const wxDateSpan diff = wxDateSpan::Months(3);
+ const wxDateTime today = wxDateTime::Today();
+
+ // Set the restricted date range.
+ if ( m_calendar->SetDateRange(today - diff, today + diff) )
+ {
+ wxLogStatus("Date range limited to 3 months around today.");
+ wxDateTime firstValidDate;
+ wxDateTime lastValidDate;
+ if ( m_calendar->GetDateRange(&firstValidDate, &lastValidDate) )
+ {
+ wxLogMessage("First valid date: %s, last valid date: %s",
+ firstValidDate.FormatISODate(),
+ lastValidDate.FormatISODate());
+ }
+ else
+ {
+ wxLogWarning("Failed to get back the valid dates range.");
+ }
+ }
+ else
+ {
+ wxLogWarning("Date range not supported.");
+ }
+ }
+ else // off
+ {
+ // Remove the date restrictions.
+ if ( m_calendar->SetDateRange() )
+ {
+ wxLogStatus("Date choice is unlimited now.");
+ }
+ else
+ {
+ wxLogWarning("Date range not supported.");
+ }
+ }
+
+ m_calendar->Refresh();
+}
+