Add fancy date format option to KLocale

David Jarvie lists at astrojar.org.uk
Sun Apr 8 19:53:19 BST 2007


On Sunday 08 April 2007 19:25:22 Pino Toscano wrote:
> Alle 15:38, domenica 8 aprile 2007, David Jarvie ha scritto:
> > > > 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)
>
> From what I see, maybe it would be better have two different enums, one for
> the type (ShortData, LongDate, ColloquialDate) - without flag - and another
> one for the options, like:
>
> enum DateTimeFormatOption {
>   NoOption = 0;
>   TimeZone = 1;
>   Seconds = 2;
> };
> Q_DECLARE_FLAGS(DateTimeFormatOptions, DateTimeFormatOption)
> maybe the names are too long - suggestion are welcome ;)

I can't think of a shorter enum name without making its usage too ambiguous. 
But I don't think it matters too much, since its name isn't likely to be used 
much except in the header file.

> Otherwise, with a single flag'ed enum I could call with eg ShortDate |
> LongDate, that does not make sense IMHO.

Good point. That will mean two option parameters for formatDateTime(), but 
just one for formatDate(). It makes the use of enums much cleaner.

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




More information about the kde-core-devel mailing list