Add fancy date format option to KLocale

David Jarvie lists at astrojar.org.uk
Sun Apr 8 14:38:52 BST 2007


On Sunday 08 April 2007 02:02:24 Andreas Hartmetz wrote:
> 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].

Yes, I think ColloquialDate is a better name.

> > 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 did think of combining the other boolean parameters with the first one, but 
mainly because of shortage of time I didn't bother. But you're right - it 
should be done at the same time as changing the first bool parameter. I'll 
expand the enum:

enum DateFormat {
  ShortDate, LongDate, FancyDate
  TimeZone,
  Seconds
};

and declare

Q_DECLARE_FLAGS(DateTimeFormat, DateFormat)

formatDate() will take a DateFormat parameter, while formatDateTime() will 
take a DateTimeFormat parameter. TimeZone and Seconds values will be ignored 
by formatDate(). It's not ideal using basically the same enum for 
formatDate() and formatDateTime(), but this seems the most obvious way to do 
it.

-- 
David Jarvie.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm




More information about the kde-core-devel mailing list