+ switch (rnr)
+ {
+ case 1: replacement=r; break;
+ case 2: replacement2=r; break;
+ case 3: replacement3=r; break;
+ case 4: replacement4=r; break;
+ }
+ }
+ // replace all occurrences of year with it
+ bool wasReplaced = fmt2.Replace(strYear, replacement) > 0;
+ // evaluation order ensures we always attempt the replacement.
+ wasReplaced = (fmt2.Replace(strYear2, replacement2) > 0) || wasReplaced;
+
+ // use strftime() to format the same date but in supported
+ // year
+ //
+ // NB: we assume that strftime() doesn't check for the
+ // date validity and will happily format the date
+ // corresponding to Feb 29 of a non leap year (which
+ // may happen if yearReal was leap and year is not)
+ struct tm tmAdjusted;
+ InitTm(tmAdjusted);
+ tmAdjusted.tm_hour = tm.hour;
+ tmAdjusted.tm_min = tm.min;
+ tmAdjusted.tm_sec = tm.sec;
+ tmAdjusted.tm_wday = tm.GetWeekDay();
+ tmAdjusted.tm_yday = GetDayOfYear();
+ tmAdjusted.tm_mday = tm.mday;
+ tmAdjusted.tm_mon = tm.mon;
+ tmAdjusted.tm_year = year - 1900;
+ tmAdjusted.tm_isdst = 0; // no DST, already adjusted
+ wxString str = CallStrftime(*p == _T('c') ? _T("%c")
+ : _T("%x"),
+ &tmAdjusted);
+
+ // now replace the occurrence of 1999 with the real year
+ // we do this in two stages to stop the 2 digit year
+ // matching any substring of the 4 digit year.
+ // Any day,month hours and minutes components should be safe due
+ // to ensuring the range of the years.
+ wxString strYearReal, strYearReal2;
+ strYearReal.Printf(_T("%04d"), yearReal);
+ strYearReal2.Printf(_T("%02d"), yearReal % 100);
+ str.Replace(strYear, replacement3);
+ str.Replace(strYear2,replacement4);
+ str.Replace(replacement3, strYearReal);
+ str.Replace(replacement4, strYearReal2);
+
+ // and replace back all occurrences of replacement string
+ if ( wasReplaced )
+ {
+ str.Replace(replacement2, strYear2);
+ str.Replace(replacement, strYear);
+ }