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

List:       kde-core-devel
Subject:    klocale patch
From:       CP Hennessy <CP.Hennessy () iname ! com>
Date:       2003-01-14 15:43:30
[Download RAW message or body]

Hi,
	Attached is a new method for klocale which returns a string formated to
the current locale's conventions regarding both date and time, but :
   *   only returns time if currentDate == date from pDateTime;
   *   only returns time and day if (currentDate -7) < date from pDateTime;
   *   otherwise shows same as formatDateTime above

e.g. if the time and date is 15:35:01 14/01/03 then "15:35:01" is returned
if the time and date is 15:35:01 13/01/03 then "Mon 15:35:01" is returned
if the time and date is 15:35:01 03/01/03 then the standard date and time 
string is returned.

If this is already implemented great. 
If not can I added to klocale ?

I have been using this in KNode for the last few months with no problem
and find it quite useful. I'd also like to see it used in KMail.

Thanks
CPH


["klocale.cpp.patch" (text/x-diff)]

Index: klocale.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/klocale.cpp,v
retrieving revision 1.322
diff -u -3 -p -u -r1.322 klocale.cpp
--- klocale.cpp	3 Jan 2003 17:34:48 -0000	1.322
+++ klocale.cpp	14 Jan 2003 15:31:52 -0000
@@ -1696,6 +1696,24 @@ QString KLocale::formatDateTime(const QD
     .arg( formatTime( pDateTime.time(), includeSeconds ) );
 }
 
+QString KLocale::formatDateTimeShortest(const QDateTime &pDateTime,
+				bool shortFormat,
+				bool includeSeconds) const
+{
+  if ( QDate::currentDate() == pDateTime.date() )
+     // show only the time 
+     return translate("concatenation of dates and time", "%1") //FIXME: what should this now be ?
+       .arg( formatTime( pDateTime.time(), includeSeconds ) );
+  else if ( QDate::currentDate().year() == pDateTime.date().year() &&
+  	( QDate::currentDate().dayOfYear() > ( pDateTime.date().dayOfYear() - 7 ) ) )
+     // show only the time and day of week
+     return translate("concatenation of dates and time", "%1 %2")
+       .arg( weekDayName ( pDateTime.date().dayOfWeek(), shortFormat ) )
+       .arg( formatTime( pDateTime.time(), includeSeconds ) );
+  else
+     return formatDateTime( pDateTime, shortFormat, includeSeconds );
+}
+
 QString i18n(const char* text)
 {
   register KLocale *instance = KGlobal::locale();

["klocale.h.patch" (text/x-diff)]

Index: klocale.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/klocale.h,v
retrieving revision 1.138
diff -u -3 -p -u -r1.138 klocale.h
--- klocale.h	5 Jan 2003 09:40:02 -0000	1.138
+++ klocale.h	14 Jan 2003 15:39:59 -0000
@@ -482,6 +482,24 @@ public:
 			 bool includeSecs = false) const;
 
   /**
+   * Returns a string formated to the current locale's conventions
+   * regarding both date and time, but :
+   *   only returns time if currentDate == date from pDateTime;
+   *   only returns time and day if (currentDate -7) < date from pDateTime;
+   *   otherwise shows same as formatDateTime above
+   *
+   * @param pDateTime The date and time to be formated.
+   * @param shortFormat using the short date format.
+   * @param includeSeconds using the short date format.
+   *
+   * @return The date and time as a string
+   * @since 3.2
+   */
+  QString formatDateTimeShortest(const QDateTime &pDateTime,
+			 bool shortFormat = true,
+			 bool includeSecs = false) const;
+
+  /**
    * Converts a localized monetary string to a double.
    *
    * @param numStr the string we want to convert.


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

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