KMime

kmime_dateformatter.h
Go to the documentation of this file.
1/* -*- c++ -*-
2 kmime_dateformatter.h
3
4 KMime, the KDE Internet mail/usenet news message library.
5 SPDX-FileCopyrightText: 2001 the KMime authors.
6 See file AUTHORS for details
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10/**
11 @file
12 This file is part of the API for handling @ref MIME data and
13 defines the DateFormatter class.
14
15 @brief
16 Defines the DateFormatter class.
17
18 @authors the KMime authors (see AUTHORS file)
19
20 @glossary @anchor RFC2822 @anchor rfc2822 @b RFC @b 2822:
21 RFC that defines the <a href="https://tools.ietf.org/html/rfc2822">
22 Internet Message Format</a>.
23
24 @glossary @anchor ISO8601 @anchor iso8601 @b ISO @b 8601:
25 International Standards Organization (ISO) standard that defines the
26 <a href="https://en.wikipedia.org/wiki/ISO_8601">
27 international standard for date and time representations</a>.
28
29 @glossary @anchor ctime @b ctime:
30 a Unix library call which returns the local time as a human readable
31 ASCII string of the form "Sun Mar 31 02:08:35 2002".
32*/
33
34#pragma once
35
36#include "kmime_export.h"
37#include <QDateTime>
38#include <QString>
39#include <memory>
40
41namespace KMime
42{
43class DateFormatterPrivate;
44
45/**
46 @brief
47 A class for abstracting date formatting.
48
49 This class deals with different kinds of date display formats.
50 The formats supported include:
51 - @b fancy "Today 02:08:35"
52 - @b ctime as with the @ref ctime function, eg. "Sun Mar 31 02:08:35 2002"
53 - @b localized according to the control center setting, eg. "2002-03-31 02:08"
54 - @b custom "whatever you like"
55*/
56class KMIME_EXPORT DateFormatter
57{
58public:
59 /**
60 The different types of date formats.
61 */
63 CTime, /**< ctime "Sun Mar 31 02:08:35 2002" */
64 Localized, /**< localized "2002-03-31 02:08" */
65 Fancy, /**< fancy "Today 02:08:35" */
66 Custom /**< custom "whatever you like" */
67 };
68
69 /**
70 Constructs a date formatter with a default #FormatType.
71
72 @param ftype is the default #FormatType to use.
73 */
74 explicit DateFormatter(FormatType ftype = DateFormatter::Fancy);
75
76 /**
77 Destroys the date formatter.
78 */
80
81 /**
82 Returns the #FormatType currently set.
83
84 @see setFormat().
85 */
86 [[nodiscard]] FormatType format() const;
87
88 /**
89 Sets the date format to @p ftype.
90
91 @param ftype is the #FormatType.
92
93 @see format().
94 */
95 void setFormat(FormatType ftype);
96
97 /**
98 Constructs a formatted date string from QDateTime @p dtime.
99
100 @param dtime is the QDateTime to use for formatting.
101 @param lang is the language, only used if #FormatType is #Localized.
102 @param shortFormat if true, create the short version of the date string,
103 only used if #FormatType is #Localized.
104
105 @return a QString containing the formatted date.
106 */
107 [[nodiscard]] QString dateString(const QDateTime &dtime,
108 const QString &lang = QString(),
109 bool shortFormat = true) const;
110
111 /**
112 Sets the custom format for date to string conversions to @p format.
113 This method accepts the same arguments as QDateTime::toString(), but
114 also supports the "Z" expression which is substituted with the
115 @ref RFC2822 (Section 3.3) style numeric timezone (-0500).
116
117 @param format is a QString containing the custom format.
118
119 @see QDateTime::toString(), customFormat().
120 */
121 void setCustomFormat(const QString &format);
122
123 /**
124 Returns the custom format string.
125
126 @see setCustomFormat().
127 */
128 [[nodiscard]] QString customFormat() const;
129
130 //static methods
131 /**
132 Convenience function dateString
133
134 @param ftype is the #FormatType to use.
135 @param t is the time to use for formatting.
136 @param data is either the format when #FormatType is Custom,
137 or language when #FormatType is #Localized.
138 @param shortFormat if true, create the short version of the date string,
139 only used if #FormatType is #Localized.
140
141 @return a QString containing the formatted date.
142 */
143 [[nodiscard]] static QString formatDate(DateFormatter::FormatType ftype,
144 const QDateTime &t,
145 const QString &data = QString(),
146 bool shortFormat = true);
147
148 /**
149 Convenience function, same as formatDate() but returns the current time
150 formatted.
151
152 @param ftype is the #FormatType to use.
153 @param data is either the format when #FormatType is Custom,
154 or language when #FormatType is #Localized.
155 @param shortFormat if true, create the short version of the date string,
156 only used if #FormatType is #Localized.
157
158 @return a QString containing the formatted date.
159 */
160 [[nodiscard]] static QString
161 formatCurrentDate(DateFormatter::FormatType ftype,
162 const QString &data = QString(), bool shortFormat = true);
163
164 private:
165 //@cond PRIVATE
166 Q_DISABLE_COPY(DateFormatter)
167 std::unique_ptr<DateFormatterPrivate> const d;
168 //@endcond
169};
170
171} // namespace KMime
172
A class for abstracting date formatting.
FormatType
The different types of date formats.
@ Localized
localized "2002-03-31 02:08"
@ CTime
ctime "Sun Mar 31 02:08:35 2002"
@ Fancy
fancy "Today 02:08:35"
~DateFormatter()
Destroys the date formatter.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.