Replacement for KDateTime

Martin Klapetek martin.klapetek at
Mon Aug 3 18:09:17 BST 2015

On Mon, Aug 3, 2015 at 6:34 PM, Thiago Macieira <thiago at> wrote:

> On Monday 03 August 2015 08:33:54 Martin Klapetek wrote:
> > > If the format you're looking for requires support from translators,
> please
> > > add
> > > a new class to QtCore.
> >
> > Suppose there's such QLocale setting as described above, then it would
> > be just a matter of some regexp inside the time formatting function which
> > would add/remove the "ap"/"AP" strings for the clock. I imagine.
> How would that setting be set? Who would set it? Is that something that the
> clock app would use and allow the user to set?
> If so, why not extract the time format and show that to the user? Or, at
> least, parse it to set the default of "Use 24-hour clock"? If the user
> wants
> to toggle 24-hour, save the new time format in the config file and use it
> to
> format the time next time.

I may have explained it poorly, so let me try again. tl;dr at the bottom :)

I can put a checkbox to the Plasma panel clock which would either
enable or disable 24h clock format. And in fact we do exactly that.
If the user wants to see 24h clock format in the panel, he can check
that checkbox. If he wants AM/PM clock, he can uncheck the checkbox.
Simple as that.

The implementation takes the Qt.locale().timeFormat(Locale.ShortFormat)
(it's QML), checks for the 24h clock option and either adds "AP"
or removes "AP" from the format string returned by Qt.locale().
The actual clock on the panel is then printed using
Qt.formatTime(currentTimeObject, thatModifiedTimeFormatString).

Now, this will affect _only_ the Plasma panel clock. This will _not_
affect Dolphin's time stamps, Gwenview's picture-taken times,
this won't affect anything else but the panel clock and the panel clock
alone. But if I want to have 24h clock format, I want it everywhere,
in all apps, system-wide, not _only_ in the panel clock. Everything
else will be however using time formatted by the LC_TIME locale
default format.

Currently each and every application would have to implement similar
code as the Plasma panel clock - get the locale's time format string,
check for some config, add/remove "AP" from the format string, print
the time using QDateTime().toString(theModifiedTimeFormatString).
Or each application would have to read the date/time format string
from somewhere, some global config in order to have the same time
format everywhere.

Is it clear now? Do you see what I'm getting at?

Setting different LC_TIME values proven to not be feasible, because
very often users want "just" 24h clock format _and_ their locale's
date format. Or some date format and their locale's time format.

Ideally there would be a global setting, set from System Settings,
perhaps written into ~/.config/QtProject.conf, which QLocale could
internally read and return the time formatted according to that setting
already. This would spare every single application doing it on its own.
Then, calling QDateTime().toString() or QLocale().toString(QDateTime)
would return the time formatted by user preference already and it would
return it in all apps, uniformly, same format.

I guess such feature might not be feasible for QLocale, hence my
suggestion to bring back KLocale in a limited form, purely for global
date/time formatting purposes around KDE apps, to have the same
date/time format everywhere around.

As a side note, missing global date/time format setting is a regression
from the kde4 times.


tl;dr - it'd be nice to be able to set a custom time format for all
QLocale users without them needing to do anything at all.

Hope it's clear now :)

Martin Klapetek | KDE Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the kde-core-devel mailing list