diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2013-01-03 13:01:17 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-03 18:19:28 +0100 |
commit | 1b47059c886d76cc1a403e74abd034cce3b53a34 (patch) | |
tree | 3950a5ae1c4b9c76869c4b9defcfb6f26702651c /src/corelib/tools | |
parent | ee7dbf97bbec888a9a5abceeab87c4a570ef20fc (diff) |
Clarify how two digit years are parsed by QDateTime::fromString().
It's currently not obvious that two digit years will always be in the
20th century (1900's).
Task-number: QTBUG-28797
Change-Id: I7dee9a46e0cb803a8f097debc5443d1789c2f16c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Venugopal Shivashankar <venugopal.shivashankar@digia.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 9ac4c1a87f..9949aeb7a1 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3533,6 +3533,18 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f) This could have meant 1 January 00:30.00 but the M will grab two digits. + Incorrectly specified fields of the \a string will cause an invalid + QDateTime to be returned. For example, consider the following code, + where the two digit year 12 is read as 1912 (see the table below for all + field defaults); the resulting datetime is invalid because 23 April 1912 + was a Tuesday, not a Monday: + + \snippet code/src_corelib_tools_qdatetime.cpp 20 + + The correct code is: + + \snippet code/src_corelib_tools_qdatetime.cpp 21 + For any field that is not represented in the format, the following defaults are used: |