• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KMIME Library

  • KMime
  • DateFormatter
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
KMime::DateFormatter Class Reference

#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

enum KMime::DateFormatter::FormatType

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 76 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 51 of file kmime_dateformatter.cpp.

DateFormatter::~DateFormatter ( )

Destroys the date formatter.

Definition at line 56 of file kmime_dateformatter.cpp.

Member Function Documentation

QString DateFormatter::cTime ( time_t  t) const
protected

Returns a QString containing the specified time_t t formatted with the ctime() function.

Parameters
tis the time_t to use for formatting.

Definition at line 281 of file kmime_dateformatter.cpp.

QString DateFormatter::custom ( time_t  t) const
protected

Returns a QString containing the specified time_t t formatted with a previously specified custom format.

Parameters
ttime 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
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.
includeSecsif 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
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.
includeSecsif 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.

QString DateFormatter::fancy ( time_t  t) const
protected

Returns a QString containing the specified time_t t formatted using the Fancy FormatType.

Parameters
tis 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.

QString DateFormatter::formatCurrentDate ( DateFormatter::FormatType  ftype,
const QString &  data = QString(),
bool  shortFormat = true,
bool  includeSecs = false 
)
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.
includeSecsif 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.

QString DateFormatter::formatDate ( DateFormatter::FormatType  ftype,
time_t  t,
const QString &  data = QString(),
bool  shortFormat = true,
bool  includeSecs = false 
)
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.
includeSecsif 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.

bool DateFormatter::isDaylight ( )
static

Returns true if the current time is on daylight savings time; else false.

Definition at line 319 of file kmime_dateformatter.cpp.

QString DateFormatter::isoDate ( time_t  t) const
protected

Returns a QString containing the specified time_t t in the "%Y-%m-%d %H:%M:%S" Iso FormatType.

Parameters
tis the time_t to use for formatting.

Definition at line 286 of file kmime_dateformatter.cpp.

QString DateFormatter::localized ( time_t  t,
bool  shortFormat = true,
bool  includeSecs = false,
const QString &  lang = QString() 
) const
protected

Returns a QString containing the specified time_t t formatted using the Localized FormatType.

Parameters
tis the time_t to use for formatting.
shortFormatif true, create the short version of the date string.
includeSecsif true, include the seconds field in the date string.
langis a QString containing the language to use.

Definition at line 261 of file kmime_dateformatter.cpp.

time_t DateFormatter::qdateToTimeT ( const QDateTime &  dt) const
protected

Converts QDateTime dt to a time_t value.

Parameters
dtis 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.

QString DateFormatter::rfc2822 ( time_t  t) const
protected

Returns a QString containing the specified time_t t in the Rfc FormatType.

Parameters
tis 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
formatis 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
ftypeis the FormatType.
See also
format().

Definition at line 65 of file kmime_dateformatter.cpp.

QByteArray DateFormatter::zone ( time_t  t) const
protected

Returns a QString that identifies the timezone (eg.

"-0500") of the specified time_t t.

Parameters
ttime to compute timezone from.

Definition at line 146 of file kmime_dateformatter.cpp.


The documentation for this class was generated from the following files:
  • kmime_dateformatter.h
  • kmime_dateformatter.cpp
This file is part of the KDE documentation.
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.

KMIME Library

Skip menu "KMIME Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal