summaryrefslogtreecommitdiff
path: root/library/timestring.h
Unidiff
Diffstat (limited to 'library/timestring.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/timestring.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/library/timestring.h b/library/timestring.h
index 0335715..875c8bf 100644
--- a/library/timestring.h
+++ b/library/timestring.h
@@ -1,140 +1,150 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef _TIMESTRING_H_ 21#ifndef _TIMESTRING_H_
22#define _TIMESTRING_H_ 22#define _TIMESTRING_H_
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25 25
26#if (QT_VERSION-0 >= 0x030000) 26#if (QT_VERSION-0 >= 0x030000)
27#define DateFormat QPEDateFormat 27#define DateFormat QPEDateFormat
28#endif 28#endif
29 29
30// return a string with the time based on whether or not you want 30// return a string with the time based on whether or not you want
31// you want it in 12 hour form. if ampm is true, then return 31// you want it in 12 hour form. if ampm is true, then return
32// it in 12 hour (am/pm) form otherwise return it in 24 hour form 32// it in 12 hour (am/pm) form otherwise return it in 24 hour form
33// in theory Qt 3,0 handles this better (hopefully obsoleteing this) 33// in theory Qt 3,0 handles this better (hopefully obsoleteing this)
34class DateFormat 34class DateFormat
35{ 35{
36public: 36public:
37 // date format type 001,010,100 = day month year 37 // date format type 001,010,100 = day month year
38 enum Order { 38 enum Order {
39 DayMonthYear = 0x0111, // 0x001 + 0x010(0x2 << 3) + 0x100(0x4 << 3) 39 DayMonthYear = 0x0111, // 0x001 + 0x010(0x2 << 3) + 0x100(0x4 << 3)
40 MonthDayYear = 0x010A, 40 MonthDayYear = 0x010A,
41 YearMonthDay = 0x0054 41 YearMonthDay = 0x0054
42 }; 42 };
43 43
44 DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so), 44 DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so),
45 _longOrder(so), _shortSeparator(s) { } 45 _longOrder(so), _shortSeparator(s) { }
46 DateFormat(QChar s, Order so, Order lo) : _shortOrder(so), 46 DateFormat(QChar s, Order so, Order lo) : _shortOrder(so),
47 _longOrder(lo), _shortSeparator(s) { } 47 _longOrder(lo), _shortSeparator(s) { }
48 DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder), 48 DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder),
49 _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { } 49 _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { }
50 50
51 bool operator==(const DateFormat &o) 51 bool operator==(const DateFormat &o)
52 { 52 {
53 if (o._shortOrder == _shortOrder && o._longOrder == _longOrder && 53 if (o._shortOrder == _shortOrder && o._longOrder == _longOrder &&
54 o._shortSeparator == _shortSeparator) 54 o._shortSeparator == _shortSeparator)
55 return TRUE; 55 return TRUE;
56 return FALSE; 56 return FALSE;
57 } 57 }
58 58
59 // verbosity specifiers 59 // verbosity specifiers
60 enum Verbosity { 60 enum Verbosity {
61 shortNumber = 0x01, // default 61 shortNumber = 0x01, // default
62 longNumber = 0x02, 62 longNumber = 0x02,
63 63
64 padNumber = 0x04, 64 padNumber = 0x04,
65 65
66 shortWord = 0x08, // default 66 shortWord = 0x08, // default
67 longWord = 0x10, 67 longWord = 0x10,
68 68
69 showWeekDay = 0x20 69 showWeekDay = 0x20
70 }; 70 };
71 71
72 QString toNumberString() const; // the M/D/Y string. 72 QString toNumberString() const; // the M/D/Y string.
73 QString toWordString() const; // the Month day, year string. 73 QString toWordString() const; // the Month day, year string.
74 74
75 QString numberDate(const QDate &d, int v = 0) const; 75 QString numberDate(const QDate &d, int v = 0) const;
76 QString wordDate(const QDate &d, int v = 0) const; 76 QString wordDate(const QDate &d, int v = 0) const;
77 77
78#ifndef QT_NO_DATASTREAM 78#ifndef QT_NO_DATASTREAM
79 void load(QDataStream&); 79 void load(QDataStream&);
80 void save(QDataStream&) const; 80 void save(QDataStream&) const;
81#endif 81#endif
82 82
83 QChar separator() const { return _shortSeparator; }; 83 QChar separator() const { return _shortSeparator; };
84 Order shortOrder() const { return _shortOrder; }; 84 Order shortOrder() const { return _shortOrder; };
85 Order longOrder() const { return _longOrder; }; 85 Order longOrder() const { return _longOrder; };
86 86
87private: 87private:
88 Order _shortOrder; 88 Order _shortOrder;
89 Order _longOrder; 89 Order _longOrder;
90 QChar _shortSeparator; 90 QChar _shortSeparator;
91}; 91};
92 92
93#ifndef QT_NO_DATASTREAM 93#ifndef QT_NO_DATASTREAM
94QDataStream &operator<<(QDataStream &s, const DateFormat&df); 94QDataStream &operator<<(QDataStream &s, const DateFormat&df);
95QDataStream &operator>>(QDataStream &s, DateFormat&df); 95QDataStream &operator>>(QDataStream &s, DateFormat&df);
96#endif 96#endif
97 97
98class TimeString 98class TimeString
99{ 99{
100public: 100public:
101 101
102 //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601, 102 //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601,
103 //YearMonthDay = ISO8601 }; 103 //YearMonthDay = ISO8601 };
104 104
105 105/**
106 * @name Convience functions which use currentDateFormat
107 */
108//@{
106 static QString shortDate( const QDate &d ) 109 static QString shortDate( const QDate &d )
107 { return shortDate( d, currentDateFormat() ); } 110 { return shortDate( d, currentDateFormat() ); }
108 static QString dateString( const QDate &d ) 111 static QString dateString( const QDate &d )
109 { return dateString( d, currentDateFormat() ); } 112 { return dateString( d, currentDateFormat() ); }
110 static QString longDateString( const QDate &d ) 113 static QString longDateString( const QDate &d )
111 { return longDateString( d, currentDateFormat() ); } 114 { return longDateString( d, currentDateFormat() ); }
115//@}
112 static QString dateString( const QDateTime &dt, bool ampm, bool seconds ) 116 static QString dateString( const QDateTime &dt, bool ampm, bool seconds )
113 { return dateString( dt, ampm, seconds, currentDateFormat() ); } 117 { return dateString( dt, ampm, seconds, currentDateFormat() ); }
114 118
119
120 /** @name Do not use as they don't honor system settings for AMPM
121 *
122 */
123 //@{
115 static QString dateString( const QDateTime &t, bool ampm = false ); 124 static QString dateString( const QDateTime &t, bool ampm = false );
116 static QString timeString( const QTime &t, bool ampm, bool seconds ); 125 static QString timeString( const QTime &t, bool ampm, bool seconds );
117 static QString timeString( const QTime &t, bool ampm = false ); 126 static QString timeString( const QTime &t, bool ampm = false );
118 static QString shortTime( bool ampm, bool seconds ); 127 static QString shortTime( bool ampm, bool seconds );
119 static QString shortTime( bool ampm = false ); 128 static QString shortTime( bool ampm = false );
129 //@}
120 130
121 static QString numberDateString( const QDate &d, DateFormat ); 131 static QString numberDateString( const QDate &d, DateFormat );
122 static QString numberDateString( const QDate &d ) 132 static QString numberDateString( const QDate &d )
123 { return numberDateString( d, currentDateFormat() ); } 133 { return numberDateString( d, currentDateFormat() ); }
124 static QString longNumberDateString( const QDate &d, DateFormat ); 134 static QString longNumberDateString( const QDate &d, DateFormat );
125 static QString longNumberDateString( const QDate &d ) 135 static QString longNumberDateString( const QDate &d )
126 { return longNumberDateString( d, currentDateFormat() ); } 136 { return longNumberDateString( d, currentDateFormat() ); }
127 137
128 static QString shortDate( const QDate &, DateFormat ); 138 static QString shortDate( const QDate &, DateFormat );
129 static QString dateString( const QDate &, DateFormat ); 139 static QString dateString( const QDate &, DateFormat );
130 static QString longDateString( const QDate &, DateFormat ); 140 static QString longDateString( const QDate &, DateFormat );
131 141
132 static DateFormat currentDateFormat(); 142 static DateFormat currentDateFormat();
133 143
134private: 144private:
135 static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat ); 145 static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat );
136 146
137 147
138}; 148};
139 149
140#endif 150#endif