-rw-r--r-- | microkde/kdecore/klocale.cpp | 17 | ||||
-rw-r--r-- | microkde/kdecore/klocale.h | 2 |
2 files changed, 19 insertions, 0 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp index 17031c7..8b4513e 100644 --- a/microkde/kdecore/klocale.cpp +++ b/microkde/kdecore/klocale.cpp | |||
@@ -235,727 +235,744 @@ QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat | |||
235 | case 'p': | 235 | case 'p': |
236 | { | 236 | { |
237 | QString s; | 237 | QString s; |
238 | if ( pTime.hour() >= 12 ) | 238 | if ( pTime.hour() >= 12 ) |
239 | put_it_in( buffer, index, i18n("pm") ); | 239 | put_it_in( buffer, index, i18n("pm") ); |
240 | else | 240 | else |
241 | put_it_in( buffer, index, i18n("am") ); | 241 | put_it_in( buffer, index, i18n("am") ); |
242 | break; | 242 | break; |
243 | } | 243 | } |
244 | default: | 244 | default: |
245 | buffer[index++] = rst.at( format_index ); | 245 | buffer[index++] = rst.at( format_index ); |
246 | break; | 246 | break; |
247 | } | 247 | } |
248 | escape = false; | 248 | escape = false; |
249 | } | 249 | } |
250 | } | 250 | } |
251 | QString ret( buffer, index ); | 251 | QString ret( buffer, index ); |
252 | delete [] buffer; | 252 | delete [] buffer; |
253 | return ret; | 253 | return ret; |
254 | } | 254 | } |
255 | 255 | ||
256 | QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const | 256 | QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const |
257 | { | 257 | { |
258 | const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); | 258 | const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); |
259 | 259 | ||
260 | // I'm rather safe than sorry | 260 | // I'm rather safe than sorry |
261 | QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; | 261 | QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; |
262 | 262 | ||
263 | unsigned int index = 0; | 263 | unsigned int index = 0; |
264 | bool escape = false; | 264 | bool escape = false; |
265 | int number = 0; | 265 | int number = 0; |
266 | 266 | ||
267 | for ( uint format_index = 0; format_index < rst.length(); ++format_index ) | 267 | for ( uint format_index = 0; format_index < rst.length(); ++format_index ) |
268 | { | 268 | { |
269 | if ( !escape ) | 269 | if ( !escape ) |
270 | { | 270 | { |
271 | if ( rst.at( format_index ).unicode() == '%' ) | 271 | if ( rst.at( format_index ).unicode() == '%' ) |
272 | escape = true; | 272 | escape = true; |
273 | else | 273 | else |
274 | buffer[index++] = rst.at( format_index ); | 274 | buffer[index++] = rst.at( format_index ); |
275 | } | 275 | } |
276 | else | 276 | else |
277 | { | 277 | { |
278 | switch ( rst.at( format_index ).unicode() ) | 278 | switch ( rst.at( format_index ).unicode() ) |
279 | { | 279 | { |
280 | case '%': | 280 | case '%': |
281 | buffer[index++] = '%'; | 281 | buffer[index++] = '%'; |
282 | break; | 282 | break; |
283 | case 'Y': | 283 | case 'Y': |
284 | put_it_in( buffer, index, pDate.year() / 100 ); | 284 | put_it_in( buffer, index, pDate.year() / 100 ); |
285 | case 'y': | 285 | case 'y': |
286 | put_it_in( buffer, index, pDate.year() % 100 ); | 286 | put_it_in( buffer, index, pDate.year() % 100 ); |
287 | break; | 287 | break; |
288 | case 'n': | 288 | case 'n': |
289 | number = pDate.month(); | 289 | number = pDate.month(); |
290 | case 'e': | 290 | case 'e': |
291 | // to share the code | 291 | // to share the code |
292 | if ( rst.at( format_index ).unicode() == 'e' ) | 292 | if ( rst.at( format_index ).unicode() == 'e' ) |
293 | number = pDate.day(); | 293 | number = pDate.day(); |
294 | if ( number / 10 ) | 294 | if ( number / 10 ) |
295 | buffer[index++] = number / 10 + '0'; | 295 | buffer[index++] = number / 10 + '0'; |
296 | buffer[index++] = number % 10 + '0'; | 296 | buffer[index++] = number % 10 + '0'; |
297 | break; | 297 | break; |
298 | case 'm': | 298 | case 'm': |
299 | put_it_in( buffer, index, pDate.month() ); | 299 | put_it_in( buffer, index, pDate.month() ); |
300 | break; | 300 | break; |
301 | case 'b': | 301 | case 'b': |
302 | put_it_in( buffer, index, monthName(pDate.month(), true) ); | 302 | put_it_in( buffer, index, monthName(pDate.month(), true) ); |
303 | break; | 303 | break; |
304 | case 'B': | 304 | case 'B': |
305 | put_it_in( buffer, index, monthName(pDate.month(), false) ); | 305 | put_it_in( buffer, index, monthName(pDate.month(), false) ); |
306 | break; | 306 | break; |
307 | case 'd': | 307 | case 'd': |
308 | put_it_in( buffer, index, pDate.day() ); | 308 | put_it_in( buffer, index, pDate.day() ); |
309 | break; | 309 | break; |
310 | case 'a': | 310 | case 'a': |
311 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); | 311 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); |
312 | break; | 312 | break; |
313 | case 'A': | 313 | case 'A': |
314 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); | 314 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); |
315 | break; | 315 | break; |
316 | default: | 316 | default: |
317 | buffer[index++] = rst.at( format_index ); | 317 | buffer[index++] = rst.at( format_index ); |
318 | break; | 318 | break; |
319 | } | 319 | } |
320 | escape = false; | 320 | escape = false; |
321 | } | 321 | } |
322 | } | 322 | } |
323 | QString ret( buffer, index ); | 323 | QString ret( buffer, index ); |
324 | delete [] buffer; | 324 | delete [] buffer; |
325 | return ret; | 325 | return ret; |
326 | } | 326 | } |
327 | 327 | ||
328 | QString KLocale::formatDateTime(const QDateTime &pDateTime, | 328 | QString KLocale::formatDateTime(const QDateTime &pDateTime, |
329 | bool shortFormat, | 329 | bool shortFormat, |
330 | bool includeSeconds, | 330 | bool includeSeconds, |
331 | IntDateFormat intIntDateFormat) const | 331 | IntDateFormat intIntDateFormat) const |
332 | { | 332 | { |
333 | QString format("%1 %2"); | 333 | QString format("%1 %2"); |
334 | 334 | ||
335 | if ( intIntDateFormat == Default ) | 335 | if ( intIntDateFormat == Default ) |
336 | format = "%1 %2"; | 336 | format = "%1 %2"; |
337 | else if ( intIntDateFormat == Format1 ) | 337 | else if ( intIntDateFormat == Format1 ) |
338 | format = "%1 %2"; | 338 | format = "%1 %2"; |
339 | else if ( intIntDateFormat == ISODate ) | 339 | else if ( intIntDateFormat == ISODate ) |
340 | format = "%1T%2"; | 340 | format = "%1T%2"; |
341 | 341 | ||
342 | return format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat )) | 342 | return format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat )) |
343 | .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat )); | 343 | .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat )); |
344 | } | 344 | } |
345 | 345 | ||
346 | QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const | 346 | QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const |
347 | { | 347 | { |
348 | return formatDateTime(pDateTime, true, true, intIntDateFormat); | 348 | return formatDateTime(pDateTime, true, true, intIntDateFormat); |
349 | } | 349 | } |
350 | 350 | ||
351 | QDate KLocale::readDate(const QString &intstr, bool* ok) const | 351 | QDate KLocale::readDate(const QString &intstr, bool* ok) const |
352 | { | 352 | { |
353 | QDate date; | 353 | QDate date; |
354 | date = readDate(intstr, true, ok); | 354 | date = readDate(intstr, true, ok); |
355 | if (date.isValid()) return date; | 355 | if (date.isValid()) return date; |
356 | return readDate(intstr, false, ok); | 356 | return readDate(intstr, false, ok); |
357 | } | 357 | } |
358 | 358 | ||
359 | QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const | 359 | QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const |
360 | { | 360 | { |
361 | QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); | 361 | QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); |
362 | return readDate( intstr, fmt, ok ); | 362 | return readDate( intstr, fmt, ok ); |
363 | } | 363 | } |
364 | 364 | ||
365 | QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const | 365 | QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const |
366 | { | 366 | { |
367 | //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; | 367 | //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; |
368 | QString str = intstr.simplifyWhiteSpace().lower(); | 368 | QString str = intstr.simplifyWhiteSpace().lower(); |
369 | int day = -1, month = -1; | 369 | int day = -1, month = -1; |
370 | // allow the year to be omitted if not in the format | 370 | // allow the year to be omitted if not in the format |
371 | int year = QDate::currentDate().year(); | 371 | int year = QDate::currentDate().year(); |
372 | uint strpos = 0; | 372 | uint strpos = 0; |
373 | uint fmtpos = 0; | 373 | uint fmtpos = 0; |
374 | 374 | ||
375 | while (fmt.length() > fmtpos || str.length() > strpos) | 375 | while (fmt.length() > fmtpos || str.length() > strpos) |
376 | { | 376 | { |
377 | if ( !(fmt.length() > fmtpos && str.length() > strpos) ) | 377 | if ( !(fmt.length() > fmtpos && str.length() > strpos) ) |
378 | goto error; | 378 | goto error; |
379 | 379 | ||
380 | QChar c = fmt.at(fmtpos++); | 380 | QChar c = fmt.at(fmtpos++); |
381 | 381 | ||
382 | if (c != '%') { | 382 | if (c != '%') { |
383 | if (c.isSpace()) | 383 | if (c.isSpace()) |
384 | strpos++; | 384 | strpos++; |
385 | else if (c != str.at(strpos++)) | 385 | else if (c != str.at(strpos++)) |
386 | goto error; | 386 | goto error; |
387 | continue; | 387 | continue; |
388 | } | 388 | } |
389 | 389 | ||
390 | // remove space at the begining | 390 | // remove space at the begining |
391 | if (str.length() > strpos && str.at(strpos).isSpace()) | 391 | if (str.length() > strpos && str.at(strpos).isSpace()) |
392 | strpos++; | 392 | strpos++; |
393 | 393 | ||
394 | c = fmt.at(fmtpos++); | 394 | c = fmt.at(fmtpos++); |
395 | switch (c) | 395 | switch (c) |
396 | { | 396 | { |
397 | case 'a': | 397 | case 'a': |
398 | case 'A': | 398 | case 'A': |
399 | // this will just be ignored | 399 | // this will just be ignored |
400 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition | 400 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition |
401 | for (int j = 1; j < 8; j++) { | 401 | for (int j = 1; j < 8; j++) { |
402 | QString s = weekDayName(j, c == 'a').lower(); | 402 | QString s = weekDayName(j, c == 'a').lower(); |
403 | int len = s.length(); | 403 | int len = s.length(); |
404 | if (str.mid(strpos, len) == s) | 404 | if (str.mid(strpos, len) == s) |
405 | strpos += len; | 405 | strpos += len; |
406 | } | 406 | } |
407 | break; | 407 | break; |
408 | } | 408 | } |
409 | case 'b': | 409 | case 'b': |
410 | case 'B': | 410 | case 'B': |
411 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition | 411 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition |
412 | for (int j = 1; j < 13; j++) { | 412 | for (int j = 1; j < 13; j++) { |
413 | QString s = monthName(j, c == 'b').lower(); | 413 | QString s = monthName(j, c == 'b').lower(); |
414 | int len = s.length(); | 414 | int len = s.length(); |
415 | if (str.mid(strpos, len) == s) { | 415 | if (str.mid(strpos, len) == s) { |
416 | month = j; | 416 | month = j; |
417 | strpos += len; | 417 | strpos += len; |
418 | } | 418 | } |
419 | } | 419 | } |
420 | break; | 420 | break; |
421 | } | 421 | } |
422 | case 'd': | 422 | case 'd': |
423 | case 'e': | 423 | case 'e': |
424 | day = readInt(str, strpos); | 424 | day = readInt(str, strpos); |
425 | if (day < 1 || day > 31) | 425 | if (day < 1 || day > 31) |
426 | goto error; | 426 | goto error; |
427 | 427 | ||
428 | break; | 428 | break; |
429 | 429 | ||
430 | case 'n': | 430 | case 'n': |
431 | case 'm': | 431 | case 'm': |
432 | month = readInt(str, strpos); | 432 | month = readInt(str, strpos); |
433 | if (month < 1 || month > 12) | 433 | if (month < 1 || month > 12) |
434 | goto error; | 434 | goto error; |
435 | 435 | ||
436 | break; | 436 | break; |
437 | 437 | ||
438 | case 'Y': | 438 | case 'Y': |
439 | case 'y': | 439 | case 'y': |
440 | year = readInt(str, strpos); | 440 | year = readInt(str, strpos); |
441 | if (year < 0) | 441 | if (year < 0) |
442 | goto error; | 442 | goto error; |
443 | // Qt treats a year in the range 0-100 as 1900-1999. | 443 | // Qt treats a year in the range 0-100 as 1900-1999. |
444 | // It is nicer for the user if we treat 0-68 as 2000-2068 | 444 | // It is nicer for the user if we treat 0-68 as 2000-2068 |
445 | if (year < 69) | 445 | if (year < 69) |
446 | year += 2000; | 446 | year += 2000; |
447 | else if (c == 'y') | 447 | else if (c == 'y') |
448 | year += 1900; | 448 | year += 1900; |
449 | 449 | ||
450 | break; | 450 | break; |
451 | } | 451 | } |
452 | } | 452 | } |
453 | //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; | 453 | //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; |
454 | if ( year != -1 && month != -1 && day != -1 ) | 454 | if ( year != -1 && month != -1 && day != -1 ) |
455 | { | 455 | { |
456 | if (ok) *ok = true; | 456 | if (ok) *ok = true; |
457 | return QDate(year, month, day); | 457 | return QDate(year, month, day); |
458 | } | 458 | } |
459 | error: | 459 | error: |
460 | if (ok) *ok = false; | 460 | if (ok) *ok = false; |
461 | return QDate(); // invalid date | 461 | return QDate(); // invalid date |
462 | } | 462 | } |
463 | 463 | ||
464 | QTime KLocale::readTime(const QString &intstr, bool *ok) const | 464 | QTime KLocale::readTime(const QString &intstr, bool *ok) const |
465 | { | 465 | { |
466 | QTime _time; | 466 | QTime _time; |
467 | _time = readTime(intstr, true, ok); | 467 | _time = readTime(intstr, true, ok); |
468 | if (_time.isValid()) return _time; | 468 | if (_time.isValid()) return _time; |
469 | return readTime(intstr, false, ok); | 469 | return readTime(intstr, false, ok); |
470 | } | 470 | } |
471 | 471 | ||
472 | QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const | 472 | QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const |
473 | { | 473 | { |
474 | QString str = intstr.simplifyWhiteSpace().lower(); | 474 | QString str = intstr.simplifyWhiteSpace().lower(); |
475 | QString Format = timeFormat().simplifyWhiteSpace(); | 475 | QString Format = timeFormat().simplifyWhiteSpace(); |
476 | if (!seconds) | 476 | if (!seconds) |
477 | Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); | 477 | Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); |
478 | 478 | ||
479 | int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds | 479 | int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds |
480 | 480 | ||
481 | bool g_12h = false; | 481 | bool g_12h = false; |
482 | bool pm = false; | 482 | bool pm = false; |
483 | uint strpos = 0; | 483 | uint strpos = 0; |
484 | uint Formatpos = 0; | 484 | uint Formatpos = 0; |
485 | 485 | ||
486 | while (Format.length() > Formatpos || str.length() > strpos) | 486 | while (Format.length() > Formatpos || str.length() > strpos) |
487 | { | 487 | { |
488 | if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; | 488 | if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; |
489 | 489 | ||
490 | QChar c = Format.at(Formatpos++); | 490 | QChar c = Format.at(Formatpos++); |
491 | 491 | ||
492 | if (c != '%') | 492 | if (c != '%') |
493 | { | 493 | { |
494 | if (c.isSpace()) | 494 | if (c.isSpace()) |
495 | strpos++; | 495 | strpos++; |
496 | else if (c != str.at(strpos++)) | 496 | else if (c != str.at(strpos++)) |
497 | goto error; | 497 | goto error; |
498 | continue; | 498 | continue; |
499 | } | 499 | } |
500 | 500 | ||
501 | // remove space at the begining | 501 | // remove space at the begining |
502 | if (str.length() > strpos && str.at(strpos).isSpace()) | 502 | if (str.length() > strpos && str.at(strpos).isSpace()) |
503 | strpos++; | 503 | strpos++; |
504 | 504 | ||
505 | c = Format.at(Formatpos++); | 505 | c = Format.at(Formatpos++); |
506 | switch (c) | 506 | switch (c) |
507 | { | 507 | { |
508 | case 'p': | 508 | case 'p': |
509 | { | 509 | { |
510 | QString s; | 510 | QString s; |
511 | s = i18n("pm").lower(); | 511 | s = i18n("pm").lower(); |
512 | int len = s.length(); | 512 | int len = s.length(); |
513 | if (str.mid(strpos, len) == s) | 513 | if (str.mid(strpos, len) == s) |
514 | { | 514 | { |
515 | pm = true; | 515 | pm = true; |
516 | strpos += len; | 516 | strpos += len; |
517 | } | 517 | } |
518 | else | 518 | else |
519 | { | 519 | { |
520 | s = i18n("am").lower(); | 520 | s = i18n("am").lower(); |
521 | len = s.length(); | 521 | len = s.length(); |
522 | if (str.mid(strpos, len) == s) { | 522 | if (str.mid(strpos, len) == s) { |
523 | pm = false; | 523 | pm = false; |
524 | strpos += len; | 524 | strpos += len; |
525 | } | 525 | } |
526 | else | 526 | else |
527 | goto error; | 527 | goto error; |
528 | } | 528 | } |
529 | } | 529 | } |
530 | break; | 530 | break; |
531 | 531 | ||
532 | case 'k': | 532 | case 'k': |
533 | case 'H': | 533 | case 'H': |
534 | g_12h = false; | 534 | g_12h = false; |
535 | hour = readInt(str, strpos); | 535 | hour = readInt(str, strpos); |
536 | if (hour < 0 || hour > 23) | 536 | if (hour < 0 || hour > 23) |
537 | goto error; | 537 | goto error; |
538 | 538 | ||
539 | break; | 539 | break; |
540 | 540 | ||
541 | case 'l': | 541 | case 'l': |
542 | case 'I': | 542 | case 'I': |
543 | g_12h = true; | 543 | g_12h = true; |
544 | hour = readInt(str, strpos); | 544 | hour = readInt(str, strpos); |
545 | if (hour < 1 || hour > 12) | 545 | if (hour < 1 || hour > 12) |
546 | goto error; | 546 | goto error; |
547 | 547 | ||
548 | break; | 548 | break; |
549 | 549 | ||
550 | case 'M': | 550 | case 'M': |
551 | minute = readInt(str, strpos); | 551 | minute = readInt(str, strpos); |
552 | if (minute < 0 || minute > 59) | 552 | if (minute < 0 || minute > 59) |
553 | goto error; | 553 | goto error; |
554 | 554 | ||
555 | break; | 555 | break; |
556 | 556 | ||
557 | case 'S': | 557 | case 'S': |
558 | second = readInt(str, strpos); | 558 | second = readInt(str, strpos); |
559 | if (second < 0 || second > 59) | 559 | if (second < 0 || second > 59) |
560 | goto error; | 560 | goto error; |
561 | 561 | ||
562 | break; | 562 | break; |
563 | } | 563 | } |
564 | } | 564 | } |
565 | if (g_12h) | 565 | if (g_12h) |
566 | { | 566 | { |
567 | hour %= 12; | 567 | hour %= 12; |
568 | if (pm) hour += 12; | 568 | if (pm) hour += 12; |
569 | } | 569 | } |
570 | 570 | ||
571 | if (ok) *ok = true; | 571 | if (ok) *ok = true; |
572 | return QTime(hour, minute, second); | 572 | return QTime(hour, minute, second); |
573 | 573 | ||
574 | error: | 574 | error: |
575 | if (ok) *ok = false; | 575 | if (ok) *ok = false; |
576 | return QTime(-1, -1, -1); // return invalid date if it didn't work | 576 | return QTime(-1, -1, -1); // return invalid date if it didn't work |
577 | // This will be removed in the near future, since it gives a warning on stderr. | 577 | // This will be removed in the near future, since it gives a warning on stderr. |
578 | // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. | 578 | // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. |
579 | } | 579 | } |
580 | 580 | ||
581 | QDateTime KLocale::readDateTime(const QString &intstr, | 581 | QDateTime KLocale::readDateTime(const QString &intstr, |
582 | IntDateFormat intIntDateFormat, | 582 | IntDateFormat intIntDateFormat, |
583 | bool* ok) const | 583 | bool* ok) const |
584 | { | 584 | { |
585 | bool ok1, ok2; | 585 | bool ok1, ok2; |
586 | 586 | ||
587 | // AT the moment we can not read any other format then ISODate | 587 | // AT the moment we can not read any other format then ISODate |
588 | if ( intIntDateFormat != ISODate ) | 588 | if ( intIntDateFormat != ISODate ) |
589 | { | 589 | { |
590 | qDebug("KLocale::readDateTime, only ISODate is supported."); | 590 | qDebug("KLocale::readDateTime, only ISODate is supported."); |
591 | return QDateTime(); | 591 | return QDateTime(); |
592 | } | 592 | } |
593 | 593 | ||
594 | int pos = intstr.find("T"); | 594 | int pos = intstr.find("T"); |
595 | QString date = intstr.left(pos); | 595 | QString date = intstr.left(pos); |
596 | QString time = intstr.mid(pos+1); | 596 | QString time = intstr.mid(pos+1); |
597 | 597 | ||
598 | QString dformat = dateFormat(intIntDateFormat); | 598 | QString dformat = dateFormat(intIntDateFormat); |
599 | QString tformat = timeFormat(intIntDateFormat); | 599 | QString tformat = timeFormat(intIntDateFormat); |
600 | 600 | ||
601 | QDate m_date = readDate(date, dformat, &ok1); | 601 | QDate m_date = readDate(date, dformat, &ok1); |
602 | QTime m_time = readTime(time, tformat, &ok2); | 602 | QTime m_time = readTime(time, tformat, &ok2); |
603 | 603 | ||
604 | if (ok) | 604 | if (ok) |
605 | { | 605 | { |
606 | if ((ok1 == false) || (ok2 == false)) | 606 | if ((ok1 == false) || (ok2 == false)) |
607 | *ok = false; | 607 | *ok = false; |
608 | else | 608 | else |
609 | *ok = true; | 609 | *ok = true; |
610 | } | 610 | } |
611 | QDateTime m_dt; | 611 | QDateTime m_dt; |
612 | m_dt.setDate(m_date); | 612 | m_dt.setDate(m_date); |
613 | m_dt.setTime(m_time); | 613 | m_dt.setTime(m_time); |
614 | 614 | ||
615 | 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); | 615 | 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); |
616 | return m_dt; | 616 | return m_dt; |
617 | } | 617 | } |
618 | 618 | ||
619 | QDate KLocale::readDate(const QString &intstr, | ||
620 | IntDateFormat intIntDateFormat, | ||
621 | bool* ok) const | ||
622 | { | ||
623 | bool ok1; | ||
624 | |||
625 | QString dformat = dateFormat(intIntDateFormat); | ||
626 | |||
627 | QDate m_date = readDate(intstr, dformat, &ok1); | ||
628 | |||
629 | if (ok) | ||
630 | *ok = ok1; | ||
631 | |||
632 | //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); | ||
633 | return m_date; | ||
634 | } | ||
635 | |||
619 | 636 | ||
620 | bool KLocale::use12Clock() const | 637 | bool KLocale::use12Clock() const |
621 | { | 638 | { |
622 | return !mHourF24Format ;; | 639 | return !mHourF24Format ;; |
623 | } | 640 | } |
624 | 641 | ||
625 | bool KLocale::weekStartsMonday() const | 642 | bool KLocale::weekStartsMonday() const |
626 | { | 643 | { |
627 | return mWeekStartsMonday; | 644 | return mWeekStartsMonday; |
628 | } | 645 | } |
629 | 646 | ||
630 | int KLocale::weekStartDay() const | 647 | int KLocale::weekStartDay() const |
631 | { | 648 | { |
632 | if ( mWeekStartsMonday ) | 649 | if ( mWeekStartsMonday ) |
633 | return 1; | 650 | return 1; |
634 | return 7; | 651 | return 7; |
635 | } | 652 | } |
636 | 653 | ||
637 | QString KLocale::weekDayName(int i,bool shortName) const | 654 | QString KLocale::weekDayName(int i,bool shortName) const |
638 | { | 655 | { |
639 | if ( shortName ) | 656 | if ( shortName ) |
640 | switch ( i ) | 657 | switch ( i ) |
641 | { | 658 | { |
642 | case 1: return i18n("Monday", "Mon"); | 659 | case 1: return i18n("Monday", "Mon"); |
643 | case 2: return i18n("Tuesday", "Tue"); | 660 | case 2: return i18n("Tuesday", "Tue"); |
644 | case 3: return i18n("Wednesday", "Wed"); | 661 | case 3: return i18n("Wednesday", "Wed"); |
645 | case 4: return i18n("Thursday", "Thu"); | 662 | case 4: return i18n("Thursday", "Thu"); |
646 | case 5: return i18n("Friday", "Fri"); | 663 | case 5: return i18n("Friday", "Fri"); |
647 | case 6: return i18n("Saturday", "Sat"); | 664 | case 6: return i18n("Saturday", "Sat"); |
648 | case 7: return i18n("Sunday", "Sun"); | 665 | case 7: return i18n("Sunday", "Sun"); |
649 | } | 666 | } |
650 | else | 667 | else |
651 | switch ( i ) | 668 | switch ( i ) |
652 | { | 669 | { |
653 | case 1: return i18n("Monday"); | 670 | case 1: return i18n("Monday"); |
654 | case 2: return i18n("Tuesday"); | 671 | case 2: return i18n("Tuesday"); |
655 | case 3: return i18n("Wednesday"); | 672 | case 3: return i18n("Wednesday"); |
656 | case 4: return i18n("Thursday"); | 673 | case 4: return i18n("Thursday"); |
657 | case 5: return i18n("Friday"); | 674 | case 5: return i18n("Friday"); |
658 | case 6: return i18n("Saturday"); | 675 | case 6: return i18n("Saturday"); |
659 | case 7: return i18n("Sunday"); | 676 | case 7: return i18n("Sunday"); |
660 | } | 677 | } |
661 | 678 | ||
662 | return QString::null; | 679 | return QString::null; |
663 | } | 680 | } |
664 | 681 | ||
665 | QString KLocale::monthName(int i,bool shortName) const | 682 | QString KLocale::monthName(int i,bool shortName) const |
666 | { | 683 | { |
667 | if ( shortName ) | 684 | if ( shortName ) |
668 | switch ( i ) | 685 | switch ( i ) |
669 | { | 686 | { |
670 | case 1: return i18n("January", "Jan"); | 687 | case 1: return i18n("January", "Jan"); |
671 | case 2: return i18n("February", "Feb"); | 688 | case 2: return i18n("February", "Feb"); |
672 | case 3: return i18n("March", "Mar"); | 689 | case 3: return i18n("March", "Mar"); |
673 | case 4: return i18n("April", "Apr"); | 690 | case 4: return i18n("April", "Apr"); |
674 | case 5: return i18n("May short", "May"); | 691 | case 5: return i18n("May short", "May"); |
675 | case 6: return i18n("June", "Jun"); | 692 | case 6: return i18n("June", "Jun"); |
676 | case 7: return i18n("July", "Jul"); | 693 | case 7: return i18n("July", "Jul"); |
677 | case 8: return i18n("August", "Aug"); | 694 | case 8: return i18n("August", "Aug"); |
678 | case 9: return i18n("September", "Sep"); | 695 | case 9: return i18n("September", "Sep"); |
679 | case 10: return i18n("October", "Oct"); | 696 | case 10: return i18n("October", "Oct"); |
680 | case 11: return i18n("November", "Nov"); | 697 | case 11: return i18n("November", "Nov"); |
681 | case 12: return i18n("December", "Dec"); | 698 | case 12: return i18n("December", "Dec"); |
682 | } | 699 | } |
683 | else | 700 | else |
684 | switch (i) | 701 | switch (i) |
685 | { | 702 | { |
686 | case 1: return i18n("January"); | 703 | case 1: return i18n("January"); |
687 | case 2: return i18n("February"); | 704 | case 2: return i18n("February"); |
688 | case 3: return i18n("March"); | 705 | case 3: return i18n("March"); |
689 | case 4: return i18n("April"); | 706 | case 4: return i18n("April"); |
690 | case 5: return i18n("May long", "May"); | 707 | case 5: return i18n("May long", "May"); |
691 | case 6: return i18n("June"); | 708 | case 6: return i18n("June"); |
692 | case 7: return i18n("July"); | 709 | case 7: return i18n("July"); |
693 | case 8: return i18n("August"); | 710 | case 8: return i18n("August"); |
694 | case 9: return i18n("September"); | 711 | case 9: return i18n("September"); |
695 | case 10: return i18n("October"); | 712 | case 10: return i18n("October"); |
696 | case 11: return i18n("November"); | 713 | case 11: return i18n("November"); |
697 | case 12: return i18n("December"); | 714 | case 12: return i18n("December"); |
698 | } | 715 | } |
699 | 716 | ||
700 | return QString::null; | 717 | return QString::null; |
701 | } | 718 | } |
702 | 719 | ||
703 | QString KLocale::country() const | 720 | QString KLocale::country() const |
704 | { | 721 | { |
705 | return QString::null; | 722 | return QString::null; |
706 | } | 723 | } |
707 | 724 | ||
708 | QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const | 725 | QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const |
709 | { | 726 | { |
710 | const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; | 727 | const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; |
711 | 728 | ||
712 | if ( dformat == ISODate ) | 729 | if ( dformat == ISODate ) |
713 | return "%Y-%m-%d"; | 730 | return "%Y-%m-%d"; |
714 | 731 | ||
715 | if ( QApplication::desktop()->width() < 480 ) { | 732 | if ( QApplication::desktop()->width() < 480 ) { |
716 | if ( dformat == Default ) | 733 | if ( dformat == Default ) |
717 | return "%a %d %b %Y"; | 734 | return "%a %d %b %Y"; |
718 | else if ( dformat == Format1 ) | 735 | else if ( dformat == Format1 ) |
719 | return "%a %b %d %Y"; | 736 | return "%a %b %d %Y"; |
720 | } else { | 737 | } else { |
721 | if ( dformat == Default ) | 738 | if ( dformat == Default ) |
722 | return "%A %d %B %Y"; | 739 | return "%A %d %B %Y"; |
723 | else if ( dformat == Format1 ) | 740 | else if ( dformat == Format1 ) |
724 | return "%A %B %d %Y"; | 741 | return "%A %B %d %Y"; |
725 | 742 | ||
726 | } | 743 | } |
727 | return mDateFormat ; | 744 | return mDateFormat ; |
728 | } | 745 | } |
729 | 746 | ||
730 | QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const | 747 | QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const |
731 | { | 748 | { |
732 | const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; | 749 | const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; |
733 | 750 | ||
734 | if ( dformat == Default ) | 751 | if ( dformat == Default ) |
735 | return "%d.%m.%Y"; | 752 | return "%d.%m.%Y"; |
736 | else if ( dformat == Format1 ) | 753 | else if ( dformat == Format1 ) |
737 | return "%m.%d.%Y"; | 754 | return "%m.%d.%Y"; |
738 | else if ( dformat == ISODate ) // = Qt::ISODate | 755 | else if ( dformat == ISODate ) // = Qt::ISODate |
739 | return "%Y-%m-%d"; | 756 | return "%Y-%m-%d"; |
740 | return mDateFormatShort ; | 757 | return mDateFormatShort ; |
741 | 758 | ||
742 | } | 759 | } |
743 | 760 | ||
744 | 761 | ||
745 | QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const | 762 | QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const |
746 | { | 763 | { |
747 | const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat; | 764 | const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat; |
748 | 765 | ||
749 | if ( tformat == Default ) | 766 | if ( tformat == Default ) |
750 | if ( mHourF24Format) | 767 | if ( mHourF24Format) |
751 | return "%H:%M:%S"; | 768 | return "%H:%M:%S"; |
752 | else | 769 | else |
753 | return "%I:%M:%S%p"; | 770 | return "%I:%M:%S%p"; |
754 | 771 | ||
755 | else if ( tformat == Format1 ) | 772 | else if ( tformat == Format1 ) |
756 | if ( mHourF24Format) | 773 | if ( mHourF24Format) |
757 | return "%H:%M:%S"; | 774 | return "%H:%M:%S"; |
758 | else | 775 | else |
759 | return "%I:%M:%S%p"; | 776 | return "%I:%M:%S%p"; |
760 | 777 | ||
761 | else if ( tformat == ISODate ) // = Qt::ISODate | 778 | else if ( tformat == ISODate ) // = Qt::ISODate |
762 | if ( mHourF24Format) | 779 | if ( mHourF24Format) |
763 | return "%H:%M:%S"; | 780 | return "%H:%M:%S"; |
764 | else | 781 | else |
765 | return "%I:%M:%S%p"; | 782 | return "%I:%M:%S%p"; |
766 | 783 | ||
767 | } | 784 | } |
768 | 785 | ||
769 | void KLocale::insertCatalogue ( const QString & ) | 786 | void KLocale::insertCatalogue ( const QString & ) |
770 | { | 787 | { |
771 | } | 788 | } |
772 | 789 | ||
773 | KCalendarSystem *KLocale::calendar() | 790 | KCalendarSystem *KLocale::calendar() |
774 | { | 791 | { |
775 | if ( !mCalendarSystem ) { | 792 | if ( !mCalendarSystem ) { |
776 | mCalendarSystem = new KCalendarSystemGregorian; | 793 | mCalendarSystem = new KCalendarSystemGregorian; |
777 | } | 794 | } |
778 | 795 | ||
779 | return mCalendarSystem; | 796 | return mCalendarSystem; |
780 | } | 797 | } |
781 | 798 | ||
782 | int KLocale::timezoneOffset( QString timeZone ) | 799 | int KLocale::timezoneOffset( QString timeZone ) |
783 | { | 800 | { |
784 | int ret = 1001; | 801 | int ret = 1001; |
785 | int index = mTimeZoneList.findIndex( timeZone ); | 802 | int index = mTimeZoneList.findIndex( timeZone ); |
786 | if ( index < 24 ) | 803 | if ( index < 24 ) |
787 | ret = ( index-11 ) * 60 ; | 804 | ret = ( index-11 ) * 60 ; |
788 | return ret; | 805 | return ret; |
789 | } | 806 | } |
790 | 807 | ||
791 | QStringList KLocale::timeZoneList() const | 808 | QStringList KLocale::timeZoneList() const |
792 | { | 809 | { |
793 | return mTimeZoneList; | 810 | return mTimeZoneList; |
794 | } | 811 | } |
795 | void KLocale::setTimezone( const QString &timeZone ) | 812 | void KLocale::setTimezone( const QString &timeZone ) |
796 | { | 813 | { |
797 | mTimeZoneOffset = timezoneOffset( timeZone ); | 814 | mTimeZoneOffset = timezoneOffset( timeZone ); |
798 | } | 815 | } |
799 | 816 | ||
800 | void KLocale::setDaylightSaving( bool b, int start , int end ) | 817 | void KLocale::setDaylightSaving( bool b, int start , int end ) |
801 | { | 818 | { |
802 | daylightEnabled = b; | 819 | daylightEnabled = b; |
803 | daylightStart = start; | 820 | daylightStart = start; |
804 | daylightEnd = end; | 821 | daylightEnd = end; |
805 | mSouthDaylight = (end < start); | 822 | mSouthDaylight = (end < start); |
806 | // qDebug("klocale daylight %d %d %d ", b, start , end ); | 823 | // qDebug("klocale daylight %d %d %d ", b, start , end ); |
807 | } | 824 | } |
808 | 825 | ||
809 | int KLocale::localTimeOffset( const QDateTime &dt ) | 826 | int KLocale::localTimeOffset( const QDateTime &dt ) |
810 | { | 827 | { |
811 | bool addDaylight = false; | 828 | bool addDaylight = false; |
812 | if ( daylightEnabled ) { | 829 | if ( daylightEnabled ) { |
813 | int d_end, d_start; | 830 | int d_end, d_start; |
814 | int dayofyear = dt.date().dayOfYear(); | 831 | int dayofyear = dt.date().dayOfYear(); |
815 | int year = dt.date().year(); | 832 | int year = dt.date().year(); |
816 | int add = 0; | 833 | int add = 0; |
817 | if ( QDate::leapYear(year) ) | 834 | if ( QDate::leapYear(year) ) |
818 | add = 1; | 835 | add = 1; |
819 | QDate date ( year,1,1 ); | 836 | QDate date ( year,1,1 ); |
820 | if ( daylightEnd > 59 ) | 837 | if ( daylightEnd > 59 ) |
821 | d_end = daylightEnd +add; | 838 | d_end = daylightEnd +add; |
822 | else | 839 | else |
823 | d_end = daylightEnd; | 840 | d_end = daylightEnd; |
824 | if ( daylightStart > 59 ) | 841 | if ( daylightStart > 59 ) |
825 | d_start = daylightStart +add; | 842 | d_start = daylightStart +add; |
826 | else | 843 | else |
827 | d_start = daylightStart; | 844 | d_start = daylightStart; |
828 | QDate s_date = date.addDays( d_start -1 ); | 845 | QDate s_date = date.addDays( d_start -1 ); |
829 | QDate e_date = date.addDays( d_end -1 ); | 846 | QDate e_date = date.addDays( d_end -1 ); |
830 | int dof = s_date.dayOfWeek(); | 847 | int dof = s_date.dayOfWeek(); |
831 | if ( dof < 7 ) | 848 | if ( dof < 7 ) |
832 | s_date = s_date.addDays( -dof ); | 849 | s_date = s_date.addDays( -dof ); |
833 | dof = e_date.dayOfWeek(); | 850 | dof = e_date.dayOfWeek(); |
834 | if ( dof < 7 ) | 851 | if ( dof < 7 ) |
835 | e_date = e_date.addDays( -dof ); | 852 | e_date = e_date.addDays( -dof ); |
836 | QTime startTime ( 3,0,0 ); | 853 | QTime startTime ( 3,0,0 ); |
837 | QDateTime startDt( s_date, startTime ); | 854 | QDateTime startDt( s_date, startTime ); |
838 | QDateTime endDt( e_date, startTime ); | 855 | QDateTime endDt( e_date, startTime ); |
839 | //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( )); | 856 | //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( )); |
840 | if ( mSouthDaylight ) { | 857 | if ( mSouthDaylight ) { |
841 | if ( ! ( endDt < dt && dt < startDt) ) | 858 | if ( ! ( endDt < dt && dt < startDt) ) |
842 | addDaylight = true; | 859 | addDaylight = true; |
843 | } else { | 860 | } else { |
844 | if ( startDt < dt && dt < endDt ) | 861 | if ( startDt < dt && dt < endDt ) |
845 | addDaylight = true; | 862 | addDaylight = true; |
846 | 863 | ||
847 | 864 | ||
848 | } | 865 | } |
849 | } | 866 | } |
850 | int addMin = 0; | 867 | int addMin = 0; |
851 | if ( addDaylight ) | 868 | if ( addDaylight ) |
852 | addMin = 60; | 869 | addMin = 60; |
853 | return mTimeZoneOffset + addMin; | 870 | return mTimeZoneOffset + addMin; |
854 | } | 871 | } |
855 | // ****************************************************************** | 872 | // ****************************************************************** |
856 | // added LR | 873 | // added LR |
857 | QString KLocale::formatNumber(double num, int precision) const | 874 | QString KLocale::formatNumber(double num, int precision) const |
858 | { | 875 | { |
859 | bool neg = num < 0; | 876 | bool neg = num < 0; |
860 | if (precision == -1) precision = 2; | 877 | if (precision == -1) precision = 2; |
861 | QString res = QString::number(neg?-num:num, 'f', precision); | 878 | QString res = QString::number(neg?-num:num, 'f', precision); |
862 | int pos = res.find('.'); | 879 | int pos = res.find('.'); |
863 | if (pos == -1) pos = res.length(); | 880 | if (pos == -1) pos = res.length(); |
864 | else res.replace(pos, 1, decimalSymbol()); | 881 | else res.replace(pos, 1, decimalSymbol()); |
865 | 882 | ||
866 | while (0 < (pos -= 3)) | 883 | while (0 < (pos -= 3)) |
867 | res.insert(pos, thousandsSeparator()); // thousand sep | 884 | res.insert(pos, thousandsSeparator()); // thousand sep |
868 | 885 | ||
869 | // How can we know where we should put the sign? | 886 | // How can we know where we should put the sign? |
870 | res.prepend(neg?negativeSign():positiveSign()); | 887 | res.prepend(neg?negativeSign():positiveSign()); |
871 | 888 | ||
872 | return res; | 889 | return res; |
873 | } | 890 | } |
874 | QString KLocale::formatNumber(const QString &numStr) const | 891 | QString KLocale::formatNumber(const QString &numStr) const |
875 | { | 892 | { |
876 | return formatNumber(numStr.toDouble()); | 893 | return formatNumber(numStr.toDouble()); |
877 | } | 894 | } |
878 | double KLocale::readNumber(const QString &_str, bool * ok) const | 895 | double KLocale::readNumber(const QString &_str, bool * ok) const |
879 | { | 896 | { |
880 | QString str = _str.stripWhiteSpace(); | 897 | QString str = _str.stripWhiteSpace(); |
881 | bool neg = str.find(negativeSign()) == 0; | 898 | bool neg = str.find(negativeSign()) == 0; |
882 | if (neg) | 899 | if (neg) |
883 | str.remove( 0, negativeSign().length() ); | 900 | str.remove( 0, negativeSign().length() ); |
884 | 901 | ||
885 | /* will hold the scientific notation portion of the number. | 902 | /* will hold the scientific notation portion of the number. |
886 | Example, with 2.34E+23, exponentialPart == "E+23" | 903 | Example, with 2.34E+23, exponentialPart == "E+23" |
887 | */ | 904 | */ |
888 | QString exponentialPart; | 905 | QString exponentialPart; |
889 | int EPos; | 906 | int EPos; |
890 | 907 | ||
891 | EPos = str.find('E', 0, false); | 908 | EPos = str.find('E', 0, false); |
892 | 909 | ||
893 | if (EPos != -1) | 910 | if (EPos != -1) |
894 | { | 911 | { |
895 | exponentialPart = str.mid(EPos); | 912 | exponentialPart = str.mid(EPos); |
896 | str = str.left(EPos); | 913 | str = str.left(EPos); |
897 | } | 914 | } |
898 | 915 | ||
899 | int pos = str.find(decimalSymbol()); | 916 | int pos = str.find(decimalSymbol()); |
900 | QString major; | 917 | QString major; |
901 | QString minor; | 918 | QString minor; |
902 | if ( pos == -1 ) | 919 | if ( pos == -1 ) |
903 | major = str; | 920 | major = str; |
904 | else | 921 | else |
905 | { | 922 | { |
906 | major = str.left(pos); | 923 | major = str.left(pos); |
907 | minor = str.mid(pos + decimalSymbol().length()); | 924 | minor = str.mid(pos + decimalSymbol().length()); |
908 | } | 925 | } |
909 | 926 | ||
910 | // Remove thousand separators | 927 | // Remove thousand separators |
911 | int thlen = thousandsSeparator().length(); | 928 | int thlen = thousandsSeparator().length(); |
912 | int lastpos = 0; | 929 | int lastpos = 0; |
913 | while ( ( pos = major.find( thousandsSeparator() ) ) > 0 ) | 930 | while ( ( pos = major.find( thousandsSeparator() ) ) > 0 ) |
914 | { | 931 | { |
915 | // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N | 932 | // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N |
916 | int fromEnd = major.length() - pos; | 933 | int fromEnd = major.length() - pos; |
917 | if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error | 934 | if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error |
918 | || pos - lastpos > 3 // More than 3 digits between two separators -> error | 935 | || pos - lastpos > 3 // More than 3 digits between two separators -> error |
919 | || pos == 0 // Can't start with a separator | 936 | || pos == 0 // Can't start with a separator |
920 | || (lastpos>0 && pos-lastpos!=3)) // Must have exactly 3 digits between two separators | 937 | || (lastpos>0 && pos-lastpos!=3)) // Must have exactly 3 digits between two separators |
921 | { | 938 | { |
922 | if (ok) *ok = false; | 939 | if (ok) *ok = false; |
923 | return 0.0; | 940 | return 0.0; |
924 | } | 941 | } |
925 | 942 | ||
926 | lastpos = pos; | 943 | lastpos = pos; |
927 | major.remove( pos, thlen ); | 944 | major.remove( pos, thlen ); |
928 | } | 945 | } |
929 | if (lastpos>0 && major.length()-lastpos!=3) // Must have exactly 3 digits after the last separator | 946 | if (lastpos>0 && major.length()-lastpos!=3) // Must have exactly 3 digits after the last separator |
930 | { | 947 | { |
931 | if (ok) *ok = false; | 948 | if (ok) *ok = false; |
932 | return 0.0; | 949 | return 0.0; |
933 | } | 950 | } |
934 | 951 | ||
935 | QString tot; | 952 | QString tot; |
936 | if (neg) tot = '-'; | 953 | if (neg) tot = '-'; |
937 | 954 | ||
938 | tot += major + '.' + minor + exponentialPart; | 955 | tot += major + '.' + minor + exponentialPart; |
939 | 956 | ||
940 | return tot.toDouble(ok); | 957 | return tot.toDouble(ok); |
941 | } | 958 | } |
942 | QString KLocale::decimalSymbol() const | 959 | QString KLocale::decimalSymbol() const |
943 | { | 960 | { |
944 | 961 | ||
945 | return m_decimalSymbol; | 962 | return m_decimalSymbol; |
946 | } | 963 | } |
947 | 964 | ||
948 | QString KLocale::thousandsSeparator() const | 965 | QString KLocale::thousandsSeparator() const |
949 | { | 966 | { |
950 | 967 | ||
951 | return m_thousandsSeparator; | 968 | return m_thousandsSeparator; |
952 | } | 969 | } |
953 | QString KLocale::positiveSign() const | 970 | QString KLocale::positiveSign() const |
954 | { | 971 | { |
955 | return m_positiveSign; | 972 | return m_positiveSign; |
956 | } | 973 | } |
957 | 974 | ||
958 | QString KLocale::negativeSign() const | 975 | QString KLocale::negativeSign() const |
959 | { | 976 | { |
960 | return m_negativeSign; | 977 | return m_negativeSign; |
961 | } | 978 | } |
diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h index 949301a..5783530 100644 --- a/microkde/kdecore/klocale.h +++ b/microkde/kdecore/klocale.h | |||
@@ -1,116 +1,118 @@ | |||
1 | #ifndef MINIKDE_KLOCALE_H | 1 | #ifndef MINIKDE_KLOCALE_H |
2 | #define MINIKDE_KLOCALE_H | 2 | #define MINIKDE_KLOCALE_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | #include <qdatetime.h> | 6 | #include <qdatetime.h> |
7 | #include <qdict.h> | 7 | #include <qdict.h> |
8 | 8 | ||
9 | #ifndef I18N_NOOP | 9 | #ifndef I18N_NOOP |
10 | #define I18N_NOOP(x) (x) | 10 | #define I18N_NOOP(x) (x) |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | class KCalendarSystem; | 13 | class KCalendarSystem; |
14 | void setLocaleDict( QDict<QString> * dict ); | 14 | void setLocaleDict( QDict<QString> * dict ); |
15 | QString i18n(const char *text); | 15 | QString i18n(const char *text); |
16 | QString i18n(const char *hint, const char *text); | 16 | QString i18n(const char *hint, const char *text); |
17 | QString i18n(const char *text1, const char *textn, int num); | 17 | QString i18n(const char *text1, const char *textn, int num); |
18 | 18 | ||
19 | // Qt3's uic generates i18n( "msg", "comment" ) calls which conflict | 19 | // Qt3's uic generates i18n( "msg", "comment" ) calls which conflict |
20 | // with our i18n method. we use uic -tr tr2i18n to redirect | 20 | // with our i18n method. we use uic -tr tr2i18n to redirect |
21 | // to the right i18n() function | 21 | // to the right i18n() function |
22 | inline QString tr2i18n(const char* message, const char* =0) { | 22 | inline QString tr2i18n(const char* message, const char* =0) { |
23 | return i18n( message); | 23 | return i18n( message); |
24 | } | 24 | } |
25 | 25 | ||
26 | class KLocale | 26 | class KLocale |
27 | { | 27 | { |
28 | public: | 28 | public: |
29 | KLocale(); | 29 | KLocale(); |
30 | 30 | ||
31 | QString formatNumber(double num, int precision = -1) const; | 31 | QString formatNumber(double num, int precision = -1) const; |
32 | QString formatNumber(const QString &numStr) const; | 32 | QString formatNumber(const QString &numStr) const; |
33 | double readNumber(const QString &numStr, bool * ok = 0) const; | 33 | double readNumber(const QString &numStr, bool * ok = 0) const; |
34 | 34 | ||
35 | QString decimalSymbol() const; | 35 | QString decimalSymbol() const; |
36 | QString thousandsSeparator() const; | 36 | QString thousandsSeparator() const; |
37 | QString positiveSign() const; | 37 | QString positiveSign() const; |
38 | QString negativeSign() const; | 38 | QString negativeSign() const; |
39 | 39 | ||
40 | 40 | ||
41 | QString translate( const char *index ) const; | 41 | QString translate( const char *index ) const; |
42 | QString translate( const char *index, const char *fallback) const; | 42 | QString translate( const char *index, const char *fallback) const; |
43 | 43 | ||
44 | enum IntDateFormat { Undefined=-1, Default=0, Format1=1, ISODate=2, Userdefined=3 }; | 44 | enum IntDateFormat { Undefined=-1, Default=0, Format1=1, ISODate=2, Userdefined=3 }; |
45 | 45 | ||
46 | QString formatDate(const QDate &pDate, bool shortFormat = false, IntDateFormat intIntDateFormat = Undefined) const; | 46 | QString formatDate(const QDate &pDate, bool shortFormat = false, IntDateFormat intIntDateFormat = Undefined) const; |
47 | QString formatTime(const QTime &pTime, bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const; | 47 | QString formatTime(const QTime &pTime, bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const; |
48 | QString formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat = Undefined) const; | 48 | QString formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat = Undefined) const; |
49 | QString formatDateTime(const QDateTime &pDateTime, | 49 | QString formatDateTime(const QDateTime &pDateTime, |
50 | bool shortFormat, | 50 | bool shortFormat, |
51 | bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const; | 51 | bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const; |
52 | 52 | ||
53 | QDate readDate(const QString &str, bool* ok = 0) const; | 53 | QDate readDate(const QString &str, bool* ok = 0) const; |
54 | QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const; | 54 | QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const; |
55 | QTime readTime(const QString &str, bool* ok = 0) const; | 55 | QTime readTime(const QString &str, bool* ok = 0) const; |
56 | QDate readDate(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; | ||
57 | |||
56 | QDateTime readDateTime(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; | 58 | QDateTime readDateTime(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; |
57 | 59 | ||
58 | bool use12Clock() const; | 60 | bool use12Clock() const; |
59 | bool weekStartsMonday() const; | 61 | bool weekStartsMonday() const; |
60 | int weekStartDay() const; | 62 | int weekStartDay() const; |
61 | 63 | ||
62 | QString weekDayName(int,bool=false) const; | 64 | QString weekDayName(int,bool=false) const; |
63 | QString monthName(int,bool=false) const; | 65 | QString monthName(int,bool=false) const; |
64 | 66 | ||
65 | QString country() const; | 67 | QString country() const; |
66 | 68 | ||
67 | QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; | 69 | QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; |
68 | QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; | 70 | QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; |
69 | QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; | 71 | QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; |
70 | 72 | ||
71 | void insertCatalogue ( const QString & ); | 73 | void insertCatalogue ( const QString & ); |
72 | 74 | ||
73 | KCalendarSystem *calendar(); | 75 | KCalendarSystem *calendar(); |
74 | void setHore24Format ( bool ); | 76 | void setHore24Format ( bool ); |
75 | void setWeekStartMonday( bool ); | 77 | void setWeekStartMonday( bool ); |
76 | void setIntDateFormat( IntDateFormat ); | 78 | void setIntDateFormat( IntDateFormat ); |
77 | void setIntTimeFormat( IntDateFormat ); | 79 | void setIntTimeFormat( IntDateFormat ); |
78 | IntDateFormat getIntDateFormat( ); | 80 | IntDateFormat getIntDateFormat( ); |
79 | IntDateFormat getIntTimeFormat( ); | 81 | IntDateFormat getIntTimeFormat( ); |
80 | void setLanguage( int ); | 82 | void setLanguage( int ); |
81 | void setDateFormat( QString ); | 83 | void setDateFormat( QString ); |
82 | void setDateFormatShort( QString ); | 84 | void setDateFormatShort( QString ); |
83 | 85 | ||
84 | QString m_decimalSymbol; | 86 | QString m_decimalSymbol; |
85 | QString m_thousandsSeparator; | 87 | QString m_thousandsSeparator; |
86 | QString m_currencySymbol; | 88 | QString m_currencySymbol; |
87 | QString m_monetaryDecimalSymbol; | 89 | QString m_monetaryDecimalSymbol; |
88 | QString m_monetaryThousandsSeparator; | 90 | QString m_monetaryThousandsSeparator; |
89 | QString m_positiveSign; | 91 | QString m_positiveSign; |
90 | QString m_negativeSign; | 92 | QString m_negativeSign; |
91 | 93 | ||
92 | int timezoneOffset( QString ); | 94 | int timezoneOffset( QString ); |
93 | QStringList timeZoneList() const; | 95 | QStringList timeZoneList() const; |
94 | void setDaylightSaving( bool, int , int ); | 96 | void setDaylightSaving( bool, int , int ); |
95 | int localTimeOffset(const QDateTime &); | 97 | int localTimeOffset(const QDateTime &); |
96 | void setTimezone( const QString &timeZone ); | 98 | void setTimezone( const QString &timeZone ); |
97 | private: | 99 | private: |
98 | QTime readTime(const QString &str, bool seconds, bool *ok) const; | 100 | QTime readTime(const QString &str, bool seconds, bool *ok) const; |
99 | QDate readDate(const QString &str, bool shortFormat, bool *ok) const; | 101 | QDate readDate(const QString &str, bool shortFormat, bool *ok) const; |
100 | KCalendarSystem *mCalendarSystem; | 102 | KCalendarSystem *mCalendarSystem; |
101 | bool mWeekStartsMonday; | 103 | bool mWeekStartsMonday; |
102 | bool mHourF24Format; | 104 | bool mHourF24Format; |
103 | IntDateFormat mIntDateFormat; | 105 | IntDateFormat mIntDateFormat; |
104 | IntDateFormat mIntTimeFormat; | 106 | IntDateFormat mIntTimeFormat; |
105 | int mLanguage; | 107 | int mLanguage; |
106 | QString mDateFormat; | 108 | QString mDateFormat; |
107 | QString mDateFormatShort; | 109 | QString mDateFormatShort; |
108 | QStringList mTimeZoneList; | 110 | QStringList mTimeZoneList; |
109 | bool daylightEnabled; | 111 | bool daylightEnabled; |
110 | int mDaylightTZoffset; | 112 | int mDaylightTZoffset; |
111 | int mNondaylightTZoffset; | 113 | int mNondaylightTZoffset; |
112 | bool mSouthDaylight; | 114 | bool mSouthDaylight; |
113 | int daylightStart, daylightEnd, mTimeZoneOffset; | 115 | int daylightStart, daylightEnd, mTimeZoneOffset; |
114 | }; | 116 | }; |
115 | 117 | ||
116 | #endif | 118 | #endif |