KMIME Library
#include <kmime_dateformatter.h>
Public Types | |
enum | FormatType { CTime, Localized, Fancy, Iso, Rfc, Custom } |
Public Member Functions | |
DateFormatter (FormatType ftype=DateFormatter::Fancy) | |
~DateFormatter () | |
QString | customFormat () const |
QString | dateString (time_t t, const QString &lang=QString(), bool shortFormat=true, bool includeSecs=false) const |
QString | dateString (const QDateTime &dtime, const QString &lang=QString(), bool shortFormat=true, bool includeSecs=false) const |
FormatType | format () const |
void | reset () |
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, bool includeSecs=false) |
static QString | formatDate (DateFormatter::FormatType ftype, time_t t, const QString &data=QString(), bool shortFormat=true, bool includeSecs=false) |
static bool | isDaylight () |
Protected Member Functions | |
QString | cTime (time_t t) const |
QString | custom (time_t t) const |
QString | fancy (time_t t) const |
QString | isoDate (time_t t) const |
QString | localized (time_t t, bool shortFormat=true, bool includeSecs=false, const QString &lang=QString()) const |
time_t | qdateToTimeT (const QDateTime &dt) const |
QString | rfc2822 (time_t t) const |
QByteArray | zone (time_t t) const |
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"
- iso according to the ISO8601 standard, eg. "2002-03-31 02:08:35"
- rfc according to RFC2822 (Section 3.3), eg. "Sun, 31 Mar 2002 02:08:35 -0500"
- custom "whatever you like"
Definition at line 70 of file kmime_dateformatter.h.
Member Enumeration Documentation
The different types of date formats.
Definition at line 76 of file kmime_dateformatter.h.
Constructor & Destructor Documentation
|
explicit |
Constructs a date formatter with a default FormatType.
- Parameters
-
ftype is the default FormatType to use.
Definition at line 51 of file kmime_dateformatter.cpp.
DateFormatter::~DateFormatter | ( | ) |
Destroys the date formatter.
Definition at line 56 of file kmime_dateformatter.cpp.
Member Function Documentation
|
protected |
Returns a QString containing the specified time_t t
formatted with the ctime() function.
- Parameters
-
t is the time_t to use for formatting.
Definition at line 281 of file kmime_dateformatter.cpp.
|
protected |
Returns a QString containing the specified time_t t
formatted with a previously specified custom format.
- Parameters
-
t time used for formatting
Definition at line 115 of file kmime_dateformatter.cpp.
QString DateFormatter::customFormat | ( | ) | const |
Returns the custom format string.
- See also
- setCustomFormat().
Definition at line 141 of file kmime_dateformatter.cpp.
QString DateFormatter::dateString | ( | time_t | t, |
const QString & | lang = QString() , |
||
bool | shortFormat = true , |
||
bool | includeSecs = false |
||
) | const |
Constructs a formatted date string from time_t t
.
- Parameters
-
t is the time_t 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. includeSecs if true, include the seconds field in the date string, only used if FormatType is Localized.
- Returns
- a QString containing the formatted date.
Definition at line 70 of file kmime_dateformatter.cpp.
QString DateFormatter::dateString | ( | const QDateTime & | dtime, |
const QString & | lang = QString() , |
||
bool | shortFormat = true , |
||
bool | includeSecs = false |
||
) | const |
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. includeSecs if true, include the seconds field in the date string, only used if FormatType is Localized.
- Returns
- a QString containing the formatted date.
Definition at line 96 of file kmime_dateformatter.cpp.
|
protected |
Returns a QString containing the specified time_t t
formatted using the Fancy FormatType.
- Parameters
-
t is the time_t to use for formatting.
Definition at line 220 of file kmime_dateformatter.cpp.
DateFormatter::FormatType DateFormatter::format | ( | ) | const |
Returns the FormatType currently set.
- See also
- setFormat().
Definition at line 60 of file kmime_dateformatter.cpp.
|
static |
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. includeSecs if true, include the seconds field in the date string, only used if FormatType is Localized.
- Returns
- a QString containing the formatted date.
Definition at line 309 of file kmime_dateformatter.cpp.
|
static |
Convenience function dateString.
- Parameters
-
ftype is the FormatType to use. t is the time_t 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. includeSecs if true, include the seconds field in the date string, only used if FormatType is Localized.
- Returns
- a QString containing the formatted date.
Definition at line 298 of file kmime_dateformatter.cpp.
|
static |
Returns true if the current time is on daylight savings time; else false.
Definition at line 319 of file kmime_dateformatter.cpp.
|
protected |
Returns a QString containing the specified time_t t
in the "%Y-%m-%d %H:%M:%S" Iso FormatType.
- Parameters
-
t is the time_t to use for formatting.
Definition at line 286 of file kmime_dateformatter.cpp.
|
protected |
Returns a QString containing the specified time_t t
formatted using the Localized FormatType.
- Parameters
-
t is the time_t to use for formatting. shortFormat if true, create the short version of the date string. includeSecs if true, include the seconds field in the date string. lang is a QString containing the language to use.
Definition at line 261 of file kmime_dateformatter.cpp.
|
protected |
Converts QDateTime dt
to a time_t value.
- Parameters
-
dt is the QDateTime to be converted.
- Returns
- the time_t equivalent of the specified QDateTime.
Definition at line 207 of file kmime_dateformatter.cpp.
void DateFormatter::reset | ( | ) |
Resets the cached current date used for calculating the fancy date.
This should be called whenever the current date changed, i.e. on midnight.
- Deprecated:
- Can be safely removed. The date change is taken care of internally (as of 4.3).
Definition at line 293 of file kmime_dateformatter.cpp.
|
protected |
Returns a QString containing the specified time_t t
in the Rfc FormatType.
- Parameters
-
t is the time_t to use for formatting.
Definition at line 102 of file kmime_dateformatter.cpp.
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 135 of file kmime_dateformatter.cpp.
void DateFormatter::setFormat | ( | FormatType | ftype | ) |
Sets the date format to ftype
.
- Parameters
-
ftype is the FormatType.
- See also
- format().
Definition at line 65 of file kmime_dateformatter.cpp.
|
protected |
Returns a QString that identifies the timezone (eg.
"-0500") of the specified time_t t
.
- Parameters
-
t time to compute timezone from.
Definition at line 146 of file kmime_dateformatter.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.