author | zautrix <zautrix> | 2004-10-22 22:10:16 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-22 22:10:16 (UTC) |
commit | b8da6435b8e5941eb1824873e68d8a6a728fae5e (patch) (unidiff) | |
tree | bc5ed11961e89bcd606f6fbca32185dbf8afab7a /microkde | |
parent | a5274f27dc71e1a0ffae73f32f84f4dd013b4b76 (diff) | |
download | kdepimpi-b8da6435b8e5941eb1824873e68d8a6a728fae5e.zip kdepimpi-b8da6435b8e5941eb1824873e68d8a6a728fae5e.tar.gz kdepimpi-b8da6435b8e5941eb1824873e68d8a6a728fae5e.tar.bz2 |
fixed an ugly timezone bug
-rw-r--r-- | microkde/kdecore/klocale.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp index 21e6937..d3b04dc 100644 --- a/microkde/kdecore/klocale.cpp +++ b/microkde/kdecore/klocale.cpp | |||
@@ -1,1034 +1,1034 @@ | |||
1 | #include <qregexp.h> | 1 | #include <qregexp.h> |
2 | #include <qapplication.h> | 2 | #include <qapplication.h> |
3 | 3 | ||
4 | #include "kdebug.h" | 4 | #include "kdebug.h" |
5 | #include "kcalendarsystemgregorian.h" | 5 | #include "kcalendarsystemgregorian.h" |
6 | 6 | ||
7 | #include "klocale.h" | 7 | #include "klocale.h" |
8 | 8 | ||
9 | #include <qstringlist.h> | 9 | #include <qstringlist.h> |
10 | QStringList missingTrans; | 10 | QStringList missingTrans; |
11 | 11 | ||
12 | QDict<QString> *mLocaleDict = 0; | 12 | QDict<QString> *mLocaleDict = 0; |
13 | void setLocaleDict( QDict<QString> * dict ) | 13 | void setLocaleDict( QDict<QString> * dict ) |
14 | { | 14 | { |
15 | mLocaleDict = dict; | 15 | mLocaleDict = dict; |
16 | 16 | ||
17 | } | 17 | } |
18 | void addMissing(const char *text) | 18 | void addMissing(const char *text) |
19 | { | 19 | { |
20 | return; | 20 | return; |
21 | QString mis ( text ); | 21 | QString mis ( text ); |
22 | if ( !missingTrans.contains( mis ) ) | 22 | if ( !missingTrans.contains( mis ) ) |
23 | missingTrans.append(mis); | 23 | missingTrans.append(mis); |
24 | 24 | ||
25 | } | 25 | } |
26 | 26 | ||
27 | #include <qfile.h> | 27 | #include <qfile.h> |
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qtextcodec.h> | 29 | #include <qtextcodec.h> |
30 | void dumpMissing() | 30 | void dumpMissing() |
31 | { | 31 | { |
32 | return; | 32 | return; |
33 | QString fileName = "/tmp/usertrans.txt"; | 33 | QString fileName = "/tmp/usertrans.txt"; |
34 | QFile file( fileName ); | 34 | QFile file( fileName ); |
35 | if (!file.open( IO_WriteOnly ) ) { | 35 | if (!file.open( IO_WriteOnly ) ) { |
36 | return ; | 36 | return ; |
37 | } | 37 | } |
38 | QTextStream ts( &file ); | 38 | QTextStream ts( &file ); |
39 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 39 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
40 | 40 | ||
41 | int i; | 41 | int i; |
42 | for ( i = 0; i< missingTrans.count(); ++i ) { | 42 | for ( i = 0; i< missingTrans.count(); ++i ) { |
43 | 43 | ||
44 | QString text = missingTrans[i].replace( QRegExp("\n"),"\\n" ); | 44 | QString text = missingTrans[i].replace( QRegExp("\n"),"\\n" ); |
45 | ts << "{ \""<<text<< "\",\""<< text <<"\" },\n"; | 45 | ts << "{ \""<<text<< "\",\""<< text <<"\" },\n"; |
46 | 46 | ||
47 | } | 47 | } |
48 | file.close(); | 48 | file.close(); |
49 | } | 49 | } |
50 | 50 | ||
51 | QString i18n(const char *text) | 51 | QString i18n(const char *text) |
52 | { | 52 | { |
53 | if ( ! mLocaleDict ) { | 53 | if ( ! mLocaleDict ) { |
54 | addMissing( text ); | 54 | addMissing( text ); |
55 | return QString( text ); | 55 | return QString( text ); |
56 | } | 56 | } |
57 | else { | 57 | else { |
58 | QString* ret = mLocaleDict->find(QString(text)) ; | 58 | QString* ret = mLocaleDict->find(QString(text)) ; |
59 | if ( ret == 0 ) { | 59 | if ( ret == 0 ) { |
60 | addMissing( text ); | 60 | addMissing( text ); |
61 | return QString( text ); | 61 | return QString( text ); |
62 | } | 62 | } |
63 | else { | 63 | else { |
64 | if ( (*ret).isEmpty() ) { | 64 | if ( (*ret).isEmpty() ) { |
65 | addMissing( text ); | 65 | addMissing( text ); |
66 | return QString( text ); | 66 | return QString( text ); |
67 | } | 67 | } |
68 | else | 68 | else |
69 | return (*ret); | 69 | return (*ret); |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | } | 73 | } |
74 | 74 | ||
75 | QString i18n(const char *,const char *text) | 75 | QString i18n(const char *,const char *text) |
76 | { | 76 | { |
77 | return i18n( text ); | 77 | return i18n( text ); |
78 | } | 78 | } |
79 | 79 | ||
80 | QString i18n(const char *text1, const char *textn, int num) | 80 | QString i18n(const char *text1, const char *textn, int num) |
81 | { | 81 | { |
82 | if ( num == 1 ) return i18n( text1 ); | 82 | if ( num == 1 ) return i18n( text1 ); |
83 | else { | 83 | else { |
84 | QString text = i18n( textn ); | 84 | QString text = i18n( textn ); |
85 | int pos = text.find( "%n" ); | 85 | int pos = text.find( "%n" ); |
86 | if ( pos >= 0 ) text.replace( pos, 2, QString::number( num ) ); | 86 | if ( pos >= 0 ) text.replace( pos, 2, QString::number( num ) ); |
87 | return text; | 87 | return text; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | inline void put_it_in( QChar *buffer, uint& index, const QString &s ) | 91 | inline void put_it_in( QChar *buffer, uint& index, const QString &s ) |
92 | { | 92 | { |
93 | for ( uint l = 0; l < s.length(); l++ ) | 93 | for ( uint l = 0; l < s.length(); l++ ) |
94 | buffer[index++] = s.at( l ); | 94 | buffer[index++] = s.at( l ); |
95 | } | 95 | } |
96 | 96 | ||
97 | inline void put_it_in( QChar *buffer, uint& index, int number ) | 97 | inline void put_it_in( QChar *buffer, uint& index, int number ) |
98 | { | 98 | { |
99 | buffer[index++] = number / 10 + '0'; | 99 | buffer[index++] = number / 10 + '0'; |
100 | buffer[index++] = number % 10 + '0'; | 100 | buffer[index++] = number % 10 + '0'; |
101 | } | 101 | } |
102 | 102 | ||
103 | static int readInt(const QString &str, uint &pos) | 103 | static int readInt(const QString &str, uint &pos) |
104 | { | 104 | { |
105 | if (!str.at(pos).isDigit()) return -1; | 105 | if (!str.at(pos).isDigit()) return -1; |
106 | int result = 0; | 106 | int result = 0; |
107 | for (; str.length() > pos && str.at(pos).isDigit(); pos++) | 107 | for (; str.length() > pos && str.at(pos).isDigit(); pos++) |
108 | { | 108 | { |
109 | result *= 10; | 109 | result *= 10; |
110 | result += str.at(pos).digitValue(); | 110 | result += str.at(pos).digitValue(); |
111 | } | 111 | } |
112 | 112 | ||
113 | return result; | 113 | return result; |
114 | } | 114 | } |
115 | 115 | ||
116 | KLocale::KLocale() : mCalendarSystem( 0 ) | 116 | KLocale::KLocale() : mCalendarSystem( 0 ) |
117 | { | 117 | { |
118 | 118 | ||
119 | m_decimalSymbol = "."; | 119 | m_decimalSymbol = "."; |
120 | m_positiveSign = ""; | 120 | m_positiveSign = ""; |
121 | m_negativeSign = "-"; | 121 | m_negativeSign = "-"; |
122 | m_thousandsSeparator = ","; | 122 | m_thousandsSeparator = ","; |
123 | 123 | ||
124 | 124 | ||
125 | 125 | ||
126 | 126 | ||
127 | mWeekStartsMonday = true; | 127 | mWeekStartsMonday = true; |
128 | mHourF24Format = true; | 128 | mHourF24Format = true; |
129 | mIntDateFormat = Default; | 129 | mIntDateFormat = Default; |
130 | mIntTimeFormat = Default; | 130 | mIntTimeFormat = Default; |
131 | mLanguage = 0; | 131 | mLanguage = 0; |
132 | mDateFormat = "%a %Y %b %d"; | 132 | mDateFormat = "%a %Y %b %d"; |
133 | mDateFormatShort = "%Y-%m-%d"; | 133 | mDateFormatShort = "%Y-%m-%d"; |
134 | mTimeZoneList << i18n ("-11:00 US/Samoa") | 134 | mTimeZoneList << ("-11:00 US/Samoa") |
135 | << i18n ("-10:00 US/Hawaii") | 135 | << ("-10:00 US/Hawaii") |
136 | << i18n ("-09:00 US/Alaska") | 136 | << ("-09:00 US/Alaska") |
137 | << i18n ("-08:00 US/Pacific") | 137 | << ("-08:00 US/Pacific") |
138 | << i18n ("-07:00 US/Mountain") | 138 | << ("-07:00 US/Mountain") |
139 | << i18n ("-06:00 US/Central") | 139 | << ("-06:00 US/Central") |
140 | << i18n ("-05:00 US/Eastern") | 140 | << ("-05:00 US/Eastern") |
141 | << i18n ("-04:00 Brazil/West") | 141 | << ("-04:00 Brazil/West") |
142 | << i18n ("-03:00 Brazil/East") | 142 | << ("-03:00 Brazil/East") |
143 | << i18n ("-02:00 Brazil/DeNoronha") | 143 | << ("-02:00 Brazil/DeNoronha") |
144 | << i18n ("-01:00 Atlantic/Azores") | 144 | << ("-01:00 Atlantic/Azores") |
145 | << i18n (" 00:00 Europe/London(UTC)") | 145 | << (" 00:00 Europe/London(UTC)") |
146 | << i18n ("+01:00 Europe/Oslo(CET)") | 146 | << ("+01:00 Europe/Oslo(CET)") |
147 | << i18n ("+02:00 Europe/Helsinki") | 147 | << ("+02:00 Europe/Helsinki") |
148 | << i18n ("+03:00 Europe/Moscow") | 148 | << ("+03:00 Europe/Moscow") |
149 | << i18n ("+04:00 Indian/Mauritius") | 149 | << ("+04:00 Indian/Mauritius") |
150 | << i18n ("+05:00 Indian/Maldives") | 150 | << ("+05:00 Indian/Maldives") |
151 | << i18n ("+06:00 Indian/Chagos") | 151 | << ("+06:00 Indian/Chagos") |
152 | << i18n ("+07:00 Asia/Bangkok") | 152 | << ("+07:00 Asia/Bangkok") |
153 | << i18n ("+08:00 Asia/Hongkong") | 153 | << ("+08:00 Asia/Hongkong") |
154 | << i18n ("+09:00 Asia/Tokyo") | 154 | << ("+09:00 Asia/Tokyo") |
155 | << i18n ("+10:00 Asia/Vladivostok") | 155 | << ("+10:00 Asia/Vladivostok") |
156 | << i18n ("+11:00 Asia/Magadan") | 156 | << ("+11:00 Asia/Magadan") |
157 | << i18n ("+12:00 Asia/Kamchatka") | 157 | << ("+12:00 Asia/Kamchatka") |
158 | // << i18n (" xx:xx User defined offset") | 158 | // << (" xx:xx User defined offset") |
159 | << i18n (" Local Time"); | 159 | << i18n (" Local Time"); |
160 | mSouthDaylight = false; | 160 | mSouthDaylight = false; |
161 | mTimeZoneOffset = 0; | 161 | mTimeZoneOffset = 0; |
162 | daylightEnabled = false; | 162 | daylightEnabled = false; |
163 | } | 163 | } |
164 | 164 | ||
165 | void KLocale::setDateFormat( QString s ) | 165 | void KLocale::setDateFormat( QString s ) |
166 | { | 166 | { |
167 | mDateFormat = s; | 167 | mDateFormat = s; |
168 | } | 168 | } |
169 | 169 | ||
170 | void KLocale::setDateFormatShort( QString s ) | 170 | void KLocale::setDateFormatShort( QString s ) |
171 | { | 171 | { |
172 | mDateFormatShort = s; | 172 | mDateFormatShort = s; |
173 | } | 173 | } |
174 | 174 | ||
175 | void KLocale::setHore24Format ( bool b ) | 175 | void KLocale::setHore24Format ( bool b ) |
176 | { | 176 | { |
177 | mHourF24Format = b; | 177 | mHourF24Format = b; |
178 | } | 178 | } |
179 | void KLocale::setWeekStartMonday( bool b ) | 179 | void KLocale::setWeekStartMonday( bool b ) |
180 | { | 180 | { |
181 | mWeekStartsMonday = b; | 181 | mWeekStartsMonday = b; |
182 | } | 182 | } |
183 | 183 | ||
184 | KLocale::IntDateFormat KLocale::getIntDateFormat( ) | 184 | KLocale::IntDateFormat KLocale::getIntDateFormat( ) |
185 | { | 185 | { |
186 | return mIntDateFormat; | 186 | return mIntDateFormat; |
187 | 187 | ||
188 | } | 188 | } |
189 | void KLocale::setIntDateFormat( KLocale::IntDateFormat i ) | 189 | void KLocale::setIntDateFormat( KLocale::IntDateFormat i ) |
190 | { | 190 | { |
191 | mIntDateFormat = i; | 191 | mIntDateFormat = i; |
192 | } | 192 | } |
193 | KLocale::IntDateFormat KLocale::getIntTimeFormat( ) | 193 | KLocale::IntDateFormat KLocale::getIntTimeFormat( ) |
194 | { | 194 | { |
195 | return mIntTimeFormat; | 195 | return mIntTimeFormat; |
196 | 196 | ||
197 | } | 197 | } |
198 | void KLocale::setIntTimeFormat( KLocale::IntDateFormat i ) | 198 | void KLocale::setIntTimeFormat( KLocale::IntDateFormat i ) |
199 | { | 199 | { |
200 | mIntTimeFormat = i; | 200 | mIntTimeFormat = i; |
201 | } | 201 | } |
202 | 202 | ||
203 | void KLocale::setLanguage( int i ) | 203 | void KLocale::setLanguage( int i ) |
204 | { | 204 | { |
205 | mLanguage = i; | 205 | mLanguage = i; |
206 | } | 206 | } |
207 | int KLocale::language( ) | 207 | int KLocale::language( ) |
208 | { | 208 | { |
209 | return mLanguage; | 209 | return mLanguage; |
210 | } | 210 | } |
211 | QString KLocale::translate( const char *index ) const | 211 | QString KLocale::translate( const char *index ) const |
212 | { | 212 | { |
213 | return i18n( index ); | 213 | return i18n( index ); |
214 | } | 214 | } |
215 | 215 | ||
216 | QString KLocale::translate( const char *, const char *fallback) const | 216 | QString KLocale::translate( const char *, const char *fallback) const |
217 | { | 217 | { |
218 | return i18n( fallback ); | 218 | return i18n( fallback ); |
219 | } | 219 | } |
220 | 220 | ||
221 | QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const | 221 | QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const |
222 | { | 222 | { |
223 | const QString rst = timeFormat(intIntDateFormat); | 223 | const QString rst = timeFormat(intIntDateFormat); |
224 | 224 | ||
225 | // only "pm/am" here can grow, the rest shrinks, but | 225 | // only "pm/am" here can grow, the rest shrinks, but |
226 | // I'm rather safe than sorry | 226 | // I'm rather safe than sorry |
227 | QChar *buffer = new QChar[rst.length() * 3 / 2 + 30]; | 227 | QChar *buffer = new QChar[rst.length() * 3 / 2 + 30]; |
228 | 228 | ||
229 | uint index = 0; | 229 | uint index = 0; |
230 | bool escape = false; | 230 | bool escape = false; |
231 | int number = 0; | 231 | int number = 0; |
232 | 232 | ||
233 | for ( uint format_index = 0; format_index < rst.length(); format_index++ ) | 233 | for ( uint format_index = 0; format_index < rst.length(); format_index++ ) |
234 | { | 234 | { |
235 | if ( !escape ) | 235 | if ( !escape ) |
236 | { | 236 | { |
237 | if ( rst.at( format_index ).unicode() == '%' ) | 237 | if ( rst.at( format_index ).unicode() == '%' ) |
238 | escape = true; | 238 | escape = true; |
239 | else | 239 | else |
240 | buffer[index++] = rst.at( format_index ); | 240 | buffer[index++] = rst.at( format_index ); |
241 | } | 241 | } |
242 | else | 242 | else |
243 | { | 243 | { |
244 | switch ( rst.at( format_index ).unicode() ) | 244 | switch ( rst.at( format_index ).unicode() ) |
245 | { | 245 | { |
246 | case '%': | 246 | case '%': |
247 | buffer[index++] = '%'; | 247 | buffer[index++] = '%'; |
248 | break; | 248 | break; |
249 | case 'H': | 249 | case 'H': |
250 | put_it_in( buffer, index, pTime.hour() ); | 250 | put_it_in( buffer, index, pTime.hour() ); |
251 | break; | 251 | break; |
252 | case 'I': | 252 | case 'I': |
253 | put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 ); | 253 | put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 ); |
254 | break; | 254 | break; |
255 | case 'M': | 255 | case 'M': |
256 | put_it_in( buffer, index, pTime.minute() ); | 256 | put_it_in( buffer, index, pTime.minute() ); |
257 | break; | 257 | break; |
258 | case 'S': | 258 | case 'S': |
259 | if (includeSecs) | 259 | if (includeSecs) |
260 | put_it_in( buffer, index, pTime.second() ); | 260 | put_it_in( buffer, index, pTime.second() ); |
261 | else | 261 | else |
262 | { | 262 | { |
263 | // we remove the seperator sign before the seconds and | 263 | // we remove the seperator sign before the seconds and |
264 | // assume that works everywhere | 264 | // assume that works everywhere |
265 | --index; | 265 | --index; |
266 | break; | 266 | break; |
267 | } | 267 | } |
268 | break; | 268 | break; |
269 | case 'k': | 269 | case 'k': |
270 | number = pTime.hour(); | 270 | number = pTime.hour(); |
271 | case 'l': | 271 | case 'l': |
272 | // to share the code | 272 | // to share the code |
273 | if ( rst.at( format_index ).unicode() == 'l' ) | 273 | if ( rst.at( format_index ).unicode() == 'l' ) |
274 | number = (pTime.hour() + 11) % 12 + 1; | 274 | number = (pTime.hour() + 11) % 12 + 1; |
275 | if ( number / 10 ) | 275 | if ( number / 10 ) |
276 | buffer[index++] = number / 10 + '0'; | 276 | buffer[index++] = number / 10 + '0'; |
277 | buffer[index++] = number % 10 + '0'; | 277 | buffer[index++] = number % 10 + '0'; |
278 | break; | 278 | break; |
279 | case 'p': | 279 | case 'p': |
280 | { | 280 | { |
281 | QString s; | 281 | QString s; |
282 | if ( pTime.hour() >= 12 ) | 282 | if ( pTime.hour() >= 12 ) |
283 | put_it_in( buffer, index, i18n("pm") ); | 283 | put_it_in( buffer, index, i18n("pm") ); |
284 | else | 284 | else |
285 | put_it_in( buffer, index, i18n("am") ); | 285 | put_it_in( buffer, index, i18n("am") ); |
286 | break; | 286 | break; |
287 | } | 287 | } |
288 | default: | 288 | default: |
289 | buffer[index++] = rst.at( format_index ); | 289 | buffer[index++] = rst.at( format_index ); |
290 | break; | 290 | break; |
291 | } | 291 | } |
292 | escape = false; | 292 | escape = false; |
293 | } | 293 | } |
294 | } | 294 | } |
295 | QString ret( buffer, index ); | 295 | QString ret( buffer, index ); |
296 | delete [] buffer; | 296 | delete [] buffer; |
297 | return ret; | 297 | return ret; |
298 | } | 298 | } |
299 | 299 | ||
300 | QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const | 300 | QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const |
301 | { | 301 | { |
302 | const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); | 302 | const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); |
303 | 303 | ||
304 | // I'm rather safe than sorry | 304 | // I'm rather safe than sorry |
305 | QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; | 305 | QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; |
306 | 306 | ||
307 | unsigned int index = 0; | 307 | unsigned int index = 0; |
308 | bool escape = false; | 308 | bool escape = false; |
309 | int number = 0; | 309 | int number = 0; |
310 | 310 | ||
311 | for ( uint format_index = 0; format_index < rst.length(); ++format_index ) | 311 | for ( uint format_index = 0; format_index < rst.length(); ++format_index ) |
312 | { | 312 | { |
313 | if ( !escape ) | 313 | if ( !escape ) |
314 | { | 314 | { |
315 | if ( rst.at( format_index ).unicode() == '%' ) | 315 | if ( rst.at( format_index ).unicode() == '%' ) |
316 | escape = true; | 316 | escape = true; |
317 | else | 317 | else |
318 | buffer[index++] = rst.at( format_index ); | 318 | buffer[index++] = rst.at( format_index ); |
319 | } | 319 | } |
320 | else | 320 | else |
321 | { | 321 | { |
322 | switch ( rst.at( format_index ).unicode() ) | 322 | switch ( rst.at( format_index ).unicode() ) |
323 | { | 323 | { |
324 | case '%': | 324 | case '%': |
325 | buffer[index++] = '%'; | 325 | buffer[index++] = '%'; |
326 | break; | 326 | break; |
327 | case 'Y': | 327 | case 'Y': |
328 | put_it_in( buffer, index, pDate.year() / 100 ); | 328 | put_it_in( buffer, index, pDate.year() / 100 ); |
329 | case 'y': | 329 | case 'y': |
330 | put_it_in( buffer, index, pDate.year() % 100 ); | 330 | put_it_in( buffer, index, pDate.year() % 100 ); |
331 | break; | 331 | break; |
332 | case 'n': | 332 | case 'n': |
333 | number = pDate.month(); | 333 | number = pDate.month(); |
334 | case 'e': | 334 | case 'e': |
335 | // to share the code | 335 | // to share the code |
336 | if ( rst.at( format_index ).unicode() == 'e' ) | 336 | if ( rst.at( format_index ).unicode() == 'e' ) |
337 | number = pDate.day(); | 337 | number = pDate.day(); |
338 | if ( number / 10 ) | 338 | if ( number / 10 ) |
339 | buffer[index++] = number / 10 + '0'; | 339 | buffer[index++] = number / 10 + '0'; |
340 | buffer[index++] = number % 10 + '0'; | 340 | buffer[index++] = number % 10 + '0'; |
341 | break; | 341 | break; |
342 | case 'm': | 342 | case 'm': |
343 | put_it_in( buffer, index, pDate.month() ); | 343 | put_it_in( buffer, index, pDate.month() ); |
344 | break; | 344 | break; |
345 | case 'b': | 345 | case 'b': |
346 | put_it_in( buffer, index, monthName(pDate.month(), true) ); | 346 | put_it_in( buffer, index, monthName(pDate.month(), true) ); |
347 | break; | 347 | break; |
348 | case 'B': | 348 | case 'B': |
349 | put_it_in( buffer, index, monthName(pDate.month(), false) ); | 349 | put_it_in( buffer, index, monthName(pDate.month(), false) ); |
350 | break; | 350 | break; |
351 | case 'd': | 351 | case 'd': |
352 | put_it_in( buffer, index, pDate.day() ); | 352 | put_it_in( buffer, index, pDate.day() ); |
353 | break; | 353 | break; |
354 | case 'a': | 354 | case 'a': |
355 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); | 355 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); |
356 | break; | 356 | break; |
357 | case 'A': | 357 | case 'A': |
358 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); | 358 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); |
359 | break; | 359 | break; |
360 | default: | 360 | default: |
361 | buffer[index++] = rst.at( format_index ); | 361 | buffer[index++] = rst.at( format_index ); |
362 | break; | 362 | break; |
363 | } | 363 | } |
364 | escape = false; | 364 | escape = false; |
365 | } | 365 | } |
366 | } | 366 | } |
367 | QString ret( buffer, index ); | 367 | QString ret( buffer, index ); |
368 | delete [] buffer; | 368 | delete [] buffer; |
369 | return ret; | 369 | return ret; |
370 | } | 370 | } |
371 | 371 | ||
372 | QString KLocale::formatDateTime(const QDateTime &pDateTime, | 372 | QString KLocale::formatDateTime(const QDateTime &pDateTime, |
373 | bool shortFormat, | 373 | bool shortFormat, |
374 | bool includeSeconds, | 374 | bool includeSeconds, |
375 | IntDateFormat intIntDateFormat) const | 375 | IntDateFormat intIntDateFormat) const |
376 | { | 376 | { |
377 | QString format("%1 %2"); | 377 | QString format("%1 %2"); |
378 | 378 | ||
379 | if ( intIntDateFormat == Default ) | 379 | if ( intIntDateFormat == Default ) |
380 | format = "%1 %2"; | 380 | format = "%1 %2"; |
381 | else if ( intIntDateFormat == Format1 ) | 381 | else if ( intIntDateFormat == Format1 ) |
382 | format = "%1 %2"; | 382 | format = "%1 %2"; |
383 | else if ( intIntDateFormat == ISODate ) | 383 | else if ( intIntDateFormat == ISODate ) |
384 | format = "%1T%2"; | 384 | format = "%1T%2"; |
385 | 385 | ||
386 | QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat )) | 386 | QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat )) |
387 | .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat )); | 387 | .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat )); |
388 | 388 | ||
389 | //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() ); | 389 | //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() ); |
390 | 390 | ||
391 | return res; | 391 | return res; |
392 | } | 392 | } |
393 | 393 | ||
394 | QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const | 394 | QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const |
395 | { | 395 | { |
396 | return formatDateTime(pDateTime, true, true, intIntDateFormat); | 396 | return formatDateTime(pDateTime, true, true, intIntDateFormat); |
397 | } | 397 | } |
398 | 398 | ||
399 | QDate KLocale::readDate(const QString &intstr, bool* ok) const | 399 | QDate KLocale::readDate(const QString &intstr, bool* ok) const |
400 | { | 400 | { |
401 | QDate date; | 401 | QDate date; |
402 | date = readDate(intstr, true, ok); | 402 | date = readDate(intstr, true, ok); |
403 | if (date.isValid()) return date; | 403 | if (date.isValid()) return date; |
404 | return readDate(intstr, false, ok); | 404 | return readDate(intstr, false, ok); |
405 | } | 405 | } |
406 | 406 | ||
407 | QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const | 407 | QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const |
408 | { | 408 | { |
409 | QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); | 409 | QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); |
410 | return readDate( intstr, fmt, ok ); | 410 | return readDate( intstr, fmt, ok ); |
411 | } | 411 | } |
412 | 412 | ||
413 | QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const | 413 | QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const |
414 | { | 414 | { |
415 | //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; | 415 | //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; |
416 | QString str = intstr.simplifyWhiteSpace().lower(); | 416 | QString str = intstr.simplifyWhiteSpace().lower(); |
417 | int day = -1, month = -1; | 417 | int day = -1, month = -1; |
418 | // allow the year to be omitted if not in the format | 418 | // allow the year to be omitted if not in the format |
419 | int year = QDate::currentDate().year(); | 419 | int year = QDate::currentDate().year(); |
420 | uint strpos = 0; | 420 | uint strpos = 0; |
421 | uint fmtpos = 0; | 421 | uint fmtpos = 0; |
422 | 422 | ||
423 | while (fmt.length() > fmtpos || str.length() > strpos) | 423 | while (fmt.length() > fmtpos || str.length() > strpos) |
424 | { | 424 | { |
425 | if ( !(fmt.length() > fmtpos && str.length() > strpos) ) | 425 | if ( !(fmt.length() > fmtpos && str.length() > strpos) ) |
426 | goto error; | 426 | goto error; |
427 | 427 | ||
428 | QChar c = fmt.at(fmtpos++); | 428 | QChar c = fmt.at(fmtpos++); |
429 | 429 | ||
430 | if (c != '%') { | 430 | if (c != '%') { |
431 | if (c.isSpace()) | 431 | if (c.isSpace()) |
432 | strpos++; | 432 | strpos++; |
433 | else if (c != str.at(strpos++)) | 433 | else if (c != str.at(strpos++)) |
434 | goto error; | 434 | goto error; |
435 | continue; | 435 | continue; |
436 | } | 436 | } |
437 | 437 | ||
438 | // remove space at the begining | 438 | // remove space at the begining |
439 | if (str.length() > strpos && str.at(strpos).isSpace()) | 439 | if (str.length() > strpos && str.at(strpos).isSpace()) |
440 | strpos++; | 440 | strpos++; |
441 | 441 | ||
442 | c = fmt.at(fmtpos++); | 442 | c = fmt.at(fmtpos++); |
443 | switch (c) | 443 | switch (c) |
444 | { | 444 | { |
445 | case 'a': | 445 | case 'a': |
446 | case 'A': | 446 | case 'A': |
447 | // this will just be ignored | 447 | // this will just be ignored |
448 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition | 448 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition |
449 | for (int j = 1; j < 8; j++) { | 449 | for (int j = 1; j < 8; j++) { |
450 | QString s = weekDayName(j, c == 'a').lower(); | 450 | QString s = weekDayName(j, c == 'a').lower(); |
451 | int len = s.length(); | 451 | int len = s.length(); |
452 | if (str.mid(strpos, len) == s) | 452 | if (str.mid(strpos, len) == s) |
453 | strpos += len; | 453 | strpos += len; |
454 | } | 454 | } |
455 | break; | 455 | break; |
456 | } | 456 | } |
457 | case 'b': | 457 | case 'b': |
458 | case 'B': | 458 | case 'B': |
459 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition | 459 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition |
460 | for (int j = 1; j < 13; j++) { | 460 | for (int j = 1; j < 13; j++) { |
461 | QString s = monthName(j, c == 'b').lower(); | 461 | QString s = monthName(j, c == 'b').lower(); |
462 | int len = s.length(); | 462 | int len = s.length(); |
463 | if (str.mid(strpos, len) == s) { | 463 | if (str.mid(strpos, len) == s) { |
464 | month = j; | 464 | month = j; |
465 | strpos += len; | 465 | strpos += len; |
466 | } | 466 | } |
467 | } | 467 | } |
468 | break; | 468 | break; |
469 | } | 469 | } |
470 | case 'd': | 470 | case 'd': |
471 | case 'e': | 471 | case 'e': |
472 | day = readInt(str, strpos); | 472 | day = readInt(str, strpos); |
473 | if (day < 1 || day > 31) | 473 | if (day < 1 || day > 31) |
474 | goto error; | 474 | goto error; |
475 | 475 | ||
476 | break; | 476 | break; |
477 | 477 | ||
478 | case 'n': | 478 | case 'n': |
479 | case 'm': | 479 | case 'm': |
480 | month = readInt(str, strpos); | 480 | month = readInt(str, strpos); |
481 | if (month < 1 || month > 12) | 481 | if (month < 1 || month > 12) |
482 | goto error; | 482 | goto error; |
483 | 483 | ||
484 | break; | 484 | break; |
485 | 485 | ||
486 | case 'Y': | 486 | case 'Y': |
487 | case 'y': | 487 | case 'y': |
488 | year = readInt(str, strpos); | 488 | year = readInt(str, strpos); |
489 | if (year < 0) | 489 | if (year < 0) |
490 | goto error; | 490 | goto error; |
491 | // Qt treats a year in the range 0-100 as 1900-1999. | 491 | // Qt treats a year in the range 0-100 as 1900-1999. |
492 | // It is nicer for the user if we treat 0-68 as 2000-2068 | 492 | // It is nicer for the user if we treat 0-68 as 2000-2068 |
493 | if (year < 69) | 493 | if (year < 69) |
494 | year += 2000; | 494 | year += 2000; |
495 | else if (c == 'y') | 495 | else if (c == 'y') |
496 | year += 1900; | 496 | year += 1900; |
497 | 497 | ||
498 | break; | 498 | break; |
499 | } | 499 | } |
500 | } | 500 | } |
501 | //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; | 501 | //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; |
502 | if ( year != -1 && month != -1 && day != -1 ) | 502 | if ( year != -1 && month != -1 && day != -1 ) |
503 | { | 503 | { |
504 | if (ok) *ok = true; | 504 | if (ok) *ok = true; |
505 | return QDate(year, month, day); | 505 | return QDate(year, month, day); |
506 | } | 506 | } |
507 | error: | 507 | error: |
508 | if (ok) *ok = false; | 508 | if (ok) *ok = false; |
509 | return QDate(); // invalid date | 509 | return QDate(); // invalid date |
510 | } | 510 | } |
511 | 511 | ||
512 | QTime KLocale::readTime(const QString &intstr, bool *ok) const | 512 | QTime KLocale::readTime(const QString &intstr, bool *ok) const |
513 | { | 513 | { |
514 | QTime _time; | 514 | QTime _time; |
515 | _time = readTime(intstr, true, ok); | 515 | _time = readTime(intstr, true, ok); |
516 | if (_time.isValid()) return _time; | 516 | if (_time.isValid()) return _time; |
517 | return readTime(intstr, false, ok); | 517 | return readTime(intstr, false, ok); |
518 | } | 518 | } |
519 | 519 | ||
520 | QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const | 520 | QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const |
521 | { | 521 | { |
522 | QString str = intstr.simplifyWhiteSpace().lower(); | 522 | QString str = intstr.simplifyWhiteSpace().lower(); |
523 | QString Format = timeFormat().simplifyWhiteSpace(); | 523 | QString Format = timeFormat().simplifyWhiteSpace(); |
524 | if (!seconds) | 524 | if (!seconds) |
525 | Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); | 525 | Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); |
526 | 526 | ||
527 | int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds | 527 | int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds |
528 | 528 | ||
529 | bool g_12h = false; | 529 | bool g_12h = false; |
530 | bool pm = false; | 530 | bool pm = false; |
531 | uint strpos = 0; | 531 | uint strpos = 0; |
532 | uint Formatpos = 0; | 532 | uint Formatpos = 0; |
533 | 533 | ||
534 | while (Format.length() > Formatpos || str.length() > strpos) | 534 | while (Format.length() > Formatpos || str.length() > strpos) |
535 | { | 535 | { |
536 | if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; | 536 | if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; |
537 | 537 | ||
538 | QChar c = Format.at(Formatpos++); | 538 | QChar c = Format.at(Formatpos++); |
539 | 539 | ||
540 | if (c != '%') | 540 | if (c != '%') |
541 | { | 541 | { |
542 | if (c.isSpace()) | 542 | if (c.isSpace()) |
543 | strpos++; | 543 | strpos++; |
544 | else if (c != str.at(strpos++)) | 544 | else if (c != str.at(strpos++)) |
545 | goto error; | 545 | goto error; |
546 | continue; | 546 | continue; |
547 | } | 547 | } |
548 | 548 | ||
549 | // remove space at the begining | 549 | // remove space at the begining |
550 | if (str.length() > strpos && str.at(strpos).isSpace()) | 550 | if (str.length() > strpos && str.at(strpos).isSpace()) |
551 | strpos++; | 551 | strpos++; |
552 | 552 | ||
553 | c = Format.at(Formatpos++); | 553 | c = Format.at(Formatpos++); |
554 | switch (c) | 554 | switch (c) |
555 | { | 555 | { |
556 | case 'p': | 556 | case 'p': |
557 | { | 557 | { |
558 | QString s; | 558 | QString s; |
559 | s = i18n("pm").lower(); | 559 | s = i18n("pm").lower(); |
560 | int len = s.length(); | 560 | int len = s.length(); |
561 | if (str.mid(strpos, len) == s) | 561 | if (str.mid(strpos, len) == s) |
562 | { | 562 | { |
563 | pm = true; | 563 | pm = true; |
564 | strpos += len; | 564 | strpos += len; |
565 | } | 565 | } |
566 | else | 566 | else |
567 | { | 567 | { |
568 | s = i18n("am").lower(); | 568 | s = i18n("am").lower(); |
569 | len = s.length(); | 569 | len = s.length(); |
570 | if (str.mid(strpos, len) == s) { | 570 | if (str.mid(strpos, len) == s) { |
571 | pm = false; | 571 | pm = false; |
572 | strpos += len; | 572 | strpos += len; |
573 | } | 573 | } |
574 | else | 574 | else |
575 | goto error; | 575 | goto error; |
576 | } | 576 | } |
577 | } | 577 | } |
578 | break; | 578 | break; |
579 | 579 | ||
580 | case 'k': | 580 | case 'k': |
581 | case 'H': | 581 | case 'H': |
582 | g_12h = false; | 582 | g_12h = false; |
583 | hour = readInt(str, strpos); | 583 | hour = readInt(str, strpos); |
584 | if (hour < 0 || hour > 23) | 584 | if (hour < 0 || hour > 23) |
585 | goto error; | 585 | goto error; |
586 | 586 | ||
587 | break; | 587 | break; |
588 | 588 | ||
589 | case 'l': | 589 | case 'l': |
590 | case 'I': | 590 | case 'I': |
591 | g_12h = true; | 591 | g_12h = true; |
592 | hour = readInt(str, strpos); | 592 | hour = readInt(str, strpos); |
593 | if (hour < 1 || hour > 12) | 593 | if (hour < 1 || hour > 12) |
594 | goto error; | 594 | goto error; |
595 | 595 | ||
596 | break; | 596 | break; |
597 | 597 | ||
598 | case 'M': | 598 | case 'M': |
599 | minute = readInt(str, strpos); | 599 | minute = readInt(str, strpos); |
600 | if (minute < 0 || minute > 59) | 600 | if (minute < 0 || minute > 59) |
601 | goto error; | 601 | goto error; |
602 | 602 | ||
603 | break; | 603 | break; |
604 | 604 | ||
605 | case 'S': | 605 | case 'S': |
606 | second = readInt(str, strpos); | 606 | second = readInt(str, strpos); |
607 | if (second < 0 || second > 59) | 607 | if (second < 0 || second > 59) |
608 | goto error; | 608 | goto error; |
609 | 609 | ||
610 | break; | 610 | break; |
611 | } | 611 | } |
612 | } | 612 | } |
613 | if (g_12h) | 613 | if (g_12h) |
614 | { | 614 | { |
615 | hour %= 12; | 615 | hour %= 12; |
616 | if (pm) hour += 12; | 616 | if (pm) hour += 12; |
617 | } | 617 | } |
618 | 618 | ||
619 | if (ok) *ok = true; | 619 | if (ok) *ok = true; |
620 | return QTime(hour, minute, second); | 620 | return QTime(hour, minute, second); |
621 | 621 | ||
622 | error: | 622 | error: |
623 | if (ok) *ok = false; | 623 | if (ok) *ok = false; |
624 | return QTime(-1, -1, -1); // return invalid date if it didn't work | 624 | return QTime(-1, -1, -1); // return invalid date if it didn't work |
625 | // This will be removed in the near future, since it gives a warning on stderr. | 625 | // This will be removed in the near future, since it gives a warning on stderr. |
626 | // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. | 626 | // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. |
627 | } | 627 | } |
628 | 628 | ||
629 | QDateTime KLocale::readDateTime(const QString &intstr, | 629 | QDateTime KLocale::readDateTime(const QString &intstr, |
630 | IntDateFormat intIntDateFormat, | 630 | IntDateFormat intIntDateFormat, |
631 | bool* ok) const | 631 | bool* ok) const |
632 | { | 632 | { |
633 | bool ok1, ok2; | 633 | bool ok1, ok2; |
634 | 634 | ||
635 | // AT the moment we can not read any other format then ISODate | 635 | // AT the moment we can not read any other format then ISODate |
636 | if ( intIntDateFormat != ISODate ) | 636 | if ( intIntDateFormat != ISODate ) |
637 | { | 637 | { |
638 | qDebug("KLocale::readDateTime, only ISODate is supported."); | 638 | qDebug("KLocale::readDateTime, only ISODate is supported."); |
639 | return QDateTime(); | 639 | return QDateTime(); |
640 | } | 640 | } |
641 | 641 | ||
642 | int pos = intstr.find("T"); | 642 | int pos = intstr.find("T"); |
643 | QString date = intstr.left(pos); | 643 | QString date = intstr.left(pos); |
644 | QString time = intstr.mid(pos+1); | 644 | QString time = intstr.mid(pos+1); |
645 | 645 | ||
646 | QString dformat = dateFormat(intIntDateFormat); | 646 | QString dformat = dateFormat(intIntDateFormat); |
647 | QString tformat = timeFormat(intIntDateFormat); | 647 | QString tformat = timeFormat(intIntDateFormat); |
648 | 648 | ||
649 | QDate m_date = readDate(date, dformat, &ok1); | 649 | QDate m_date = readDate(date, dformat, &ok1); |
650 | QTime m_time = readTime(time, tformat, &ok2); | 650 | QTime m_time = readTime(time, tformat, &ok2); |
651 | 651 | ||
652 | QDateTime m_dt; | 652 | QDateTime m_dt; |
653 | 653 | ||
654 | if (ok) | 654 | if (ok) |
655 | { | 655 | { |
656 | if ((ok1 == false) || (ok2 == false)) | 656 | if ((ok1 == false) || (ok2 == false)) |
657 | *ok = false; | 657 | *ok = false; |
658 | else | 658 | else |
659 | *ok = true; | 659 | *ok = true; |
660 | } | 660 | } |
661 | 661 | ||
662 | //only set values if both operations returned true. | 662 | //only set values if both operations returned true. |
663 | if ((ok1 == true) && (ok2 == true)) | 663 | if ((ok1 == true) && (ok2 == true)) |
664 | { | 664 | { |
665 | m_dt.setDate(m_date); | 665 | m_dt.setDate(m_date); |
666 | m_dt.setTime(m_time); | 666 | m_dt.setTime(m_time); |
667 | } | 667 | } |
668 | 668 | ||
669 | //qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); | 669 | //qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); |
670 | return m_dt; | 670 | return m_dt; |
671 | } | 671 | } |
672 | 672 | ||
673 | QDate KLocale::readDate(const QString &intstr, | 673 | QDate KLocale::readDate(const QString &intstr, |
674 | IntDateFormat intIntDateFormat, | 674 | IntDateFormat intIntDateFormat, |
675 | bool* ok) const | 675 | bool* ok) const |
676 | { | 676 | { |
677 | bool ok1; | 677 | bool ok1; |
678 | 678 | ||
679 | QString dformat = dateFormat(intIntDateFormat); | 679 | QString dformat = dateFormat(intIntDateFormat); |
680 | 680 | ||
681 | QDate m_date = readDate(intstr, dformat, &ok1); | 681 | QDate m_date = readDate(intstr, dformat, &ok1); |
682 | 682 | ||
683 | if (ok) | 683 | if (ok) |
684 | *ok = ok1; | 684 | *ok = ok1; |
685 | 685 | ||
686 | //qDebug("KLocale::readDate() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); | 686 | //qDebug("KLocale::readDate() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); |
687 | return m_date; | 687 | return m_date; |
688 | } | 688 | } |
689 | 689 | ||
690 | 690 | ||
691 | bool KLocale::use12Clock() const | 691 | bool KLocale::use12Clock() const |
692 | { | 692 | { |
693 | return !mHourF24Format ;; | 693 | return !mHourF24Format ;; |
694 | } | 694 | } |
695 | 695 | ||
696 | bool KLocale::weekStartsMonday() const | 696 | bool KLocale::weekStartsMonday() const |
697 | { | 697 | { |
698 | return mWeekStartsMonday; | 698 | return mWeekStartsMonday; |
699 | } | 699 | } |
700 | 700 | ||
701 | int KLocale::weekStartDay() const | 701 | int KLocale::weekStartDay() const |
702 | { | 702 | { |
703 | if ( mWeekStartsMonday ) | 703 | if ( mWeekStartsMonday ) |
704 | return 1; | 704 | return 1; |
705 | return 7; | 705 | return 7; |
706 | } | 706 | } |
707 | 707 | ||
708 | QString KLocale::weekDayName(int i,bool shortName) const | 708 | QString KLocale::weekDayName(int i,bool shortName) const |
709 | { | 709 | { |
710 | if ( shortName ) | 710 | if ( shortName ) |
711 | switch ( i ) | 711 | switch ( i ) |
712 | { | 712 | { |
713 | case 1: return i18n("Monday", "Mon"); | 713 | case 1: return i18n("Monday", "Mon"); |
714 | case 2: return i18n("Tuesday", "Tue"); | 714 | case 2: return i18n("Tuesday", "Tue"); |
715 | case 3: return i18n("Wednesday", "Wed"); | 715 | case 3: return i18n("Wednesday", "Wed"); |
716 | case 4: return i18n("Thursday", "Thu"); | 716 | case 4: return i18n("Thursday", "Thu"); |
717 | case 5: return i18n("Friday", "Fri"); | 717 | case 5: return i18n("Friday", "Fri"); |
718 | case 6: return i18n("Saturday", "Sat"); | 718 | case 6: return i18n("Saturday", "Sat"); |
719 | case 7: return i18n("Sunday", "Sun"); | 719 | case 7: return i18n("Sunday", "Sun"); |
720 | } | 720 | } |
721 | else | 721 | else |
722 | switch ( i ) | 722 | switch ( i ) |
723 | { | 723 | { |
724 | case 1: return i18n("Monday"); | 724 | case 1: return i18n("Monday"); |
725 | case 2: return i18n("Tuesday"); | 725 | case 2: return i18n("Tuesday"); |
726 | case 3: return i18n("Wednesday"); | 726 | case 3: return i18n("Wednesday"); |
727 | case 4: return i18n("Thursday"); | 727 | case 4: return i18n("Thursday"); |
728 | case 5: return i18n("Friday"); | 728 | case 5: return i18n("Friday"); |
729 | case 6: return i18n("Saturday"); | 729 | case 6: return i18n("Saturday"); |
730 | case 7: return i18n("Sunday"); | 730 | case 7: return i18n("Sunday"); |
731 | } | 731 | } |
732 | 732 | ||
733 | return QString::null; | 733 | return QString::null; |
734 | } | 734 | } |
735 | 735 | ||
736 | QString KLocale::monthName(int i,bool shortName) const | 736 | QString KLocale::monthName(int i,bool shortName) const |
737 | { | 737 | { |
738 | if ( shortName ) | 738 | if ( shortName ) |
739 | switch ( i ) | 739 | switch ( i ) |
740 | { | 740 | { |
741 | case 1: return i18n("January", "Jan"); | 741 | case 1: return i18n("January", "Jan"); |
742 | case 2: return i18n("February", "Feb"); | 742 | case 2: return i18n("February", "Feb"); |
743 | case 3: return i18n("March", "Mar"); | 743 | case 3: return i18n("March", "Mar"); |
744 | case 4: return i18n("April", "Apr"); | 744 | case 4: return i18n("April", "Apr"); |
745 | case 5: return i18n("May short", "May"); | 745 | case 5: return i18n("May short", "May"); |
746 | case 6: return i18n("June", "Jun"); | 746 | case 6: return i18n("June", "Jun"); |
747 | case 7: return i18n("July", "Jul"); | 747 | case 7: return i18n("July", "Jul"); |
748 | case 8: return i18n("August", "Aug"); | 748 | case 8: return i18n("August", "Aug"); |
749 | case 9: return i18n("September", "Sep"); | 749 | case 9: return i18n("September", "Sep"); |
750 | case 10: return i18n("October", "Oct"); | 750 | case 10: return i18n("October", "Oct"); |
751 | case 11: return i18n("November", "Nov"); | 751 | case 11: return i18n("November", "Nov"); |
752 | case 12: return i18n("December", "Dec"); | 752 | case 12: return i18n("December", "Dec"); |
753 | } | 753 | } |
754 | else | 754 | else |
755 | switch (i) | 755 | switch (i) |
756 | { | 756 | { |
757 | case 1: return i18n("January"); | 757 | case 1: return i18n("January"); |
758 | case 2: return i18n("February"); | 758 | case 2: return i18n("February"); |
759 | case 3: return i18n("March"); | 759 | case 3: return i18n("March"); |
760 | case 4: return i18n("April"); | 760 | case 4: return i18n("April"); |
761 | case 5: return i18n("May long", "May"); | 761 | case 5: return i18n("May long", "May"); |
762 | case 6: return i18n("June"); | 762 | case 6: return i18n("June"); |
763 | case 7: return i18n("July"); | 763 | case 7: return i18n("July"); |
764 | case 8: return i18n("August"); | 764 | case 8: return i18n("August"); |
765 | case 9: return i18n("September"); | 765 | case 9: return i18n("September"); |
766 | case 10: return i18n("October"); | 766 | case 10: return i18n("October"); |
767 | case 11: return i18n("November"); | 767 | case 11: return i18n("November"); |
768 | case 12: return i18n("December"); | 768 | case 12: return i18n("December"); |
769 | } | 769 | } |
770 | 770 | ||
771 | return QString::null; | 771 | return QString::null; |
772 | } | 772 | } |
773 | 773 | ||
774 | QString KLocale::country() const | 774 | QString KLocale::country() const |
775 | { | 775 | { |
776 | return QString::null; | 776 | return QString::null; |
777 | } | 777 | } |
778 | 778 | ||
779 | QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const | 779 | QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const |
780 | { | 780 | { |
781 | const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; | 781 | const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; |
782 | 782 | ||
783 | if ( dformat == ISODate ) | 783 | if ( dformat == ISODate ) |
784 | return "%Y-%m-%d"; | 784 | return "%Y-%m-%d"; |
785 | 785 | ||
786 | if ( QApplication::desktop()->width() < 480 ) { | 786 | if ( QApplication::desktop()->width() < 480 ) { |
787 | if ( dformat == Default ) | 787 | if ( dformat == Default ) |
788 | return "%a %d %b %Y"; | 788 | return "%a %d %b %Y"; |
789 | else if ( dformat == Format1 ) | 789 | else if ( dformat == Format1 ) |
790 | return "%a %b %d %Y"; | 790 | return "%a %b %d %Y"; |
791 | } else { | 791 | } else { |
792 | if ( dformat == Default ) | 792 | if ( dformat == Default ) |
793 | return "%A %d %B %Y"; | 793 | return "%A %d %B %Y"; |
794 | else if ( dformat == Format1 ) | 794 | else if ( dformat == Format1 ) |
795 | return "%A %B %d %Y"; | 795 | return "%A %B %d %Y"; |
796 | 796 | ||
797 | } | 797 | } |
798 | return mDateFormat ; | 798 | return mDateFormat ; |
799 | } | 799 | } |
800 | 800 | ||
801 | QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const | 801 | QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const |
802 | { | 802 | { |
803 | const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; | 803 | const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; |
804 | 804 | ||
805 | if ( dformat == Default ) | 805 | if ( dformat == Default ) |
806 | return "%d.%m.%Y"; | 806 | return "%d.%m.%Y"; |
807 | else if ( dformat == Format1 ) | 807 | else if ( dformat == Format1 ) |
808 | return "%m.%d.%Y"; | 808 | return "%m.%d.%Y"; |
809 | else if ( dformat == ISODate ) // = Qt::ISODate | 809 | else if ( dformat == ISODate ) // = Qt::ISODate |
810 | return "%Y-%m-%d"; | 810 | return "%Y-%m-%d"; |
811 | return mDateFormatShort ; | 811 | return mDateFormatShort ; |
812 | 812 | ||
813 | } | 813 | } |
814 | 814 | ||
815 | 815 | ||
816 | QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const | 816 | QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const |
817 | { | 817 | { |
818 | const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat; | 818 | const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat; |
819 | 819 | ||
820 | if ( tformat == Default ) | 820 | if ( tformat == Default ) |
821 | if ( mHourF24Format) | 821 | if ( mHourF24Format) |
822 | return "%H:%M:%S"; | 822 | return "%H:%M:%S"; |
823 | else | 823 | else |
824 | return "%I:%M:%S%p"; | 824 | return "%I:%M:%S%p"; |
825 | 825 | ||
826 | else if ( tformat == Format1 ) | 826 | else if ( tformat == Format1 ) |
827 | if ( mHourF24Format) | 827 | if ( mHourF24Format) |
828 | return "%H:%M:%S"; | 828 | return "%H:%M:%S"; |
829 | else | 829 | else |
830 | return "%I:%M:%S%p"; | 830 | return "%I:%M:%S%p"; |
831 | 831 | ||
832 | else if ( tformat == ISODate ) // = Qt::ISODate | 832 | else if ( tformat == ISODate ) // = Qt::ISODate |
833 | if ( mHourF24Format) | 833 | if ( mHourF24Format) |
834 | return "%H:%M:%S"; | 834 | return "%H:%M:%S"; |
835 | else | 835 | else |
836 | return "%I:%M:%S%p"; | 836 | return "%I:%M:%S%p"; |
837 | 837 | ||
838 | } | 838 | } |
839 | 839 | ||
840 | void KLocale::insertCatalogue ( const QString & ) | 840 | void KLocale::insertCatalogue ( const QString & ) |
841 | { | 841 | { |
842 | } | 842 | } |
843 | 843 | ||
844 | KCalendarSystem *KLocale::calendar() | 844 | KCalendarSystem *KLocale::calendar() |
845 | { | 845 | { |
846 | if ( !mCalendarSystem ) { | 846 | if ( !mCalendarSystem ) { |
847 | mCalendarSystem = new KCalendarSystemGregorian; | 847 | mCalendarSystem = new KCalendarSystemGregorian; |
848 | } | 848 | } |
849 | 849 | ||
850 | return mCalendarSystem; | 850 | return mCalendarSystem; |
851 | } | 851 | } |
852 | 852 | ||
853 | int KLocale::timezoneOffset( QString timeZone ) | 853 | int KLocale::timezoneOffset( QString timeZone ) |
854 | { | 854 | { |
855 | int ret = 1001; | 855 | int ret = 1001; |
856 | int index = mTimeZoneList.findIndex( timeZone ); | 856 | int index = mTimeZoneList.findIndex( timeZone ); |
857 | if ( index < 24 ) | 857 | if ( index < 24 ) |
858 | ret = ( index-11 ) * 60 ; | 858 | ret = ( index-11 ) * 60 ; |
859 | return ret; | 859 | return ret; |
860 | } | 860 | } |
861 | 861 | ||
862 | QStringList KLocale::timeZoneList() const | 862 | QStringList KLocale::timeZoneList() const |
863 | { | 863 | { |
864 | return mTimeZoneList; | 864 | return mTimeZoneList; |
865 | } | 865 | } |
866 | void KLocale::setTimezone( const QString &timeZone, bool oddTZ ) | 866 | void KLocale::setTimezone( const QString &timeZone, bool oddTZ ) |
867 | { | 867 | { |
868 | mTimeZoneOffset = timezoneOffset( timeZone ); | 868 | mTimeZoneOffset = timezoneOffset( timeZone ); |
869 | if ( oddTZ ) | 869 | if ( oddTZ ) |
870 | mTimeZoneOffset += 30; | 870 | mTimeZoneOffset += 30; |
871 | } | 871 | } |
872 | 872 | ||
873 | void KLocale::setDaylightSaving( bool b, int start , int end ) | 873 | void KLocale::setDaylightSaving( bool b, int start , int end ) |
874 | { | 874 | { |
875 | daylightEnabled = b; | 875 | daylightEnabled = b; |
876 | daylightStart = start; | 876 | daylightStart = start; |
877 | daylightEnd = end; | 877 | daylightEnd = end; |
878 | mSouthDaylight = (end < start); | 878 | mSouthDaylight = (end < start); |
879 | // qDebug("klocale daylight %d %d %d ", b, start , end ); | 879 | // qDebug("klocale daylight %d %d %d ", b, start , end ); |
880 | } | 880 | } |
881 | 881 | ||
882 | int KLocale::localTimeOffset( const QDateTime &dt ) | 882 | int KLocale::localTimeOffset( const QDateTime &dt ) |
883 | { | 883 | { |
884 | bool addDaylight = false; | 884 | bool addDaylight = false; |
885 | if ( daylightEnabled ) { | 885 | if ( daylightEnabled ) { |
886 | int d_end, d_start; | 886 | int d_end, d_start; |
887 | int dayofyear = dt.date().dayOfYear(); | 887 | int dayofyear = dt.date().dayOfYear(); |
888 | int year = dt.date().year(); | 888 | int year = dt.date().year(); |
889 | int add = 0; | 889 | int add = 0; |
890 | if ( QDate::leapYear(year) ) | 890 | if ( QDate::leapYear(year) ) |
891 | add = 1; | 891 | add = 1; |
892 | QDate date ( year,1,1 ); | 892 | QDate date ( year,1,1 ); |
893 | if ( daylightEnd > 59 ) | 893 | if ( daylightEnd > 59 ) |
894 | d_end = daylightEnd +add; | 894 | d_end = daylightEnd +add; |
895 | else | 895 | else |
896 | d_end = daylightEnd; | 896 | d_end = daylightEnd; |
897 | if ( daylightStart > 59 ) | 897 | if ( daylightStart > 59 ) |
898 | d_start = daylightStart +add; | 898 | d_start = daylightStart +add; |
899 | else | 899 | else |
900 | d_start = daylightStart; | 900 | d_start = daylightStart; |
901 | QDate s_date = date.addDays( d_start -1 ); | 901 | QDate s_date = date.addDays( d_start -1 ); |
902 | QDate e_date = date.addDays( d_end -1 ); | 902 | QDate e_date = date.addDays( d_end -1 ); |
903 | int dof = s_date.dayOfWeek(); | 903 | int dof = s_date.dayOfWeek(); |
904 | if ( dof < 7 ) | 904 | if ( dof < 7 ) |
905 | s_date = s_date.addDays( -dof ); | 905 | s_date = s_date.addDays( -dof ); |
906 | dof = e_date.dayOfWeek(); | 906 | dof = e_date.dayOfWeek(); |
907 | if ( dof < 7 ) | 907 | if ( dof < 7 ) |
908 | e_date = e_date.addDays( -dof ); | 908 | e_date = e_date.addDays( -dof ); |
909 | QTime startTime ( 3,0,0 ); | 909 | QTime startTime ( 3,0,0 ); |
910 | QDateTime startDt( s_date, startTime ); | 910 | QDateTime startDt( s_date, startTime ); |
911 | QDateTime endDt( e_date, startTime ); | 911 | QDateTime endDt( e_date, startTime ); |
912 | //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( )); | 912 | //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( )); |
913 | if ( mSouthDaylight ) { | 913 | if ( mSouthDaylight ) { |
914 | if ( ! ( endDt < dt && dt < startDt) ) | 914 | if ( ! ( endDt < dt && dt < startDt) ) |
915 | addDaylight = true; | 915 | addDaylight = true; |
916 | } else { | 916 | } else { |
917 | if ( startDt < dt && dt < endDt ) | 917 | if ( startDt < dt && dt < endDt ) |
918 | addDaylight = true; | 918 | addDaylight = true; |
919 | 919 | ||
920 | 920 | ||
921 | } | 921 | } |
922 | } | 922 | } |
923 | int addMin = 0; | 923 | int addMin = 0; |
924 | if ( addDaylight ) | 924 | if ( addDaylight ) |
925 | addMin = 60; | 925 | addMin = 60; |
926 | return mTimeZoneOffset + addMin; | 926 | return mTimeZoneOffset + addMin; |
927 | } | 927 | } |
928 | // ****************************************************************** | 928 | // ****************************************************************** |
929 | // added LR | 929 | // added LR |
930 | QString KLocale::formatNumber(double num, int precision) const | 930 | QString KLocale::formatNumber(double num, int precision) const |
931 | { | 931 | { |
932 | bool neg = num < 0; | 932 | bool neg = num < 0; |
933 | if (precision == -1) precision = 2; | 933 | if (precision == -1) precision = 2; |
934 | QString res = QString::number(neg?-num:num, 'f', precision); | 934 | QString res = QString::number(neg?-num:num, 'f', precision); |
935 | int pos = res.find('.'); | 935 | int pos = res.find('.'); |
936 | if (pos == -1) pos = res.length(); | 936 | if (pos == -1) pos = res.length(); |
937 | else res.replace(pos, 1, decimalSymbol()); | 937 | else res.replace(pos, 1, decimalSymbol()); |
938 | 938 | ||
939 | while (0 < (pos -= 3)) | 939 | while (0 < (pos -= 3)) |
940 | res.insert(pos, thousandsSeparator()); // thousand sep | 940 | res.insert(pos, thousandsSeparator()); // thousand sep |
941 | 941 | ||
942 | // How can we know where we should put the sign? | 942 | // How can we know where we should put the sign? |
943 | res.prepend(neg?negativeSign():positiveSign()); | 943 | res.prepend(neg?negativeSign():positiveSign()); |
944 | 944 | ||
945 | return res; | 945 | return res; |
946 | } | 946 | } |
947 | QString KLocale::formatNumber(const QString &numStr) const | 947 | QString KLocale::formatNumber(const QString &numStr) const |
948 | { | 948 | { |
949 | return formatNumber(numStr.toDouble()); | 949 | return formatNumber(numStr.toDouble()); |
950 | } | 950 | } |
951 | double KLocale::readNumber(const QString &_str, bool * ok) const | 951 | double KLocale::readNumber(const QString &_str, bool * ok) const |
952 | { | 952 | { |
953 | QString str = _str.stripWhiteSpace(); | 953 | QString str = _str.stripWhiteSpace(); |
954 | bool neg = str.find(negativeSign()) == 0; | 954 | bool neg = str.find(negativeSign()) == 0; |
955 | if (neg) | 955 | if (neg) |
956 | str.remove( 0, negativeSign().length() ); | 956 | str.remove( 0, negativeSign().length() ); |
957 | 957 | ||
958 | /* will hold the scientific notation portion of the number. | 958 | /* will hold the scientific notation portion of the number. |
959 | Example, with 2.34E+23, exponentialPart == "E+23" | 959 | Example, with 2.34E+23, exponentialPart == "E+23" |
960 | */ | 960 | */ |
961 | QString exponentialPart; | 961 | QString exponentialPart; |
962 | int EPos; | 962 | int EPos; |
963 | 963 | ||
964 | EPos = str.find('E', 0, false); | 964 | EPos = str.find('E', 0, false); |
965 | 965 | ||
966 | if (EPos != -1) | 966 | if (EPos != -1) |
967 | { | 967 | { |
968 | exponentialPart = str.mid(EPos); | 968 | exponentialPart = str.mid(EPos); |
969 | str = str.left(EPos); | 969 | str = str.left(EPos); |
970 | } | 970 | } |
971 | 971 | ||
972 | int pos = str.find(decimalSymbol()); | 972 | int pos = str.find(decimalSymbol()); |
973 | QString major; | 973 | QString major; |
974 | QString minor; | 974 | QString minor; |
975 | if ( pos == -1 ) | 975 | if ( pos == -1 ) |
976 | major = str; | 976 | major = str; |
977 | else | 977 | else |
978 | { | 978 | { |
979 | major = str.left(pos); | 979 | major = str.left(pos); |
980 | minor = str.mid(pos + decimalSymbol().length()); | 980 | minor = str.mid(pos + decimalSymbol().length()); |
981 | } | 981 | } |
982 | 982 | ||
983 | // Remove thousand separators | 983 | // Remove thousand separators |
984 | int thlen = thousandsSeparator().length(); | 984 | int thlen = thousandsSeparator().length(); |
985 | int lastpos = 0; | 985 | int lastpos = 0; |
986 | while ( ( pos = major.find( thousandsSeparator() ) ) > 0 ) | 986 | while ( ( pos = major.find( thousandsSeparator() ) ) > 0 ) |
987 | { | 987 | { |
988 | // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N | 988 | // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N |
989 | int fromEnd = major.length() - pos; | 989 | int fromEnd = major.length() - pos; |
990 | if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error | 990 | if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error |
991 | || pos - lastpos > 3 // More than 3 digits between two separators -> error | 991 | || pos - lastpos > 3 // More than 3 digits between two separators -> error |
992 | || pos == 0 // Can't start with a separator | 992 | || pos == 0 // Can't start with a separator |
993 | || (lastpos>0 && pos-lastpos!=3)) // Must have exactly 3 digits between two separators | 993 | || (lastpos>0 && pos-lastpos!=3)) // Must have exactly 3 digits between two separators |
994 | { | 994 | { |
995 | if (ok) *ok = false; | 995 | if (ok) *ok = false; |
996 | return 0.0; | 996 | return 0.0; |
997 | } | 997 | } |
998 | 998 | ||
999 | lastpos = pos; | 999 | lastpos = pos; |
1000 | major.remove( pos, thlen ); | 1000 | major.remove( pos, thlen ); |
1001 | } | 1001 | } |
1002 | if (lastpos>0 && major.length()-lastpos!=3) // Must have exactly 3 digits after the last separator | 1002 | if (lastpos>0 && major.length()-lastpos!=3) // Must have exactly 3 digits after the last separator |
1003 | { | 1003 | { |
1004 | if (ok) *ok = false; | 1004 | if (ok) *ok = false; |
1005 | return 0.0; | 1005 | return 0.0; |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | QString tot; | 1008 | QString tot; |
1009 | if (neg) tot = '-'; | 1009 | if (neg) tot = '-'; |
1010 | 1010 | ||
1011 | tot += major + '.' + minor + exponentialPart; | 1011 | tot += major + '.' + minor + exponentialPart; |
1012 | 1012 | ||
1013 | return tot.toDouble(ok); | 1013 | return tot.toDouble(ok); |
1014 | } | 1014 | } |
1015 | QString KLocale::decimalSymbol() const | 1015 | QString KLocale::decimalSymbol() const |
1016 | { | 1016 | { |
1017 | 1017 | ||
1018 | return m_decimalSymbol; | 1018 | return m_decimalSymbol; |
1019 | } | 1019 | } |
1020 | 1020 | ||
1021 | QString KLocale::thousandsSeparator() const | 1021 | QString KLocale::thousandsSeparator() const |
1022 | { | 1022 | { |
1023 | 1023 | ||
1024 | return m_thousandsSeparator; | 1024 | return m_thousandsSeparator; |
1025 | } | 1025 | } |
1026 | QString KLocale::positiveSign() const | 1026 | QString KLocale::positiveSign() const |
1027 | { | 1027 | { |
1028 | return m_positiveSign; | 1028 | return m_positiveSign; |
1029 | } | 1029 | } |
1030 | 1030 | ||
1031 | QString KLocale::negativeSign() const | 1031 | QString KLocale::negativeSign() const |
1032 | { | 1032 | { |
1033 | return m_negativeSign; | 1033 | return m_negativeSign; |
1034 | } | 1034 | } |