← Back to team overview

ubuntu-touch-coreapps team mailing list archive

[Calendar] [Clock] i18n.language aware date and time formatting

 

Hi,

there was some confusion within the calendar team about how to format dates and times
correctly. Qt.formatTime() seems to uses the C-library's locale formatting. The problem
with that is, that it is not dynamically bound to the i18n property. Therefore the language
change wouldn't affect the running application's time display. In the details lies the devil!

Anyway, I found, that Qt extends the Javascript Date object:

http://qt-project.org/doc/qt-5.0/qtqml/qml-qtquick2-date.html

And this allows to write the following to format the current time:

new Date().toLocaleTimeString(Qt.locale(i18n.language), Locale.ShortFormat)

Which is then avoiding any dynamic translation problems, because it binds to i18n;)

Cheers,
frank

-- 
gplus.to/frankencode
frankencode@freenode


Follow ups