Version: 1.0 (using KDE 4.4.1) Installed from: Fedora RPMs At the moment, "kdialog --calendar Title" returns the result depending on locale: | [tim@passepartout ~]$ kdialog --calendar Title | Di. Mrz 30 2010 | [tim@passepartout ~]$ LANG=en_GB kdialog --calendar Title | Tue Mar 30 2010 | [tim@passepartout ~]$ In most cases, this cannot be easily processed by the calling script and/or other programs down the line. Therefore, it would be nice to have an option to get the result in ISO 8601 format ("YYYY-MM-DD").
I don't think it should be locale independent by default (after all, KDE goes to a great deal of trouble to localise your desktop). I can see a potential use for an ISO-8601 Extended Format date though, based on some modified option. Would you prefer this to be a separate option (i.e. something in place of --calendar) or a modifier to the current --calendar option (i.e. --calendar --something) or controlled by an environment variable? Brad
I think the modifier would be the best way. An environment variable could introduce subtle bugs and a separate option - well, the calendar stays the same after all :-). One interesting approach would be to allow to specify the date format itself that gets passed to QDate::toString () so that users wouldn't be stuck with "standard locale format or ISO 8601" but could use the whole palette.
Sounds reasonable, so there would be a modifier that looks like --dateformat="yyyy-MM-dd" if you wanted (in this case) ISO 8601 Extended Format dates. Feel like proposing a patch? Looks like it should only affect kdialog.cpp.
I'd just point out you would probably want to use KGlobal::locale()->calendar()->formatDate() rather than QString::toString() to ensure you get the localised Calendar System, in which case the date format string would actually be "%Y-%m-%d", or the enum KLocale:IsoFormat.
(In reply to comment #3) > Sounds reasonable, so there would be a modifier that looks like > --dateformat="yyyy-MM-dd" if you wanted (in this case) ISO 8601 Extended Format > dates. > Feel like proposing a patch? Looks like it should only affect kdialog.cpp. I'm sorry, but considering my knowledge of KDE/Qt I'd rather let someone more experienced do that job :-).
John, I think we're now trying to pass the format as a parameter, so we'd need to be using the QString KCalendarSystem::formatDate ( const QDate & fromDate, const QString & toFormat, KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat ) API. Is there a way to say "give me whatever QDate's toString() method would have provided"? I'm very reluctant to break existing scripts that count on the old format. Brad
Not yet. I'm planning to add support for the Unicode format standard (http://unicode.org/reports/tr35/#Date_Format_Patterns) as used by Qt, hence the formatStandard parameter, it's just a case of finding the time to do so. I'll probably just copy the Qt code, so it shouldn't take long to do. Give me a couple of days and I'll get back to you.
In kdelibs in SC 4.5 you can now call KGlobal::locale()->calendar()->formatDate( fromDate, "yyyy-MM-dd", KLocale::UnicodeFormat ) to get the same result as QDate::toString(). Note that the reverse is not available, i.e. QDate::fromString.
Git commit 174444b6bfce6b817b4130c5b08fcf78ebd7a722 by David Faure. Committed on 23/06/2020 at 18:05. Pushed by dfaure into branch 'master'. Add option for specifying calendar's date format Summary: The new option --dateformat can be used to change the default date format used by --calendar. The default format 'ddd MMM d yyyy' is no explicitly stated. We can't change the default as scripts in the wild probably expect this format by now. When using locales other than C, 'date' does not understand this format, though. The new option makes it easy to use e.g. the ISO format ('yyyy-MM-dd'). Reviewers: #kdialog, dfaure Reviewed By: #kdialog, dfaure Differential Revision: https://phabricator.kde.org/D29777 M +8 -1 src/kdialog.cpp https://invent.kde.org/utilities/kdialog/commit/174444b6bfce6b817b4130c5b08fcf78ebd7a722