KMime::DateFormatter

Search for usage in LXR

#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) const
 
QString dateString (const QDateTime &dtime, const QString &lang=QString(), bool shortFormat=true) const
 
FormatType format () 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, time_t 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"
  • 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 59 of file kmime_dateformatter.h.

Member Enumeration Documentation

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"

Iso 

iso "2002-03-31 02:08:35"

Rfc 

rfc "Sun, 31 Mar 2002 02:08:35 -0500"

Custom 

custom "whatever you like"

Definition at line 65 of file kmime_dateformatter.h.

Constructor & Destructor Documentation

DateFormatter::DateFormatter ( FormatType  ftype = DateFormatter::Fancy)
explicit

Constructs a date formatter with a default FormatType.

Parameters
ftypeis the default FormatType to use.

Definition at line 103 of file kmime_dateformatter.cpp.

DateFormatter::~DateFormatter ( )
default

Destroys the date formatter.

Member Function Documentation

QString DateFormatter::customFormat ( ) const

Returns the custom format string.

See also
setCustomFormat().

Definition at line 184 of file kmime_dateformatter.cpp.

QString DateFormatter::dateString ( time_t  t,
const QString lang = QString(),
bool  shortFormat = true 
) const

Constructs a formatted date string from time_t t.

Parameters
tis the time_t to use for formatting.
langis the language, only used if FormatType is Localized.
shortFormatif 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 121 of file kmime_dateformatter.cpp.

QString DateFormatter::dateString ( const QDateTime dtime,
const QString lang = QString(),
bool  shortFormat = true 
) const

Constructs a formatted date string from QDateTime dtime.

Parameters
dtimeis the QDateTime to use for formatting.
langis the language, only used if FormatType is Localized.
shortFormatif 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 140 of file kmime_dateformatter.cpp.

DateFormatter::FormatType DateFormatter::format ( ) const

Returns the FormatType currently set.

See also
setFormat().

Definition at line 111 of file kmime_dateformatter.cpp.

QString DateFormatter::formatCurrentDate ( DateFormatter::FormatType  ftype,
const QString data = QString(),
bool  shortFormat = true 
)
static

Convenience function, same as formatDate() but returns the current time formatted.

Parameters
ftypeis the FormatType to use.
datais either the format when FormatType is Custom, or language when FormatType is Localized.
shortFormatif 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 323 of file kmime_dateformatter.cpp.

QString DateFormatter::formatDate ( DateFormatter::FormatType  ftype,
time_t  t,
const QString data = QString(),
bool  shortFormat = true 
)
static

Convenience function dateString.

Parameters
ftypeis the FormatType to use.
tis the time_t to use for formatting.
datais either the format when FormatType is Custom, or language when FormatType is Localized.
shortFormatif 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 313 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
formatis a QString containing the custom format.
See also
QDateTime::toString(), customFormat().

Definition at line 178 of file kmime_dateformatter.cpp.

void DateFormatter::setFormat ( FormatType  ftype)

Sets the date format to ftype.

Parameters
ftypeis the FormatType.
See also
format().

Definition at line 116 of file kmime_dateformatter.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Oct 24 2021 23:13:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.