Add fancy date format option to KLocale

Andreas Hartmetz ahartmetz at gmail.com
Sun Apr 8 02:02:24 BST 2007


On Sunday 08 April 2007 01:48:33 David Jarvie wrote:
> Tom Albers asked to add a fancy date/time string format option to KDateTime
> (if the date is in the last week, replace it by Today, Yesterday, or the
> weekday name). This is a function currently in kdepimlibs/kmime. I think
> that this really belongs in KLocale rather than KDateTime, since only
> KLocale knows the format in which a date/time value should be displayed in
> the current locale. I therefore propose to amend KLocale::formatDateTime()
> and formatDate() to replace the second (bool shortFormat) parameter with an
> enum:
>
> enum DateFormat {
> 	ShortDate, LongDate, FancyDate
> };
>
Hmmm, ColloquialDate or similar might be a better name for FancyDate. Ignore 
me on that one if you know better because English is your mother tongue, or 
because I don't know enough about the issue [i.e. what one can infer from the 
mail thread].

> QString formatDate(const QDate&, DateFormat = ShortDate);
> QString formatDateTime(const QDateTime&, DateFormat = ShortDate,
>     bool includeSeconds = false);
> QString formatDateTime(const KDateTime&, DateFormat = ShortDate,
>     bool includeSeconds = false, bool includeTimeZone = false);
>
We "officially dislike" boolean arguments if their meaning is unclear when 
somebody reads the code. You could add more enum elements and maybe make 
flags (as in QFlags) out of all boolean options if that looks advantageous.

> I will initially add these methods and deprecate the existing
> formatDateTime() ones, since I doubt whether I'll be able to convert the
> whole of KDE by the end of Monday. I'll complete the conversion as soon as
> I can during the week to come, and remove the deprecated methods a week on
> Monday.
>
> Please let me know if there are any objections.

I'm not familiar with KLocale or KDateTime, but sounds good... yeah. :]

Cheers,
Andreas




More information about the kde-core-devel mailing list