MessageCore::DateFormatter
#include <dateformatter.h>
Public Types | |
enum | FormatType : uint8_t { CTime , Localized , Fancy , Custom } |
Public Member Functions | |
DateFormatter (FormatType ftype=DateFormatter::Fancy) | |
~DateFormatter () | |
QString | customFormat () const |
QString | dateString (const QDateTime &dtime, const QString &lang=QString(), bool shortFormat=true) const |
FormatType | format () const |
void | invalidateReferenceDate () const |
void | setCustomFormat (const QString &format) |
void | setFormat (FormatType ftype) |
Static Public Member Functions | |
static QString | formatCurrentDate (DateFormatter::FormatType ftype, const QString &data=QString(), bool shortFormat=true) |
static QString | formatDate (DateFormatter::FormatType ftype, const QDateTime &t, const QString &data=QString(), bool shortFormat=true) |
Detailed Description
A class for abstracting date formatting.
This class deals with different kinds of date display formats. The formats supported include:
- fancy "Today 02:08:35"
- ctime as with the ctime function, eg. "Sun Mar 31 02:08:35 2002"
- localized according to the control center setting, eg. "2002-03-31 02:08"
- custom "whatever you like"
- Note
- If a long-lived instance of this class is kept, its owner is responsible for calling
invalidateReferenceDate()
on date changes. This ensures that theFancy
formatter has an up-to-date notion of "Today", "Yesterday" etc.
Definition at line 54 of file dateformatter.h.
Member Enumeration Documentation
◆ FormatType
enum MessageCore::DateFormatter::FormatType : uint8_t |
The different types of date formats.
Enumerator | |
---|---|
CTime | ctime "Sun Mar 31 02:08:35 2002" |
Localized | localized "2002-03-31 02:08" |
Fancy | fancy "Today 02:08:35" |
Custom | custom "whatever you like" |
Definition at line 60 of file dateformatter.h.
Constructor & Destructor Documentation
◆ DateFormatter()
|
explicit |
Constructs a date formatter with a default FormatType.
- Parameters
-
ftype is the default FormatType to use.
Definition at line 80 of file dateformatter.cpp.
◆ ~DateFormatter()
|
default |
Destroys the date formatter.
Member Function Documentation
◆ customFormat()
|
nodiscard |
Returns the custom format string.
- See also
- setCustomFormat().
Definition at line 138 of file dateformatter.cpp.
◆ dateString()
|
nodiscard |
Constructs a formatted date string from QDateTime dtime
.
- Parameters
-
dtime is the QDateTime to use for formatting. lang is the language, only used if FormatType is Localized. shortFormat if true, create the short version of the date string, only used if FormatType is Localized.
- Returns
- a QString containing the formatted date.
Definition at line 98 of file dateformatter.cpp.
◆ format()
|
nodiscard |
Returns the FormatType currently set.
- See also
- setFormat().
Definition at line 88 of file dateformatter.cpp.
◆ formatCurrentDate()
|
staticnodiscard |
Convenience function, same as formatDate() but returns the current time formatted.
- Parameters
-
ftype is the FormatType to use. data is either the format when FormatType is Custom, or language when FormatType is Localized. shortFormat if true, create the short version of the date string, only used if FormatType is Localized.
- Returns
- a QString containing the formatted date.
Definition at line 221 of file dateformatter.cpp.
◆ formatDate()
|
staticnodiscard |
Convenience function dateString.
- Parameters
-
ftype is the FormatType to use. t is the time to use for formatting. data is either the format when FormatType is Custom, or language when FormatType is Localized. shortFormat if true, create the short version of the date string, only used if FormatType is Localized.
- Returns
- a QString containing the formatted date.
Definition at line 212 of file dateformatter.cpp.
◆ invalidateReferenceDate()
void DateFormatter::invalidateReferenceDate | ( | ) | const |
Invalidates the cached reference date used by the Fancy
formatter to determine the meaning of "Today", "Yesterday" etc.
Definition at line 143 of file dateformatter.cpp.
◆ setCustomFormat()
void DateFormatter::setCustomFormat | ( | const QString & | format | ) |
Sets the custom format for date to string conversions to format
.
This method accepts the same arguments as QDateTime::toString(), but also supports the "Z" expression which is substituted with the RFC2822 (Section 3.3) style numeric timezone (-0500).
- Parameters
-
format is a QString containing the custom format.
- See also
- QDateTime::toString(), customFormat().
Definition at line 132 of file dateformatter.cpp.
◆ setFormat()
void DateFormatter::setFormat | ( | FormatType | ftype | ) |
Sets the date format to ftype
.
- Parameters
-
ftype is the FormatType.
- See also
- format().
Definition at line 93 of file dateformatter.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.