author | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
commit | 6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4 (patch) (unidiff) | |
tree | 6ebc93c6432f4ed9d00ef1448b6a047ef522a79a /library/timestring.cpp | |
parent | d10cddb3c9ce75bc90b14add14bc133737fe35aa (diff) | |
download | opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.zip opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.gz opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.bz2 |
Qtopia1-6 merge
still to test
bic changes to be resolved
more changes to be made?
-rw-r--r-- | library/timestring.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/library/timestring.cpp b/library/timestring.cpp index d5d78ae..4c6fa72 100644 --- a/library/timestring.cpp +++ b/library/timestring.cpp | |||
@@ -1,52 +1,52 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of 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 | #include "timestring.h" | 21 | #include "timestring.h" |
22 | #include <qobject.h> | 22 | #include <qobject.h> |
23 | #include "qpeapplication.h" //for qApp | 23 | #include "qpeapplication.h" //for qApp |
24 | #include "config.h" | 24 | #include "config.h" |
25 | 25 | ||
26 | 26 | ||
27 | class TimeStringFormatKeeper : public QObject | 27 | class TimeStringFormatKeeper : public QObject |
28 | { | 28 | { |
29 | Q_OBJECT | 29 | Q_OBJECT |
30 | public: | 30 | public: |
31 | static DateFormat currentFormat() | 31 | static DateFormat currentFormat() |
32 | { | 32 | { |
33 | if ( !self ) | 33 | if ( !self ) |
34 | self = new TimeStringFormatKeeper; | 34 | self = new TimeStringFormatKeeper; |
35 | return self->format; | 35 | return self->format; |
36 | } | 36 | } |
37 | private slots: | 37 | private slots: |
38 | void formatChanged( DateFormat f ) | 38 | void formatChanged( DateFormat f ) |
39 | { | 39 | { |
40 | format = f; | 40 | format = f; |
41 | } | 41 | } |
42 | private: | 42 | private: |
43 | static TimeStringFormatKeeper *self; | 43 | static TimeStringFormatKeeper *self; |
44 | DateFormat format; | 44 | DateFormat format; |
45 | 45 | ||
46 | TimeStringFormatKeeper() | 46 | TimeStringFormatKeeper() |
47 | : QObject( qApp ) | 47 | : QObject( qApp ) |
48 | { | 48 | { |
49 | Config config("qpe"); | 49 | Config config("qpe"); |
50 | config.setGroup( "Date" ); | 50 | config.setGroup( "Date" ); |
51 | format = DateFormat(QChar(config.readEntry("Separator", "/")[0]), | 51 | format = DateFormat(QChar(config.readEntry("Separator", "/")[0]), |
52 | (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), | 52 | (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), |
@@ -72,158 +72,154 @@ QString DateFormat::toNumberString() const | |||
72 | case 0x0002: | 72 | case 0x0002: |
73 | buf += QObject::tr( "M" ); | 73 | buf += QObject::tr( "M" ); |
74 | break; | 74 | break; |
75 | case 0x0004: | 75 | case 0x0004: |
76 | buf += QObject::tr( "Y" ); | 76 | buf += QObject::tr( "Y" ); |
77 | break; | 77 | break; |
78 | } | 78 | } |
79 | if (i < 2) | 79 | if (i < 2) |
80 | buf += _shortSeparator; | 80 | buf += _shortSeparator; |
81 | } | 81 | } |
82 | return buf; | 82 | return buf; |
83 | } | 83 | } |
84 | 84 | ||
85 | QString DateFormat::toWordString() const | 85 | QString DateFormat::toWordString() const |
86 | { | 86 | { |
87 | QString buf = ""; | 87 | QString buf = ""; |
88 | // for each part of the order | 88 | // for each part of the order |
89 | for (int i = 0; i < 3; i++) { | 89 | for (int i = 0; i < 3; i++) { |
90 | // switch on the relavent 3 bits. | 90 | // switch on the relavent 3 bits. |
91 | switch((_longOrder >> (i * 3)) & 0x0007) { | 91 | switch((_longOrder >> (i * 3)) & 0x0007) { |
92 | case 0x0001: | 92 | case 0x0001: |
93 | buf += QObject::tr( "day" ); | 93 | buf += QObject::tr( "day" ); |
94 | if (i < 2) { | 94 | if (i < 2) { |
95 | if ((_shortOrder << ((i+1) * 3)) & 0x0007) | 95 | if ((_shortOrder << ((i+1) * 3)) & 0x0007) |
96 | buf += ", "; | 96 | buf += ", "; |
97 | else | 97 | else |
98 | buf += " "; | 98 | buf += " "; |
99 | } | 99 | } |
100 | break; | 100 | break; |
101 | case 0x0002: | 101 | case 0x0002: |
102 | buf += QObject::tr( "month" ); | 102 | buf += QObject::tr( "month" ); |
103 | if (i < 2) | 103 | if (i < 2) |
104 | buf += " "; | 104 | buf += " "; |
105 | break; | 105 | break; |
106 | case 0x0004: | 106 | case 0x0004: |
107 | buf += QObject::tr( "year" ); | 107 | buf += QObject::tr( "year" ); |
108 | if (i < 2) | 108 | if (i < 2) |
109 | buf += ", "; | 109 | buf += ", "; |
110 | break; | 110 | break; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | return buf; | 113 | return buf; |
114 | } | 114 | } |
115 | 115 | ||
116 | QString DateFormat::numberDate(const QDate &d, int v) const | 116 | QString DateFormat::numberDate(const QDate &d, int v) const |
117 | { | 117 | { |
118 | QString buf = ""; | 118 | QString buf = ""; |
119 | 119 | ||
120 | int pad = 0; | 120 | int pad = 2; |
121 | if (v & padNumber) | ||
122 | pad = 2; | ||
123 | 121 | ||
124 | // for each part of the order | 122 | // for each part of the order |
125 | for (int i = 0; i < 3; i++) { | 123 | for (int i = 0; i < 3; i++) { |
126 | // switch on the relavent 3 bits. | 124 | // switch on the relavent 3 bits. |
127 | switch((_shortOrder >> (i * 3)) & 0x0007) { | 125 | switch((_shortOrder >> (i * 3)) & 0x0007) { |
128 | case 0x0001: | 126 | case 0x0001: |
129 | buf += QString("%1").arg(d.day(), pad); | 127 | if (pad==2) buf += QString().sprintf("%02d",d.day()); |
128 | else buf += QString().sprintf("%d",d.day()); | ||
130 | break; | 129 | break; |
131 | case 0x0002: | 130 | case 0x0002: |
132 | buf += QString("%1").arg(d.month(), pad); | 131 | if (i==0) { // no padding with only MM/DD/YY format |
132 | pad=0; | ||
133 | } | ||
134 | if (pad==2) buf += QString().sprintf("%02d",d.month()); | ||
135 | else buf += QString().sprintf("%d",d.month()); | ||
133 | break; | 136 | break; |
134 | case 0x0004: | 137 | case 0x0004: |
135 | { | 138 | { |
136 | int year = d.year(); | 139 | int year = d.year(); |
137 | if (!(v & longNumber)) | 140 | if (!(v & longNumber)) |
138 | year = year % 100; | 141 | year = year % 100; |
139 | 142 | buf += QString().sprintf("%02d",year); | |
140 | if (year < 10) | ||
141 | buf += "0"; | ||
142 | |||
143 | buf += QString::number(year); | ||
144 | |||
145 | } | 143 | } |
146 | break; | 144 | break; |
147 | } | 145 | } |
148 | if (i < 2) | 146 | if (i < 2) |
149 | buf = _shortSeparator; | 147 | buf += _shortSeparator; |
150 | } | 148 | } |
151 | return buf; | 149 | return buf; |
152 | } | 150 | } |
153 | 151 | ||
154 | QString DateFormat::wordDate(const QDate &d, int v) const | 152 | QString DateFormat::wordDate(const QDate &d, int v) const |
155 | { | 153 | { |
156 | QString buf = ""; | 154 | QString buf = ""; |
157 | // for each part of the order | 155 | // for each part of the order |
158 | if (v & showWeekDay) { | 156 | if (v & showWeekDay) { |
159 | QString weekDay = d.dayName(d.dayOfWeek()); | 157 | QString weekDay = d.dayName(d.dayOfWeek()); |
160 | if (!(v & longWord)) { | 158 | if (!(v & longWord)) { |
161 | weekDay = weekDay.left(3); | 159 | weekDay = weekDay.left(3); |
162 | } | 160 | } |
163 | buf += weekDay; | 161 | buf += weekDay; |
164 | if (_longOrder & 0x0007 == 0x0002) | 162 | if ((_longOrder & 0x0007) == 0x0002) |
165 | buf += ' '; | 163 | buf += ' '; |
166 | else | 164 | else |
167 | buf += ", "; | 165 | buf += ", "; |
168 | } | 166 | } |
169 | 167 | ||
170 | int pad = 0; | ||
171 | if (v & padNumber) | ||
172 | pad = 2; | ||
173 | |||
174 | for (int i = 0; i < 3; i++) { | 168 | for (int i = 0; i < 3; i++) { |
175 | // switch on the relavent 3 bits. | 169 | // switch on the relavent 3 bits. |
176 | switch((_longOrder >> (i * 3)) & 0x0007) { | 170 | switch((_longOrder >> (i * 3)) & 0x0007) { |
177 | case 0x0001: | 171 | case 0x0001: |
178 | buf += QString("%1").arg(d.day(), pad); | 172 | if (i==1) { |
179 | if (i < 2) { | 173 | buf += QString().sprintf("%02d, ",d.day()); |
180 | if ((_shortOrder << ((i+1) * 3)) & 0x0007) | 174 | } else { |
181 | buf += ", "; | 175 | buf += QString().sprintf("%2d",d.day()); |
176 | if (separator()=='.') // 2002/1/11 | ||
177 | buf += ". "; | ||
182 | else | 178 | else |
183 | buf += " "; | 179 | buf += " "; |
184 | } | 180 | } |
185 | break; | 181 | break; |
186 | case 0x0002: | 182 | case 0x0002: |
187 | { | 183 | { |
188 | QString monthName = d.monthName(d.month()); | 184 | QString monthName = d.monthName(d.month()); |
189 | if (!(v & longWord)) { | 185 | if (!(v & longWord)) { |
190 | monthName = monthName.left(3); | 186 | monthName = monthName.left(3); |
191 | } | 187 | } |
192 | buf += monthName; | 188 | buf += monthName; |
193 | } | 189 | } |
194 | if (i < 2) | 190 | if (i < 2) |
195 | buf += " "; | 191 | buf += " "; |
196 | break; | 192 | break; |
197 | case 0x0004: | 193 | case 0x0004: |
198 | { | 194 | { |
199 | int year = d.year(); | 195 | int year = d.year(); |
200 | if (!(v & longNumber)) | 196 | if (!(v & longNumber)) |
201 | year = year % 100; | 197 | year = year % 100; |
202 | 198 | ||
203 | if (year < 10) | 199 | if (year < 10) |
204 | buf += "0"; | 200 | buf += "0"; |
205 | 201 | ||
206 | buf += QString::number(year); | 202 | buf += QString::number(year); |
207 | } | 203 | } |
208 | if (i < 2) | 204 | if (i < 2) |
209 | buf += ", "; | 205 | buf += ", "; |
210 | break; | 206 | break; |
211 | } | 207 | } |
212 | } | 208 | } |
213 | return buf; | 209 | return buf; |
214 | } | 210 | } |
215 | 211 | ||
216 | #ifndef QT_NO_DATASTREAM | 212 | #ifndef QT_NO_DATASTREAM |
217 | void DateFormat::save(QDataStream &d) const | 213 | void DateFormat::save(QDataStream &d) const |
218 | { | 214 | { |
219 | d << _shortSeparator.unicode(); | 215 | d << _shortSeparator.unicode(); |
220 | uint v= _shortOrder; | 216 | uint v= _shortOrder; |
221 | d << v; | 217 | d << v; |
222 | v = _longOrder; | 218 | v = _longOrder; |
223 | d << v; | 219 | d << v; |
224 | } | 220 | } |
225 | 221 | ||
226 | void DateFormat::load(QDataStream &d) | 222 | void DateFormat::load(QDataStream &d) |
227 | { | 223 | { |
228 | ushort value; | 224 | ushort value; |
229 | d >> value; | 225 | d >> value; |
@@ -312,49 +308,58 @@ QString TimeString::timeString( const QTime &t, bool ampm, bool seconds ) | |||
312 | if ( t.minute() < 10 ) | 308 | if ( t.minute() < 10 ) |
313 | strMin.prepend( "0" ); | 309 | strMin.prepend( "0" ); |
314 | if ( t.second() < 10 ) | 310 | if ( t.second() < 10 ) |
315 | strSec.prepend( "0" ); | 311 | strSec.prepend( "0" ); |
316 | argString = argString.arg( strMin ); | 312 | argString = argString.arg( strMin ); |
317 | if ( seconds ) | 313 | if ( seconds ) |
318 | argString = argString.arg( strSec ); | 314 | argString = argString.arg( strSec ); |
319 | if ( hour >= 12 ) | 315 | if ( hour >= 12 ) |
320 | argString = argString.arg( QObject::tr("PM") ); | 316 | argString = argString.arg( QObject::tr("PM") ); |
321 | else | 317 | else |
322 | argString = argString.arg( QObject::tr("AM") ); | 318 | argString = argString.arg( QObject::tr("AM") ); |
323 | return argString; | 319 | return argString; |
324 | } | 320 | } |
325 | 321 | ||
326 | QString TimeString::shortTime( bool ampm, bool seconds ) | 322 | QString TimeString::shortTime( bool ampm, bool seconds ) |
327 | { | 323 | { |
328 | static const char* const day[] = { | 324 | static const char* const day[] = { |
329 | QT_TRANSLATE_NOOP( "QObject", "Mon" ), | 325 | QT_TRANSLATE_NOOP( "QObject", "Mon" ), |
330 | QT_TRANSLATE_NOOP( "QObject", "Tue" ), | 326 | QT_TRANSLATE_NOOP( "QObject", "Tue" ), |
331 | QT_TRANSLATE_NOOP( "QObject", "Wed" ), | 327 | QT_TRANSLATE_NOOP( "QObject", "Wed" ), |
332 | QT_TRANSLATE_NOOP( "QObject", "Thu" ), | 328 | QT_TRANSLATE_NOOP( "QObject", "Thu" ), |
333 | QT_TRANSLATE_NOOP( "QObject", "Fri" ), | 329 | QT_TRANSLATE_NOOP( "QObject", "Fri" ), |
334 | QT_TRANSLATE_NOOP( "QObject", "Sat" ), | 330 | QT_TRANSLATE_NOOP( "QObject", "Sat" ), |
335 | QT_TRANSLATE_NOOP( "QObject", "Sun" ) | 331 | QT_TRANSLATE_NOOP( "QObject", "Sun" ) |
336 | }; | 332 | }; |
337 | // just create a shorter time String | 333 | // just create a shorter time String |
338 | QDateTime dtTmp = QDateTime::currentDateTime(); | 334 | QDateTime dtTmp = QDateTime::currentDateTime(); |
339 | QString strTime; | 335 | QString strTime; |
340 | strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " + | 336 | strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " + |
341 | timeString( dtTmp.time(), ampm, seconds ); | 337 | timeString( dtTmp.time(), ampm, seconds ); |
342 | return strTime; | 338 | return strTime; |
343 | } | 339 | } |
344 | 340 | ||
345 | QString TimeString::dateString( const QDateTime &t, bool ampm ) | 341 | QString TimeString::dateString( const QDateTime &t, bool ampm ) |
346 | { | 342 | { |
347 | return dateString(t,ampm,FALSE); | 343 | return dateString(t,ampm,FALSE); |
348 | } | 344 | } |
349 | 345 | ||
350 | QString TimeString::timeString( const QTime &t, bool ampm) | 346 | QString TimeString::timeString( const QTime &t, bool ampm) |
351 | { | 347 | { |
352 | return timeString(t,ampm,FALSE); | 348 | return timeString(t,ampm,FALSE); |
353 | } | 349 | } |
354 | 350 | ||
355 | QString TimeString::shortTime( bool ampm ) | 351 | QString TimeString::shortTime( bool ampm ) |
356 | { | 352 | { |
357 | return shortTime(ampm,FALSE); | 353 | return shortTime(ampm,FALSE); |
358 | } | 354 | } |
359 | 355 | ||
356 | QString TimeString::numberDateString( const QDate &d, DateFormat dtf ) | ||
357 | { | ||
358 | return dtf.numberDate(d); | ||
359 | } | ||
360 | QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf ) | ||
361 | { | ||
362 | return dtf.numberDate(d,DateFormat::longNumber); | ||
363 | } | ||
364 | |||
360 | #include "timestring.moc" | 365 | #include "timestring.moc" |