Request to add formatInterval to klocale
Simon Hausmann
hausmann at kde.org
Sun Dec 10 14:21:32 GMT 2006
On Sunday 10 December 2006 04:04, John Tapsell wrote:
> Hi all,
>
> In KLocale there is a formatNumber, formatTime, formatByteSize etc.
>
> I would like to add a formatInterval(unsigned long msec), which
> formats a time interval.
>
> The would be fairly clean and straight forward as so:
>
>
>
> Index: klocale.h
> ===================================================================
> --- klocale.h (revision 606175)
> +++ klocale.h (working copy)
> @@ -424,6 +424,16 @@
> QString formatByteSize( double size ) const;
>
> /**
> + * Given a number of milliseconds, converts that to a string containing
> + * the localized equivalent
> + *
> + * e.g. given formatInterval(60000), returns "1.0 minutes"
> + *
> + * @param mSec Time interval in milliseconds
> + * @return converted interval as a string - e.g. "5.5 seconds" "23.0
> minutes" + */
> + QString formatInterval( unsigned long mSec) const;
> + /**
> * Use this to determine whether nouns are declined in
> * locale's language. This property should remain
> * read-only (no setter function)
> Index: klocale.cpp
> ===================================================================
> --- klocale.cpp (revision 606175)
> +++ klocale.cpp (working copy)
> @@ -1103,6 +1103,25 @@
> return s;
> }
>
> +QString KLocale::formatInterval( unsigned long mSec) const
> +{
> + QString s;
> + if( size >= 24*3600000) {
> + s = i18n( "%1 days", formatNumber( size/(24*3600000), 3));
> + } else if(size >= 3600000)
> + {
> + s = i18n( "%1 hours", formatNumber( size/3600000.0, 2));
> + } else if(size >= 60000)
> + {
> + s = i18n( "%1 minutes", formatNumber( size/60000.0, 2));
> + } else if(size >= 1000)
> + {
> + s = i18n( "%1 seconds", formatNumber( size/1000.0, 2));
> + } else
> + {
> + s = i18n( "%1 milliseconds", formatNumber(size, 0));
> + }
> +}
return s; is missing there :)
Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20061210/10aa44c6/attachment.sig>
More information about the kde-core-devel
mailing list