KLocale::formatDate()
David Faure
faure at kde.org
Sun Feb 4 23:07:12 GMT 2007
On Sunday 04 February 2007, Adriaan de Groot wrote:
> On Sunday 04 February 2007 21:54, Reinhold Kainhofer wrote:
> > Am Son Feb 4 2007 schrieb David Faure:
> > > On Saturday 03 February 2007, Adriaan de Groot wrote:
> > > > I'm asking in particular because I found some code that does:
> > >
> > > Why doesn't this code create a different KLocale object, set the date
> > > format on it, and use it to format dates?
> >
> > Because I needed a workaround for the "missing" general formatDate( const
> > QDate &, const QString &format) method, and this was the first hack that
> > came to my mind...
>
> Reinhold: I was trying to anonymize the code, eh.
:-)
> David: API bloat follows, but no code duplication since you end up with
>
> /* static */ QString KLocale::formatDate(const QDate&, const QString &format);
> QString KLocale::formatDate(const QDate &d)
> {
> formatDate(d,dateFormat());
> }
Of course. I didn't mean code duplication, but api duplication - even more
formatDate methods than we have already.
> Well, almost, since you need the calendar() object from the locale, too.
Right. So it can't be a static method, but a member method does the job.
> I don't know what it costs to create a spare KLocale object, it just seems very
> extra-kludgy to me.
(unless you need to do more than one reading/formatting with the given format)
But indeed there's a lot of initialization in klocale so better avoid doing that
too many times, I agree. I just don't like the resulting API - for consistency and
completeness we need to have overloads that pass a format to formatNumber,
formatMoney, formatLong, formatDate, formatTime, formatDateTime(QDateTime)
and formatDateTime(KDateTime)? See that's quite a lot of api bloat...
And generally speaking, it just encourages to hardcode formats in the applications.
Just my 2 cents, if there's really much code that needs this then I'm not really objecting.
--
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
More information about the kde-core-devel
mailing list