Jump to content

KDE Core/QtMerge/QDateTime: Difference between revisions

From KDE Community Wiki
Jlayt (talk | contribs)
Jlayt (talk | contribs)
Line 1: Line 1:
The following are proposed additions to Qt's Date/Time support which KDE would like to see to enable dropping of our own Date/Time support, or would help improve Qt's localization under Win/OSX/CLDR.
The following are proposed additions to Qt's Date/Time support which KDE would like to see to enable dropping of our own Date/Time support, or would help improve Qt's localization under Win/OSX/CLDR.


== Date/Time Formats ==
== Date/Time Format Codes ==


Goal: To add more date/time to/from string format codes
Goal: To add more date/time to/from string format codes
Line 86: Line 86:


Note the month and day name api are already marked for change in Qt5.
Note the month and day name api are already marked for change in Qt5.
== Date/Time Named Formats ==
Goal: To add more date/time named formats
Rationale: Convenience for coders
Qt currently provides the following named date formats via an enum:
    enum DateFormat {
        TextDate,      // default Qt
        ISODate,      // ISO 8601
        SystemLocaleShortDate,
        SystemLocaleLongDate,
        DefaultLocaleShortDate,
        DefaultLocaleLongDate
    };
The following named date/time formats would be useful:
ISODateTime      ISO 8601 format, "[±]YYYY-MM-DDThh[:mm[:ss[.sss]]]TZ"
RFCDateTime      RFC 822/850/1036/1123/2822 format, "[Wdy,] DD Mon YYYY hh:mm[:ss] ±hhmm", "Wdy Mon DD HH:MM:SS YYYY"
RFCDateTimeDay  RFC format including day of the week, "Wdy, DD Mon YYYY hh:mm:ss ±hhmm"
RFC3339DateTime  RFC 3339 format, "YYYY-MM-DDThh:mm:ss[.sss](Z|±hh:mm)"
ISOWeekDate,    ISO 8601 Week Date format YYYY-Www-D, e.g. 2009-W01-1
ISOOrdinalDate  ISO 8601 Ordinal Date format YYYY-DDD, e.g. 2009-001


== Date Maths ==
== Date Maths ==

Revision as of 18:50, 20 May 2011

The following are proposed additions to Qt's Date/Time support which KDE would like to see to enable dropping of our own Date/Time support, or would help improve Qt's localization under Win/OSX/CLDR.

Date/Time Format Codes

Goal: To add more date/time to/from string format codes

Rationale: Format codes part of standard CLDR, Windows and OSX date formats and localization, so Qt may not be localizing dates to country or users system date/time format. Some are string form of existing Qt api.

QDateTime formats are based on the Unicode CLDR fomats:

However only a sub-set of these are implemented. Qt currently supports the following format codes:

d    Day as a number without a leading zero (1 to 31)
dd   Day as a number with a leading zero (01 to 31)
ddd  Weekday abbreviated localized name (e.g. 'Mon' to 'Sun').
dddd Weekday long localized name (e.g. 'Monday' to 'Sunday').
M    Month as a number without a leading zero (1 to 12)
MM   Month as a number with a leading zero (01 to 12)
MMM  Month abbreviated localized name (e.g. 'Jan' to 'Dec').
MMMM Month long localized name (e.g. 'January' to 'December').
yy   Year as two digit number (00 to 99)
yyyy Year as four digit number. (-9999 to 9999)
h    Hour without a leading zero (0 to 23 or 1 to 12 if AM/PM)
hh   Hour with a leading zero (00 to 23 or 01 to 12 if AM/PM)
H    24 Hour without a leading zero (0 to 23)
HH   24 Hour with a leading zero (00 to 23)
m    Minute without a leading zero (0 to 59)
mm   Minute with a leading zero (00 to 59)
s    Second without a leading zero (0 to 59)
ss   Second with a leading zero (00 to 59)
z    Milliseconds without leading zeroes (0 to 999)
zzz  Milliseconds with leading zeroes (000 to 999)
AP   AM/PM uppercase
ap   AM/PM lowercase
t    Timezone (for example "CEST")

Note the ddd and dddd formats are not valid CLDR forms, they should be EEE and EEEE instead. The h and hh formats do not exactly match the CLDR definition.

The following CLDR codes are suggested to be supported:

ddddd Day narrow localized name (e.g. 'M' to 'S').
MMMMM Month narrow localized name (e.g. 'J' to 'D').
y     Year without a leading zero (1 to 9999)
D (1..3)
Day of Year, numeric with or without leading zeros.  Matches existing dayOfYear() api.
w (1-2)
Week of Year, numeric with or without leading zero. Matches existing weekNumber() api.
Y (1..n)
Week year, e.g. for ISO Week Number year week falls in, forms to match y. Matches existing weekNumber() api.
E (1..5)
Weekday, abbreviated (e.g. 'Mon'), long (e.g. 'Monday') and narrow (e.g. 'M')
G (1..5)
Era localized name, abbreviated (e.g. 'AD'), long (e.g. 'Anno Domini') and narrow (e.g. 'A')

The following CLDR codes may be implemented but are not considered as important:

Q (1..4)
Quarter in year, '2', '02', 'Q2' or '2nd Quarter'
W (1)
Week of Month, numeric.
F (1)
Day of Week In Month, e.g. if today is 2nd Monday in Month = 2
e (1..5)
Weekday, localized numeric (1 or 01), abbreviated (e.g. 'Mon'), long (e.g. 'Monday') and narrow (e.g. 'M').  Would require QLocale support for localized week number, i.e. US week as well as ISO week.

The following new api will be required in QDateTime to support the format codes.

enum QDate::NameFormat( NarrowName, ShortName, LongName )
QString QDate::monthName(NameFormat format)
QString QDate::weekdayName(NameFormat format)
QStringQDate:: eraName(NameFormat format)
int QDate::quarter()
int QDate::weekOfMonth()
int QDate::weekdayInMonth()

Note the month and day name api are already marked for change in Qt5.

Date/Time Named Formats

Goal: To add more date/time named formats

Rationale: Convenience for coders

Qt currently provides the following named date formats via an enum:

   enum DateFormat {
       TextDate,      // default Qt
       ISODate,       // ISO 8601
       SystemLocaleShortDate,
       SystemLocaleLongDate,
       DefaultLocaleShortDate,
       DefaultLocaleLongDate
   };

The following named date/time formats would be useful:

ISODateTime      ISO 8601 format, "[±]YYYY-MM-DDThh[:mm[:ss[.sss]]]TZ"
RFCDateTime      RFC 822/850/1036/1123/2822 format, "[Wdy,] DD Mon YYYY hh:mm[:ss] ±hhmm", "Wdy Mon DD HH:MM:SS YYYY"
RFCDateTimeDay   RFC format including day of the week, "Wdy, DD Mon YYYY hh:mm:ss ±hhmm"
RFC3339DateTime  RFC 3339 format, "YYYY-MM-DDThh:mm:ss[.sss](Z|±hh:mm)"
ISOWeekDate,     ISO 8601 Week Date format YYYY-Www-D, e.g. 2009-W01-1
ISOOrdinalDate   ISO 8601 Ordinal Date format YYYY-DDD, e.g. 2009-001

Date Maths

Calendar Systems

Time Zones