summaryrefslogtreecommitdiffabout
path: root/microkde
Unidiff
Diffstat (limited to 'microkde') (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
@@ -558,60 +558,83 @@ QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
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 )
@@ -665,63 +688,62 @@ QString KLocale::monthName(int i,bool shortName) const
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 )
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
@@ -32,48 +32,49 @@ class KLocale
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 );