Bug 232712 - RFE: --calendar should return result independent on locale
Summary: RFE: --calendar should return result independent on locale
Status: RESOLVED FIXED
Alias: None
Product: kdialog
Classification: Applications
Component: general (show other bugs)
Version: 1.0
Platform: Fedora RPMs Unspecified
: NOR wishlist
Target Milestone: ---
Assignee: Brad Hards
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-30 16:20 UTC by Tim Landscheidt
Modified: 2020-06-23 18:05 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Landscheidt 2010-03-30 16:20:08 UTC
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").
Comment 1 Brad Hards 2010-03-31 01:29:20 UTC
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
Comment 2 Tim Landscheidt 2010-03-31 01:58:54 UTC
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.
Comment 3 Brad Hards 2010-03-31 02:04:54 UTC
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.
Comment 4 John Layt 2010-04-02 22:54:05 UTC
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.
Comment 5 Tim Landscheidt 2010-04-03 01:03:45 UTC
(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 :-).
Comment 6 Brad Hards 2010-04-03 12:52:32 UTC
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
Comment 7 John Layt 2010-04-12 23:54:22 UTC
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.
Comment 8 John Layt 2010-06-08 17:48:57 UTC
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.
Comment 9 David Faure 2020-06-23 18:05:54 UTC
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