author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /library/timestring.h | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
-rw-r--r-- | library/timestring.h | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/library/timestring.h b/library/timestring.h new file mode 100644 index 0000000..fd06d5b --- a/dev/null +++ b/library/timestring.h | |||
@@ -0,0 +1,131 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #ifndef _TIMESTRING_H_ | ||
22 | #define _TIMESTRING_H_ | ||
23 | #include <qdatetime.h> | ||
24 | #include <qstring.h> | ||
25 | |||
26 | // return a string with the time based on whether or not you want | ||
27 | // you want it in 12 hour form. if ampm is true, then return | ||
28 | // it in 12 hour (am/pm) form otherwise return it in 24 hour form | ||
29 | // in theory Qt 3,0 handles this better (hopefully obsoleteing this) | ||
30 | class DateFormat | ||
31 | { | ||
32 | public: | ||
33 | // date format type 001,010,100 = day month year | ||
34 | enum Order { | ||
35 | DayMonthYear = 0x0111, // 0x001 + 0x010(0x2 << 3) + 0x100(0x4 << 3) | ||
36 | MonthDayYear = 0x010A, | ||
37 | YearMonthDay = 0x0054 | ||
38 | }; | ||
39 | |||
40 | DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so), | ||
41 | _longOrder(so), _shortSeparator(s) { } | ||
42 | DateFormat(QChar s, Order so, Order lo) : _shortOrder(so), | ||
43 | _longOrder(lo), _shortSeparator(s) { } | ||
44 | DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder), | ||
45 | _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { } | ||
46 | |||
47 | bool operator==(const DateFormat &o) | ||
48 | { | ||
49 | if (o._shortOrder == _shortOrder && o._longOrder == _longOrder && | ||
50 | o._shortSeparator == _shortSeparator) | ||
51 | return TRUE; | ||
52 | return FALSE; | ||
53 | } | ||
54 | |||
55 | // verbosity specifiers | ||
56 | enum Verbosity { | ||
57 | shortNumber = 0x01, // default | ||
58 | longNumber = 0x02, | ||
59 | |||
60 | padNumber = 0x04, | ||
61 | |||
62 | shortWord = 0x08, // default | ||
63 | longWord = 0x10, | ||
64 | |||
65 | showWeekDay = 0x20 | ||
66 | }; | ||
67 | |||
68 | QString toNumberString() const; // the M/D/Y string. | ||
69 | QString toWordString() const; // the Month day, year string. | ||
70 | |||
71 | QString numberDate(const QDate &d, int v = 0) const; | ||
72 | QString wordDate(const QDate &d, int v = 0) const; | ||
73 | |||
74 | #ifndef QT_NO_DATASTREAM | ||
75 | void load(QDataStream&); | ||
76 | void save(QDataStream&) const; | ||
77 | #endif | ||
78 | |||
79 | QChar separator() const { return _shortSeparator; }; | ||
80 | Order shortOrder() const { return _shortOrder; }; | ||
81 | Order longOrder() const { return _longOrder; }; | ||
82 | |||
83 | private: | ||
84 | Order _shortOrder; | ||
85 | Order _longOrder; | ||
86 | QChar _shortSeparator; | ||
87 | }; | ||
88 | |||
89 | #ifndef QT_NO_DATASTREAM | ||
90 | QDataStream &operator<<(QDataStream &s, const DateFormat&df); | ||
91 | QDataStream &operator>>(QDataStream &s, DateFormat&df); | ||
92 | #endif | ||
93 | |||
94 | class TimeString | ||
95 | { | ||
96 | public: | ||
97 | |||
98 | //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601, | ||
99 | //YearMonthDay = ISO8601 }; | ||
100 | |||
101 | |||
102 | static QString shortDate( const QDate &d ) | ||
103 | { return shortDate( d, currentDateFormat() ); } | ||
104 | static QString dateString( const QDate &d ) | ||
105 | { return dateString( d, currentDateFormat() ); } | ||
106 | static QString longDateString( const QDate &d ) | ||
107 | { return longDateString( d, currentDateFormat() ); } | ||
108 | static QString dateString( const QDateTime &dt, bool ampm, bool seconds ) | ||
109 | { return dateString( dt, ampm, seconds, currentDateFormat() ); } | ||
110 | |||
111 | static QString dateString( const QDateTime &t, bool ampm = false ); | ||
112 | static QString timeString( const QTime &t, bool ampm, bool seconds ); | ||
113 | static QString timeString( const QTime &t, bool ampm = false ); | ||
114 | static QString shortTime( bool ampm, bool seconds ); | ||
115 | static QString shortTime( bool ampm = false ); | ||
116 | |||
117 | |||
118 | |||
119 | static QString shortDate( const QDate &, DateFormat ); | ||
120 | static QString dateString( const QDate &, DateFormat ); | ||
121 | static QString longDateString( const QDate &, DateFormat ); | ||
122 | |||
123 | static DateFormat currentDateFormat(); | ||
124 | |||
125 | private: | ||
126 | static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat ); | ||
127 | |||
128 | |||
129 | }; | ||
130 | #endif | ||
131 | |||