[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [PATCH] KoText: date variable
From:       Nicolas Goutte <nicolasg () snafu ! de>
Date:       2003-09-18 20:21:56
[Download RAW message or body]

The attached patch is for koffice/lib/kotext/kovariable.cc

It fixes the conversion of the date format to the final text. It uses directly 
and everywhere QDateTime (works also with a QDate QVariant).

The use of 1970-01-01 is necessary as otherwise the popup menu for a printdate 
is monotone:
----
No date set
No date set
No date set
...

However, the user do not care about the print date before he prints but he 
should be able to find the right format.

Have a nice day!

PS.: the patches are been made one after another form a clean copy of 
kovariable.cc. Therefore they might not be applicable together without patch 
merging problem.
["patch_kotext_convert.diff" (text/x-diff)]

Index: kovariable.cc
===================================================================
RCS file: /home/kde/koffice/lib/kotext/kovariable.cc,v
retrieving revision 1.126
diff -u -r1.126 kovariable.cc
--- kovariable.cc	29 Aug 2003 13:13:33 -0000	1.126
+++ kovariable.cc	18 Sep 2003 20:14:56 -0000
@@ -155,27 +155,27 @@
 {
     if ( data.type() != QVariant::Date && data.type() != QVariant::DateTime )
     {
-        kdDebug(32500)<<" Error in KoVariableDateFormat::convert. Value is a "
+        kdWarning(32500)<<" Error in KoVariableDateFormat::convert. Value is a "
                       << data.typeName() << "(" << data.type() << ")" << endl;
-        return QString::null;
+        // dateTime will be invalid, then set to 1970-01-01
     }
-    QDate date = data.toDate();
-    QDateTime dateTime = data.type() == QVariant::DateTime ? data.toDateTime() : \
                QDateTime(date, QTime());
-    if ( !date.isValid() )
-        return i18n("No date set"); // e.g. "last printed date" if never printed
+    QDateTime dateTime ( data.toDateTime() );
+    if ( !dateTime.isValid() )
+        dateTime.setTime_t(0); // 1970-01-01 00:00:00.000 local time
 
     if (m_strFormat.lower() == "locale" || m_strFormat.isEmpty())
-	return KGlobal::locale()->formatDate( date, false );
+        return KGlobal::locale()->formatDate( dateTime.date(), false );
     else if ( m_strFormat.lower() == "localeshort" )
-	return KGlobal::locale()->formatDate( date, true );
+        return KGlobal::locale()->formatDate( dateTime.date(), true );
     else if ( m_strFormat.lower() == "localedatetime" )
-	return KGlobal::locale()->formatDateTime( dateTime, false );
+        return KGlobal::locale()->formatDateTime( dateTime, false );
     else if ( m_strFormat.lower() == "localedatetimeshort" )
-	return KGlobal::locale()->formatDateTime( dateTime, true );
+        return KGlobal::locale()->formatDateTime( dateTime, true );
 
-    QString tmp=data.toDate().toString(m_strFormat);
-    tmp.replace("PPPP", KGlobal::locale()->monthNamePossessive(date.month(), \
                false)); //long possessive month name
-    tmp.replace("PPP", KGlobal::locale()->monthNamePossessive(date.month(), true)); \
//short possessive month name +    QString tmp ( dateTime.toString(m_strFormat) );
+    const int month = dateTime.date().month();
+    tmp.replace("PPPP", KGlobal::locale()->monthNamePossessive(month, false)); \
//long possessive month name +    tmp.replace("PPP",  \
KGlobal::locale()->monthNamePossessive(month, true));  //short possessive month name  \
return tmp;  }
 



_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic