diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index ff72517769..cc2061a175 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -580,6 +580,10 @@ wxString wxDateTime::Format(const wxString& formatp, const TimeZone& tz) const res += wxString::Format(fmt, tm.mday); break; + case wxT('F'): // ISO 8601 date + res += wxString::Format(wxT("%04d-%02d-%02d"), tm.year, tm.mon + 1, tm.mday); + break; + case wxT('g'): // 2-digit week-based year res += wxString::Format(fmt, GetWeekBasedYear() % 100); break; @@ -1229,6 +1233,22 @@ wxDateTime::ParseFormat(const wxString& date, mday = (wxDateTime_t)num; break; + case wxT('F'): // ISO 8601 date + { + wxDateTime dt = ParseFormatAt(input, end, wxS("%Y-%m-%d")); + if ( !dt.IsValid() ) + return false; + + const Tm tm = dt.GetTm(); + + year = tm.year; + mon = tm.mon; + mday = tm.mday; + + haveDay = haveMon = haveYear = true; + } + break; + case wxT('H'): // hour in 24h format (00-23) if ( !GetNumericToken(width, input, end, &num) || (num > 23) ) { diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 43c3d94cf3..565a1077cf 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -684,6 +684,7 @@ void DateTimeTestCase::TestTimeFormat() { CompareYear, "Date is %x, time is %X" }, // %x could use 2 digits { CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" }, { CompareNone, "The day of year: %j, the week of year: %W" }, + { CompareDate, "ISO date using short form: %F" }, { CompareDate, "ISO date without separators: %Y%m%d" }, { CompareBoth, "RFC 2822 string: %Y-%m-%d %H:%M:%S.%l %z" },