KMIME Library
kmime_dateformatter.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00047 #ifndef __KMIME_DATEFORMATTER_H__
00048 #define __KMIME_DATEFORMATTER_H__
00049
00050 #include <time.h>
00051 #include <QtCore/QDateTime>
00052 #include <QtCore/QString>
00053 #include "kmime_export.h"
00054
00055 namespace KMime {
00056
00070 class KMIME_EXPORT DateFormatter
00071 {
00072 public:
00076 enum FormatType {
00077 CTime,
00078 Localized,
00079 Fancy,
00080 Iso,
00081 Rfc,
00082 Custom
00083 };
00084
00090 explicit DateFormatter( FormatType ftype=DateFormatter::Fancy );
00091
00095 ~DateFormatter();
00096
00102 FormatType format() const;
00103
00111 void setFormat( FormatType ftype );
00112
00125 QString dateString( time_t t, const QString &lang=QString(),
00126 bool shortFormat=true, bool includeSecs=false ) const;
00127
00140 QString dateString( const QDateTime &dtime, const QString &lang=QString(),
00141 bool shortFormat=true, bool includeSecs=false ) const;
00142
00153 void setCustomFormat( const QString &format );
00154
00160 QString customFormat() const;
00161
00165 void reset();
00166
00167
00182 static QString formatDate( DateFormatter::FormatType ftype, time_t t,
00183 const QString &data=QString(),
00184 bool shortFormat=true,
00185 bool includeSecs=false );
00186
00201 static QString formatCurrentDate( DateFormatter::FormatType ftype,
00202 const QString &data=QString(),
00203 bool shortFormat=true,
00204 bool includeSecs=false );
00205
00209 static bool isDaylight();
00210
00211 protected:
00218 QString fancy( time_t t ) const ;
00219
00229 QString localized( time_t t, bool shortFormat=true,
00230 bool includeSecs=false,
00231 const QString &lang=QString() ) const;
00232
00239 QString cTime( time_t t ) const;
00240
00247 QString isoDate( time_t t ) const;
00248
00255 QString rfc2822( time_t t ) const;
00256
00263 QString custom( time_t t ) const;
00264
00271 QByteArray zone( time_t t ) const;
00272
00279 time_t qdateToTimeT( const QDateTime &dt ) const;
00280
00281 private:
00282
00283 FormatType mFormat;
00284 mutable time_t mCurrentTime;
00285 mutable QDateTime mDate;
00286 QString mCustomFormat;
00287 static int mDaylight;
00288
00289 };
00290
00291 }
00292
00293 #endif