00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _TIMESTRING_H_
00022 #define _TIMESTRING_H_
00023 #include <qdatetime.h>
00024 #include <qstring.h>
00025
00026 #if (QT_VERSION-0 >= 0x030000)
00027 #define DateFormat QPEDateFormat
00028 #endif
00029
00030
00031
00032
00033
00034 class DateFormat
00035 {
00036 public:
00037
00038 enum Order {
00039 DayMonthYear = 0x0111,
00040 MonthDayYear = 0x010A,
00041 YearMonthDay = 0x0054
00042 };
00043
00044 DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so),
00045 _longOrder(so), _shortSeparator(s) { }
00046 DateFormat(QChar s, Order so, Order lo) : _shortOrder(so),
00047 _longOrder(lo), _shortSeparator(s) { }
00048 DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder),
00049 _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { }
00050
00051 bool operator==(const DateFormat &o)
00052 {
00053 if (o._shortOrder == _shortOrder && o._longOrder == _longOrder &&
00054 o._shortSeparator == _shortSeparator)
00055 return TRUE;
00056 return FALSE;
00057 }
00058
00059
00060 enum Verbosity {
00061 shortNumber = 0x01,
00062 longNumber = 0x02,
00063
00064 padNumber = 0x04,
00065
00066 shortWord = 0x08,
00067 longWord = 0x10,
00068
00069 showWeekDay = 0x20
00070 };
00071
00072 QString toNumberString() const;
00073 QString toWordString() const;
00074
00075 QString numberDate(const QDate &d, int v = 0) const;
00076 QString wordDate(const QDate &d, int v = 0) const;
00077
00078 #ifndef QT_NO_DATASTREAM
00079 void load(QDataStream&);
00080 void save(QDataStream&) const;
00081 #endif
00082
00083 QChar separator() const { return _shortSeparator; };
00084 Order shortOrder() const { return _shortOrder; };
00085 Order longOrder() const { return _longOrder; };
00086
00087 private:
00088 Order _shortOrder;
00089 Order _longOrder;
00090 QChar _shortSeparator;
00091 };
00092
00093 #ifndef QT_NO_DATASTREAM
00094 QDataStream &operator<<(QDataStream &s, const DateFormat&df);
00095 QDataStream &operator>>(QDataStream &s, DateFormat&df);
00096 #endif
00097
00098 class TimeString
00099 {
00100 public:
00101
00102
00103
00104
00109 static QString shortDate( const QDate &d )
00110 { return shortDate( d, currentDateFormat() ); }
00111 static QString dateString( const QDate &d )
00112 { return dateString( d, currentDateFormat() ); }
00113 static QString longDateString( const QDate &d )
00114 { return longDateString( d, currentDateFormat() ); }
00116 static QString dateString( const QDateTime &dt, bool ampm, bool seconds )
00117 { return dateString( dt, ampm, seconds, currentDateFormat() ); }
00118
00119
00124 static QString dateString( const QDateTime &t, bool ampm = false );
00125 static QString timeString( const QTime &t, bool ampm, bool seconds );
00126 static QString timeString( const QTime &t, bool ampm = false );
00127 static QString shortTime( bool ampm, bool seconds );
00128 static QString shortTime( bool ampm = false );
00130
00131 static QString numberDateString( const QDate &d, DateFormat );
00132 static QString numberDateString( const QDate &d )
00133 { return numberDateString( d, currentDateFormat() ); }
00134 static QString longNumberDateString( const QDate &d, DateFormat );
00135 static QString longNumberDateString( const QDate &d )
00136 { return longNumberDateString( d, currentDateFormat() ); }
00137
00138 static QString shortDate( const QDate &, DateFormat );
00139 static QString dateString( const QDate &, DateFormat );
00140 static QString longDateString( const QDate &, DateFormat );
00141
00142 static DateFormat currentDateFormat();
00143
00144 private:
00145 static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat );
00146
00147
00148 };
00149
00150 #endif