summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/klocale.cpp44
-rw-r--r--microkde/kdecore/klocale.h1
2 files changed, 34 insertions, 11 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index 7bd8a70..17031c7 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -390,506 +390,528 @@ QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) con
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
464QTime KLocale::readTime(const QString &intstr, bool *ok) const 464QTime 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
472QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const 472QTime 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
581QDateTime KLocale::readDateTime(const QString &intstr, 581QDateTime KLocale::readDateTime(const QString &intstr,
582 bool shortFormat,
583 bool includeSeconds,
584 IntDateFormat intIntDateFormat, 582 IntDateFormat intIntDateFormat,
585 bool* ok) const 583 bool* ok) const
586{ 584{
587 bool ok1, ok2; 585 bool ok1, ok2;
588 586
589 QDate m_date = readDate(date, &ok1); 587 // AT the moment we can not read any other format then ISODate
590 QTime m_time = KGlobal::locale()->readTime(time, &ok2); 588 if ( intIntDateFormat != ISODate )
591 if ((ok1 == false) || (ok2 == false)) 589 {
592 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); 590 qDebug("KLocale::readDateTime, only ISODate is supported.");
591 return QDateTime();
592 }
593
594 int pos = intstr.find("T");
595 QString date = intstr.left(pos);
596 QString time = intstr.mid(pos+1);
593 597
598 QString dformat = dateFormat(intIntDateFormat);
599 QString tformat = timeFormat(intIntDateFormat);
600
601 QDate m_date = readDate(date, dformat, &ok1);
602 QTime m_time = readTime(time, tformat, &ok2);
603
604 if (ok)
605 {
606 if ((ok1 == false) || (ok2 == false))
607 *ok = false;
608 else
609 *ok = true;
610 }
611 QDateTime m_dt;
612 m_dt.setDate(m_date);
613 m_dt.setTime(m_time);
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);
616 return m_dt;
594} 617}
595 618
596 619
597bool KLocale::use12Clock() const 620bool KLocale::use12Clock() const
598{ 621{
599 return !mHourF24Format ;; 622 return !mHourF24Format ;;
600} 623}
601 624
602bool KLocale::weekStartsMonday() const 625bool KLocale::weekStartsMonday() const
603{ 626{
604 return mWeekStartsMonday; 627 return mWeekStartsMonday;
605} 628}
606 629
607int KLocale::weekStartDay() const 630int KLocale::weekStartDay() const
608{ 631{
609 if ( mWeekStartsMonday ) 632 if ( mWeekStartsMonday )
610 return 1; 633 return 1;
611 return 7; 634 return 7;
612} 635}
613 636
614QString KLocale::weekDayName(int i,bool shortName) const 637QString KLocale::weekDayName(int i,bool shortName) const
615{ 638{
616 if ( shortName ) 639 if ( shortName )
617 switch ( i ) 640 switch ( i )
618 { 641 {
619 case 1: return i18n("Monday", "Mon"); 642 case 1: return i18n("Monday", "Mon");
620 case 2: return i18n("Tuesday", "Tue"); 643 case 2: return i18n("Tuesday", "Tue");
621 case 3: return i18n("Wednesday", "Wed"); 644 case 3: return i18n("Wednesday", "Wed");
622 case 4: return i18n("Thursday", "Thu"); 645 case 4: return i18n("Thursday", "Thu");
623 case 5: return i18n("Friday", "Fri"); 646 case 5: return i18n("Friday", "Fri");
624 case 6: return i18n("Saturday", "Sat"); 647 case 6: return i18n("Saturday", "Sat");
625 case 7: return i18n("Sunday", "Sun"); 648 case 7: return i18n("Sunday", "Sun");
626 } 649 }
627 else 650 else
628 switch ( i ) 651 switch ( i )
629 { 652 {
630 case 1: return i18n("Monday"); 653 case 1: return i18n("Monday");
631 case 2: return i18n("Tuesday"); 654 case 2: return i18n("Tuesday");
632 case 3: return i18n("Wednesday"); 655 case 3: return i18n("Wednesday");
633 case 4: return i18n("Thursday"); 656 case 4: return i18n("Thursday");
634 case 5: return i18n("Friday"); 657 case 5: return i18n("Friday");
635 case 6: return i18n("Saturday"); 658 case 6: return i18n("Saturday");
636 case 7: return i18n("Sunday"); 659 case 7: return i18n("Sunday");
637 } 660 }
638 661
639 return QString::null; 662 return QString::null;
640} 663}
641 664
642QString KLocale::monthName(int i,bool shortName) const 665QString KLocale::monthName(int i,bool shortName) const
643{ 666{
644 if ( shortName ) 667 if ( shortName )
645 switch ( i ) 668 switch ( i )
646 { 669 {
647 case 1: return i18n("January", "Jan"); 670 case 1: return i18n("January", "Jan");
648 case 2: return i18n("February", "Feb"); 671 case 2: return i18n("February", "Feb");
649 case 3: return i18n("March", "Mar"); 672 case 3: return i18n("March", "Mar");
650 case 4: return i18n("April", "Apr"); 673 case 4: return i18n("April", "Apr");
651 case 5: return i18n("May short", "May"); 674 case 5: return i18n("May short", "May");
652 case 6: return i18n("June", "Jun"); 675 case 6: return i18n("June", "Jun");
653 case 7: return i18n("July", "Jul"); 676 case 7: return i18n("July", "Jul");
654 case 8: return i18n("August", "Aug"); 677 case 8: return i18n("August", "Aug");
655 case 9: return i18n("September", "Sep"); 678 case 9: return i18n("September", "Sep");
656 case 10: return i18n("October", "Oct"); 679 case 10: return i18n("October", "Oct");
657 case 11: return i18n("November", "Nov"); 680 case 11: return i18n("November", "Nov");
658 case 12: return i18n("December", "Dec"); 681 case 12: return i18n("December", "Dec");
659 } 682 }
660 else 683 else
661 switch (i) 684 switch (i)
662 { 685 {
663 case 1: return i18n("January"); 686 case 1: return i18n("January");
664 case 2: return i18n("February"); 687 case 2: return i18n("February");
665 case 3: return i18n("March"); 688 case 3: return i18n("March");
666 case 4: return i18n("April"); 689 case 4: return i18n("April");
667 case 5: return i18n("May long", "May"); 690 case 5: return i18n("May long", "May");
668 case 6: return i18n("June"); 691 case 6: return i18n("June");
669 case 7: return i18n("July"); 692 case 7: return i18n("July");
670 case 8: return i18n("August"); 693 case 8: return i18n("August");
671 case 9: return i18n("September"); 694 case 9: return i18n("September");
672 case 10: return i18n("October"); 695 case 10: return i18n("October");
673 case 11: return i18n("November"); 696 case 11: return i18n("November");
674 case 12: return i18n("December"); 697 case 12: return i18n("December");
675 } 698 }
676 699
677 return QString::null; 700 return QString::null;
678} 701}
679 702
680QString KLocale::country() const 703QString KLocale::country() const
681{ 704{
682 return QString::null; 705 return QString::null;
683} 706}
684 707
685QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const 708QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const
686{ 709{
687 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; 710 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
688 711
712 if ( dformat == ISODate )
713 return "%Y-%m-%d";
714
689 if ( QApplication::desktop()->width() < 480 ) { 715 if ( QApplication::desktop()->width() < 480 ) {
690 if ( dformat == Default ) 716 if ( dformat == Default )
691 return "%a %d %b %Y"; 717 return "%a %d %b %Y";
692 else if ( dformat == Format1 ) 718 else if ( dformat == Format1 )
693 return "%a %b %d %Y"; 719 return "%a %b %d %Y";
694 else if ( dformat == ISODate )
695 return "%a %Y %b %d";
696 } else { 720 } else {
697
698 if ( dformat == Default ) 721 if ( dformat == Default )
699 return "%A %d %B %Y"; 722 return "%A %d %B %Y";
700 else if ( dformat == Format1 ) 723 else if ( dformat == Format1 )
701 return "%A %B %d %Y"; 724 return "%A %B %d %Y";
702 else if ( dformat == ISODate ) 725
703 return "%A %Y %B %d";
704 } 726 }
705 return mDateFormat ; 727 return mDateFormat ;
706} 728}
707 729
708QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const 730QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const
709{ 731{
710 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; 732 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
711 733
712 if ( dformat == Default ) 734 if ( dformat == Default )
713 return "%d.%m.%Y"; 735 return "%d.%m.%Y";
714 else if ( dformat == Format1 ) 736 else if ( dformat == Format1 )
715 return "%m.%d.%Y"; 737 return "%m.%d.%Y";
716 else if ( dformat == ISODate ) // = Qt::ISODate 738 else if ( dformat == ISODate ) // = Qt::ISODate
717 return "%Y-%m-%d"; 739 return "%Y-%m-%d";
718 return mDateFormatShort ; 740 return mDateFormatShort ;
719 741
720} 742}
721 743
722 744
723QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const 745QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const
724{ 746{
725 const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat; 747 const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat;
726 748
727 if ( tformat == Default ) 749 if ( tformat == Default )
728 if ( mHourF24Format) 750 if ( mHourF24Format)
729 return "%H:%M:%S"; 751 return "%H:%M:%S";
730 else 752 else
731 return "%I:%M:%S%p"; 753 return "%I:%M:%S%p";
732 754
733 else if ( tformat == Format1 ) 755 else if ( tformat == Format1 )
734 if ( mHourF24Format) 756 if ( mHourF24Format)
735 return "%H:%M:%S"; 757 return "%H:%M:%S";
736 else 758 else
737 return "%I:%M:%S%p"; 759 return "%I:%M:%S%p";
738 760
739 else if ( tformat == ISODate ) // = Qt::ISODate 761 else if ( tformat == ISODate ) // = Qt::ISODate
740 if ( mHourF24Format) 762 if ( mHourF24Format)
741 return "%H:%M:%S"; 763 return "%H:%M:%S";
742 else 764 else
743 return "%I:%M:%S%p"; 765 return "%I:%M:%S%p";
744 766
745} 767}
746 768
747void KLocale::insertCatalogue ( const QString & ) 769void KLocale::insertCatalogue ( const QString & )
748{ 770{
749} 771}
750 772
751KCalendarSystem *KLocale::calendar() 773KCalendarSystem *KLocale::calendar()
752{ 774{
753 if ( !mCalendarSystem ) { 775 if ( !mCalendarSystem ) {
754 mCalendarSystem = new KCalendarSystemGregorian; 776 mCalendarSystem = new KCalendarSystemGregorian;
755 } 777 }
756 778
757 return mCalendarSystem; 779 return mCalendarSystem;
758} 780}
759 781
760int KLocale::timezoneOffset( QString timeZone ) 782int KLocale::timezoneOffset( QString timeZone )
761{ 783{
762 int ret = 1001; 784 int ret = 1001;
763 int index = mTimeZoneList.findIndex( timeZone ); 785 int index = mTimeZoneList.findIndex( timeZone );
764 if ( index < 24 ) 786 if ( index < 24 )
765 ret = ( index-11 ) * 60 ; 787 ret = ( index-11 ) * 60 ;
766 return ret; 788 return ret;
767} 789}
768 790
769QStringList KLocale::timeZoneList() const 791QStringList KLocale::timeZoneList() const
770{ 792{
771 return mTimeZoneList; 793 return mTimeZoneList;
772} 794}
773void KLocale::setTimezone( const QString &timeZone ) 795void KLocale::setTimezone( const QString &timeZone )
774{ 796{
775 mTimeZoneOffset = timezoneOffset( timeZone ); 797 mTimeZoneOffset = timezoneOffset( timeZone );
776} 798}
777 799
778void KLocale::setDaylightSaving( bool b, int start , int end ) 800void KLocale::setDaylightSaving( bool b, int start , int end )
779{ 801{
780 daylightEnabled = b; 802 daylightEnabled = b;
781 daylightStart = start; 803 daylightStart = start;
782 daylightEnd = end; 804 daylightEnd = end;
783 mSouthDaylight = (end < start); 805 mSouthDaylight = (end < start);
784 // qDebug("klocale daylight %d %d %d ", b, start , end ); 806 // qDebug("klocale daylight %d %d %d ", b, start , end );
785} 807}
786 808
787int KLocale::localTimeOffset( const QDateTime &dt ) 809int KLocale::localTimeOffset( const QDateTime &dt )
788{ 810{
789 bool addDaylight = false; 811 bool addDaylight = false;
790 if ( daylightEnabled ) { 812 if ( daylightEnabled ) {
791 int d_end, d_start; 813 int d_end, d_start;
792 int dayofyear = dt.date().dayOfYear(); 814 int dayofyear = dt.date().dayOfYear();
793 int year = dt.date().year(); 815 int year = dt.date().year();
794 int add = 0; 816 int add = 0;
795 if ( QDate::leapYear(year) ) 817 if ( QDate::leapYear(year) )
796 add = 1; 818 add = 1;
797 QDate date ( year,1,1 ); 819 QDate date ( year,1,1 );
798 if ( daylightEnd > 59 ) 820 if ( daylightEnd > 59 )
799 d_end = daylightEnd +add; 821 d_end = daylightEnd +add;
800 else 822 else
801 d_end = daylightEnd; 823 d_end = daylightEnd;
802 if ( daylightStart > 59 ) 824 if ( daylightStart > 59 )
803 d_start = daylightStart +add; 825 d_start = daylightStart +add;
804 else 826 else
805 d_start = daylightStart; 827 d_start = daylightStart;
806 QDate s_date = date.addDays( d_start -1 ); 828 QDate s_date = date.addDays( d_start -1 );
807 QDate e_date = date.addDays( d_end -1 ); 829 QDate e_date = date.addDays( d_end -1 );
808 int dof = s_date.dayOfWeek(); 830 int dof = s_date.dayOfWeek();
809 if ( dof < 7 ) 831 if ( dof < 7 )
810 s_date = s_date.addDays( -dof ); 832 s_date = s_date.addDays( -dof );
811 dof = e_date.dayOfWeek(); 833 dof = e_date.dayOfWeek();
812 if ( dof < 7 ) 834 if ( dof < 7 )
813 e_date = e_date.addDays( -dof ); 835 e_date = e_date.addDays( -dof );
814 QTime startTime ( 3,0,0 ); 836 QTime startTime ( 3,0,0 );
815 QDateTime startDt( s_date, startTime ); 837 QDateTime startDt( s_date, startTime );
816 QDateTime endDt( e_date, startTime ); 838 QDateTime endDt( e_date, startTime );
817 //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( )); 839 //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( ));
818 if ( mSouthDaylight ) { 840 if ( mSouthDaylight ) {
819 if ( ! ( endDt < dt && dt < startDt) ) 841 if ( ! ( endDt < dt && dt < startDt) )
820 addDaylight = true; 842 addDaylight = true;
821 } else { 843 } else {
822 if ( startDt < dt && dt < endDt ) 844 if ( startDt < dt && dt < endDt )
823 addDaylight = true; 845 addDaylight = true;
824 846
825 847
826 } 848 }
827 } 849 }
828 int addMin = 0; 850 int addMin = 0;
829 if ( addDaylight ) 851 if ( addDaylight )
830 addMin = 60; 852 addMin = 60;
831 return mTimeZoneOffset + addMin; 853 return mTimeZoneOffset + addMin;
832} 854}
833// ****************************************************************** 855// ******************************************************************
834// added LR 856// added LR
835QString KLocale::formatNumber(double num, int precision) const 857QString KLocale::formatNumber(double num, int precision) const
836{ 858{
837 bool neg = num < 0; 859 bool neg = num < 0;
838 if (precision == -1) precision = 2; 860 if (precision == -1) precision = 2;
839 QString res = QString::number(neg?-num:num, 'f', precision); 861 QString res = QString::number(neg?-num:num, 'f', precision);
840 int pos = res.find('.'); 862 int pos = res.find('.');
841 if (pos == -1) pos = res.length(); 863 if (pos == -1) pos = res.length();
842 else res.replace(pos, 1, decimalSymbol()); 864 else res.replace(pos, 1, decimalSymbol());
843 865
844 while (0 < (pos -= 3)) 866 while (0 < (pos -= 3))
845 res.insert(pos, thousandsSeparator()); // thousand sep 867 res.insert(pos, thousandsSeparator()); // thousand sep
846 868
847 // How can we know where we should put the sign? 869 // How can we know where we should put the sign?
848 res.prepend(neg?negativeSign():positiveSign()); 870 res.prepend(neg?negativeSign():positiveSign());
849 871
850 return res; 872 return res;
851} 873}
852QString KLocale::formatNumber(const QString &numStr) const 874QString KLocale::formatNumber(const QString &numStr) const
853{ 875{
854 return formatNumber(numStr.toDouble()); 876 return formatNumber(numStr.toDouble());
855} 877}
856double KLocale::readNumber(const QString &_str, bool * ok) const 878double KLocale::readNumber(const QString &_str, bool * ok) const
857{ 879{
858 QString str = _str.stripWhiteSpace(); 880 QString str = _str.stripWhiteSpace();
859 bool neg = str.find(negativeSign()) == 0; 881 bool neg = str.find(negativeSign()) == 0;
860 if (neg) 882 if (neg)
861 str.remove( 0, negativeSign().length() ); 883 str.remove( 0, negativeSign().length() );
862 884
863 /* will hold the scientific notation portion of the number. 885 /* will hold the scientific notation portion of the number.
864 Example, with 2.34E+23, exponentialPart == "E+23" 886 Example, with 2.34E+23, exponentialPart == "E+23"
865 */ 887 */
866 QString exponentialPart; 888 QString exponentialPart;
867 int EPos; 889 int EPos;
868 890
869 EPos = str.find('E', 0, false); 891 EPos = str.find('E', 0, false);
870 892
871 if (EPos != -1) 893 if (EPos != -1)
872 { 894 {
873 exponentialPart = str.mid(EPos); 895 exponentialPart = str.mid(EPos);
874 str = str.left(EPos); 896 str = str.left(EPos);
875 } 897 }
876 898
877 int pos = str.find(decimalSymbol()); 899 int pos = str.find(decimalSymbol());
878 QString major; 900 QString major;
879 QString minor; 901 QString minor;
880 if ( pos == -1 ) 902 if ( pos == -1 )
881 major = str; 903 major = str;
882 else 904 else
883 { 905 {
884 major = str.left(pos); 906 major = str.left(pos);
885 minor = str.mid(pos + decimalSymbol().length()); 907 minor = str.mid(pos + decimalSymbol().length());
886 } 908 }
887 909
888 // Remove thousand separators 910 // Remove thousand separators
889 int thlen = thousandsSeparator().length(); 911 int thlen = thousandsSeparator().length();
890 int lastpos = 0; 912 int lastpos = 0;
891 while ( ( pos = major.find( thousandsSeparator() ) ) > 0 ) 913 while ( ( pos = major.find( thousandsSeparator() ) ) > 0 )
892 { 914 {
893 // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N 915 // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N
894 int fromEnd = major.length() - pos; 916 int fromEnd = major.length() - pos;
895 if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error 917 if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error
diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h
index 153b12a..949301a 100644
--- a/microkde/kdecore/klocale.h
+++ b/microkde/kdecore/klocale.h
@@ -1,115 +1,116 @@
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
13class KCalendarSystem; 13class KCalendarSystem;
14void setLocaleDict( QDict<QString> * dict ); 14void setLocaleDict( QDict<QString> * dict );
15QString i18n(const char *text); 15QString i18n(const char *text);
16QString i18n(const char *hint, const char *text); 16QString i18n(const char *hint, const char *text);
17QString i18n(const char *text1, const char *textn, int num); 17QString 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
22inline QString tr2i18n(const char* message, const char* =0) { 22inline QString tr2i18n(const char* message, const char* =0) {
23 return i18n( message); 23 return i18n( message);
24} 24}
25 25
26class KLocale 26class 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 QDateTime readDateTime(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const;
56 57
57 bool use12Clock() const; 58 bool use12Clock() const;
58 bool weekStartsMonday() const; 59 bool weekStartsMonday() const;
59 int weekStartDay() const; 60 int weekStartDay() const;
60 61
61 QString weekDayName(int,bool=false) const; 62 QString weekDayName(int,bool=false) const;
62 QString monthName(int,bool=false) const; 63 QString monthName(int,bool=false) const;
63 64
64 QString country() const; 65 QString country() const;
65 66
66 QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; 67 QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const;
67 QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; 68 QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const;
68 QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; 69 QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const;
69 70
70 void insertCatalogue ( const QString & ); 71 void insertCatalogue ( const QString & );
71 72
72 KCalendarSystem *calendar(); 73 KCalendarSystem *calendar();
73 void setHore24Format ( bool ); 74 void setHore24Format ( bool );
74 void setWeekStartMonday( bool ); 75 void setWeekStartMonday( bool );
75 void setIntDateFormat( IntDateFormat ); 76 void setIntDateFormat( IntDateFormat );
76 void setIntTimeFormat( IntDateFormat ); 77 void setIntTimeFormat( IntDateFormat );
77 IntDateFormat getIntDateFormat( ); 78 IntDateFormat getIntDateFormat( );
78 IntDateFormat getIntTimeFormat( ); 79 IntDateFormat getIntTimeFormat( );
79 void setLanguage( int ); 80 void setLanguage( int );
80 void setDateFormat( QString ); 81 void setDateFormat( QString );
81 void setDateFormatShort( QString ); 82 void setDateFormatShort( QString );
82 83
83 QString m_decimalSymbol; 84 QString m_decimalSymbol;
84 QString m_thousandsSeparator; 85 QString m_thousandsSeparator;
85 QString m_currencySymbol; 86 QString m_currencySymbol;
86 QString m_monetaryDecimalSymbol; 87 QString m_monetaryDecimalSymbol;
87 QString m_monetaryThousandsSeparator; 88 QString m_monetaryThousandsSeparator;
88 QString m_positiveSign; 89 QString m_positiveSign;
89 QString m_negativeSign; 90 QString m_negativeSign;
90 91
91 int timezoneOffset( QString ); 92 int timezoneOffset( QString );
92 QStringList timeZoneList() const; 93 QStringList timeZoneList() const;
93 void setDaylightSaving( bool, int , int ); 94 void setDaylightSaving( bool, int , int );
94 int localTimeOffset(const QDateTime &); 95 int localTimeOffset(const QDateTime &);
95 void setTimezone( const QString &timeZone ); 96 void setTimezone( const QString &timeZone );
96 private: 97 private:
97 QTime readTime(const QString &str, bool seconds, bool *ok) const; 98 QTime readTime(const QString &str, bool seconds, bool *ok) const;
98 QDate readDate(const QString &str, bool shortFormat, bool *ok) const; 99 QDate readDate(const QString &str, bool shortFormat, bool *ok) const;
99 KCalendarSystem *mCalendarSystem; 100 KCalendarSystem *mCalendarSystem;
100 bool mWeekStartsMonday; 101 bool mWeekStartsMonday;
101 bool mHourF24Format; 102 bool mHourF24Format;
102 IntDateFormat mIntDateFormat; 103 IntDateFormat mIntDateFormat;
103 IntDateFormat mIntTimeFormat; 104 IntDateFormat mIntTimeFormat;
104 int mLanguage; 105 int mLanguage;
105 QString mDateFormat; 106 QString mDateFormat;
106 QString mDateFormatShort; 107 QString mDateFormatShort;
107 QStringList mTimeZoneList; 108 QStringList mTimeZoneList;
108 bool daylightEnabled; 109 bool daylightEnabled;
109 int mDaylightTZoffset; 110 int mDaylightTZoffset;
110 int mNondaylightTZoffset; 111 int mNondaylightTZoffset;
111 bool mSouthDaylight; 112 bool mSouthDaylight;
112 int daylightStart, daylightEnd, mTimeZoneOffset; 113 int daylightStart, daylightEnd, mTimeZoneOffset;
113}; 114};
114 115
115#endif 116#endif