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

List:       koffice-devel
Subject:    Re: Presentation duration display
From:       David Faure <faure () kde ! org>
Date:       2004-04-30 9:23:10
Message-ID: 200404301123.10793.faure () kde ! org
[Download RAW message or body]

On Friday 30 April 2004 10:58, Brad Hards wrote:
> Slide time shouldn't be localised IMHO - it makes no sense to have a duration 
> of 12:00:04am
> 
> I'm thinking just a straight display in seconds, or perhaps minutes and 
> seconds. The total could be in hours, minutes and seconds if I can find some 
> way to display it - my concern is over translation. I'm not sure what the 
> impact is going to be yet.

One solution is to add support for "durations" in KLocale.
klocaletest: 0:22:33 (as time) -> 12:22:33 am
klocaletest: 0:22:33 (as duration) -> 00:22:33
Patch attached. (What do you think? Should I commit it?)

The downside is that you have to use KDE_IS_VERSION(3,2,90) to use the new
method, but hopefully this should be correct in all languages. In the #else part
you can use HH:MM:SS as fallback.

The other solution is QTime::toString( Qt::LocalDate ) since it says it has no
concept of am/pm nor 12h clock.... at least currently.

-- 
David Faure, faure@kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).

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

Index: klocale.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/klocale.cpp,v
retrieving revision 1.350
diff -u -p -r1.350 klocale.cpp
--- klocale.cpp	15 Mar 2004 09:55:15 -0000	1.350
+++ klocale.cpp	30 Apr 2004 09:19:49 -0000
@@ -1578,8 +1578,14 @@ QTime KLocale::readTime(const QString &i
   return QTime(-1, -1, -1); // return invalid date if it didn't work
 }
 
+//BIC: merge with below
 QString KLocale::formatTime(const QTime &pTime, bool includeSecs) const
 {
+  return formatTime( pTime, includeSecs, false );
+}
+
+QString KLocale::formatTime(const QTime &pTime, bool includeSecs, bool isDuration) const
+{
   const QString rst = timeFormat();
 
   // only "pm/am" here can grow, the rest shrinks, but
@@ -1610,7 +1616,10 @@ QString KLocale::formatTime(const QTime 
 	      put_it_in( buffer, index, pTime.hour() );
 	      break;
 	    case 'I':
-	      put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 );
+	      if ( isDuration )
+	          put_it_in( buffer, index, pTime.hour() );
+	      else
+	          put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 );
 	      break;
 	    case 'M':
 	      put_it_in( buffer, index, pTime.minute() );
@@ -1631,20 +1640,21 @@ QString KLocale::formatTime(const QTime 
 	    case 'l':
 	      // to share the code
 	      if ( rst.at( format_index ).unicode() == 'l' )
-		number = (pTime.hour() + 11) % 12 + 1;
+		number = isDuration ? pTime.hour() : (pTime.hour() + 11) % 12 + 1;
 	      if ( number / 10 )
 		buffer[index++] = number / 10 + '0';
 	      buffer[index++] = number % 10 + '0';
 	      break;
 	    case 'p':
+	      if ( !isDuration )
 	      {
 		QString s;
 		if ( pTime.hour() >= 12 )
 		  put_it_in( buffer, index, translate("pm") );
 		else
 		  put_it_in( buffer, index, translate("am") );
-		break;
 	      }
+	      break;
 	    default:
 	      buffer[index++] = rst.at( format_index );
 	      break;
Index: klocale.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/klocale.h,v
retrieving revision 1.156
diff -u -p -r1.156 klocale.h
--- klocale.h	7 Apr 2004 22:43:29 -0000	1.156
+++ klocale.h	30 Apr 2004 09:19:49 -0000
@@ -441,10 +441,24 @@ public:
    * @param pTime The time to be formated.
    * @param includeSecs if true, seconds are included in the output,
    *        otherwise only hours and minutes are formatted.
+   * @param isDuration if true, the given time is a duration, not a clock time.
+   * This means "am/pm" shouldn't be displayed.
    *
    * @return The time as a string
    */
-  QString formatTime(const QTime &pTime, bool includeSecs = false) const;
+  QString formatTime(const QTime &pTime, bool includeSecs, bool isDuration /*=false*/) const;
+
+  /**
+   * Returns a string formatted to the current locale's conventions
+   * regarding times.
+   *
+   * @param pTime The time to be formated.
+   * @param includeSecs if true, seconds are included in the output,
+   *        otherwise only hours and minutes are formatted.
+   *
+   * @return The time as a string
+   */
+  QString formatTime(const QTime &pTime, bool includeSecs = false) const; // BIC: merge with above
 
   /**
    * Use this to determine if the user wants a 12 hour clock.


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
https://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