summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetime.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-11-07 17:02:07 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2019-01-31 12:07:41 +0000
commite352ec4db4e6c6936bb406bb77776e1da89a2e84 (patch)
treefc303196e7d918d0ddd4e0c4d004ccd6135450ad /src/corelib/tools/qdatetime.cpp
parent7dd41b32678b8cedc6e03932ac4330d147f25f4a (diff)
Q(Date|Time)+::toString: correct account of format specifiers
Where non-format characters appear in the format string, they are not "ignored" as claimed; they are passed through verbatim. Formats without separators between fields are in fact supported, although results may be ambiguous. Cleaned up phrasing in the process. Fixes: QTBUG-51208 Change-Id: I7284a36c48aa0be29deaa16945ca0212e9e6f72c Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/corelib/tools/qdatetime.cpp')
-rw-r--r--src/corelib/tools/qdatetime.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 816bd974eb..3cba786865 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -908,10 +908,16 @@ QString QDate::toString(Qt::DateFormat format) const
a minus sign is prepended in addition.
\endtable
- All other input characters will be ignored. Any sequence of characters that
- are enclosed in single quotes will be treated as text and not be used as an
- expression. Two consecutive single quotes ("''") are replaced by a singlequote
- in the output. Formats without separators (e.g. "ddMM") are currently not supported.
+ Any sequence of characters enclosed in single quotes will be included
+ verbatim in the output string (stripped of the quotes), even if it contains
+ formatting characters. Two consecutive single quotes ("''") are replaced by
+ a single quote in the output. All other characters in the format string are
+ included verbatim in the output string.
+
+ Formats without separators (e.g. "ddMM") are supported but must be used with
+ care, as the resulting strings aren't always reliably readable (e.g. if "dM"
+ produces "212" it could mean either the 2nd of December or the 21st of
+ February).
Example format strings (assuming that the QDate is the 20 July
1969):
@@ -1672,10 +1678,16 @@ QString QTime::toString(Qt::DateFormat format) const
\row \li t \li the timezone (for example "CEST")
\endtable
- All other input characters will be ignored. Any sequence of characters that
- are enclosed in single quotes will be treated as text and not be used as an
- expression. Two consecutive single quotes ("''") are replaced by a singlequote
- in the output. Formats without separators (e.g. "HHmm") are currently not supported.
+ Any sequence of characters enclosed in single quotes will be included
+ verbatim in the output string (stripped of the quotes), even if it contains
+ formatting characters. Two consecutive single quotes ("''") are replaced by
+ a single quote in the output. All other characters in the format string are
+ included verbatim in the output string.
+
+ Formats without separators (e.g. "ddMM") are supported but must be used with
+ care, as the resulting strings aren't always reliably readable (e.g. if "dM"
+ produces "212" it could mean either the 2nd of December or the 21st of
+ February).
Example format strings (assuming that the QTime is 14:13:09.042 and the system
locale is \c{en_US})
@@ -3962,10 +3974,16 @@ QString QDateTime::toString(Qt::DateFormat format) const
\row \li t \li the timezone (for example "CEST")
\endtable
- All other input characters will be ignored. Any sequence of characters that
- are enclosed in single quotes will be treated as text and not be used as an
- expression. Two consecutive single quotes ("''") are replaced by a singlequote
- in the output. Formats without separators (e.g. "HHmm") are currently not supported.
+ Any sequence of characters enclosed in single quotes will be included
+ verbatim in the output string (stripped of the quotes), even if it contains
+ formatting characters. Two consecutive single quotes ("''") are replaced by
+ a single quote in the output. All other characters in the format string are
+ included verbatim in the output string.
+
+ Formats without separators (e.g. "ddMM") are supported but must be used with
+ care, as the resulting strings aren't always reliably readable (e.g. if "dM"
+ produces "212" it could mean either the 2nd of December or the 21st of
+ February).
Example format strings (assumed that the QDateTime is 21 May 2001
14:13:09.120):