KDE Core/QtMerge/QDateTime: Difference between revisions

From KDE Community Wiki
No edit summary
Line 9: Line 9:
The following API design is based on the CLDR standard,and is not Source Compatible with Qt4.  The Qt4 API is inconsistent and requires modification to fully support CLDR, so the opportunity should be taken to fully overhaul the API.  Most apps will be unaffected as they will simply be using the default toString()/fromString() methods.
The following API design is based on the CLDR standard,and is not Source Compatible with Qt4.  The Qt4 API is inconsistent and requires modification to fully support CLDR, so the opportunity should be taken to fully overhaul the API.  Most apps will be unaffected as they will simply be using the default toString()/fromString() methods.


=== Object Model ===
The object model will be:
QLocale - The locale container, provides type of calendar system, date/time formats, and date/time name translations.
QCalendarSystem - A private virtual base class implementing Calendar System calculations.  Derived implementations like QCalendarSystemGregorian will also be private.  It is not intended to expose this class to public access at this time, but it may in the future once stable.
QDateTimeParser - Takes a QString, date/time format, QCalendarSystem, and QLocale and returns a QDateTime
QDateTimeFormatter - Takes a QDateTime, date/time format, QCalendarSystem, and QLocale and returns a QString
QDate - Holds a date as a Julian Day number, a QCalendarSystem calculator instance for converting the JD to/from YMD, a QLocale for use converting the JD to/from YMD and string formats
Note that by default the system QLocale and QCalendarSystem will be used by a default created QDate, but  these can both be over-ridden.


Replace the old enums:
Replace the old enums:


<syntaxhighlight lang="cpp-qt">
   enum QLocale::FormatType { LongFormat, ShortFormat, NarrowFormat };
   enum QLocale::FormatType { LongFormat, ShortFormat, NarrowFormat };


   enum QDate:MonthNameType { DateFormat = 0, StandaloneFormat };
   enum QDate::MonthNameType { DateFormat = 0, StandaloneFormat };


   enum Qt::DateFormat { TextDate,                    // default Qt
   enum Qt::DateFormat { TextDate,                    // default Qt
Line 25: Line 37:
                         DefaultLocaleShortDate,
                         DefaultLocaleShortDate,
                         DefaultLocaleLongDate };
                         DefaultLocaleLongDate };
</syntaxhighlight>


with new enums:
with new enums:


<syntaxhighlight lang="cpp-qt">
   // CLDR format length attribute for date/time/number/currency
   // CLDR format length attribute for date/time/number/currency
   enum QLocale::StringFormat { FullFormat,
   enum QLocale::StringFormat { FullFormat,
Line 59: Line 73:
                                   WeekFormat,
                                   WeekFormat,
                                   OrdinalFormat };
                                   OrdinalFormat };
</syntaxhighlight>


Replace the old name methods:
Replace the old name methods:


<syntaxhighlight lang="cpp-qt">
   QString QLocale::monthName(int month, FormatType format = LongFormat) const;
   QString QLocale::monthName(int month, FormatType format = LongFormat) const;
   QString QLocale::standaloneMonthName(int month, FormatType format = LongFormat) const;
   QString QLocale::standaloneMonthName(int month, FormatType format = LongFormat) const;
Line 71: Line 87:
   static QString QDate::longMonthName(int month, MonthNameType type = QDate::DateFormat);
   static QString QDate::longMonthName(int month, MonthNameType type = QDate::DateFormat);
   static QString QDate::longDayName(int weekday, MonthNameType type = QDate::DateFormat);
   static QString QDate::longDayName(int weekday, MonthNameType type = QDate::DateFormat);
</syntaxhighlight>


with new name methods:
with new name methods:


<syntaxhighlight lang="cpp-qt">
   QString QLocale::monthName(int month,
   QString QLocale::monthName(int month,
                             FieldFormat format = LongName,
                             FieldFormat format = LongName,
Line 83: Line 101:
                               FieldContext context = FormatContext,
                               FieldContext context = FormatContext,
                               CalendarSystem calendar = DefaultCalendar) const;
                               CalendarSystem calendar = DefaultCalendar) const;
</syntaxhighlight>


and extend with new feature name methods:
and extend with new feature name methods:


<syntaxhighlight lang="cpp-qt">
   QString QLocale::quarterName(int quarter,
   QString QLocale::quarterName(int quarter,
                               FieldFormat format = LongName,
                               FieldFormat format = LongName,
Line 101: Line 121:
                                 FieldContext context = FormatContext,
                                 FieldContext context = FormatContext,
                                 CalendarSystem calendar = DefaultCalendar) const;
                                 CalendarSystem calendar = DefaultCalendar) const;
</syntaxhighlight>


Note the QDate methods are removed as being redundent, see also the QDate::setLocale() method below.
Note the QDate methods are removed as being redundent, see also the QDate::setLocale() method below.
Line 106: Line 127:
Modify the date/time format methods to use the new enums:
Modify the date/time format methods to use the new enums:


<syntaxhighlight lang="cpp-qt">
   QString QLocale::dateFormat(StringFormat format = LongFormat);
   QString QLocale::dateFormat(StringFormat format = LongFormat);
   QString QLocale::timeFormat(StringFormat format = LongFormat);
   QString QLocale::timeFormat(StringFormat format = LongFormat);
   QString QLocale::dateTimeFormat(StringFormat format = LongFormat);
   QString QLocale::dateTimeFormat(StringFormat format = LongFormat);
</syntaxhighlight>


Remove all the QLocale toString(), toDate(), toTime(), toDateTime() methods, all formatting/parsing to be done in QDate/QTime/QDateTime
Remove all the QLocale toString(), toDate(), toTime(), toDateTime() methods, all formatting/parsing to be done in QDate/QTime/QDateTime
Line 114: Line 137:
Replace all the QDate toString() and fromString() methods with the following:
Replace all the QDate toString() and fromString() methods with the following:


<syntaxhighlight lang="cpp-qt">
   QString QDate::toString(const QString &format) const;
   QString QDate::toString(const QString &format) const;
   QString QDate::toString(QLocale::StringFormat format = QLocale::LongFormat) const;
   QString QDate::toString(QLocale::StringFormat format = QLocale::LongFormat) const;
Line 121: Line 145:
   static QDate QDate::fromString(const QString &string, QLocale::StringFormat format = QLocale::LongFormat);
   static QDate QDate::fromString(const QString &string, QLocale::StringFormat format = QLocale::LongFormat);
   static QDate QDate::fromString(const QString &string, QDateTime::DateTimeFormat format);
   static QDate QDate::fromString(const QString &string, QDateTime::DateTimeFormat format);
</syntaxhighlight>


Repeat exactly the same for QTime and QDateTime.
Repeat exactly the same for QTime and QDateTime.
Line 126: Line 151:
Add the following new methods to support calendar systems:
Add the following new methods to support calendar systems:


<syntaxhighlight lang="cpp-qt">
   CalendarSystem QLocale::calendarSystem()            // locale default calendar
   CalendarSystem QLocale::calendarSystem()            // locale default calendar
   QList<CalendarSystem> QLocale::calendarSystems()    // locale preferred list
   QList<CalendarSystem> QLocale::calendarSystems()    // locale preferred list
Line 140: Line 166:
   int QDate::weeksInYear()
   int QDate::weeksInYear()
   int QDate::daysInWeek()
   int QDate::daysInWeek()
</syntaxhighlight>

Revision as of 17:53, 3 August 2011

The initial proposal for merging KDE features in Qt5 as presented at QtCS is documented on the QtCS wiki at http://developer.qt.nokia.com/groups/qt_contributors_summit/wiki/QDateTime

This page documents specific API proposals.

Full CLDR Date Format and Calendar System support

The CLDR Date Format support and Calendar System support are closely connected and need to be designed together, although they will be separately implemented.

The following API design is based on the CLDR standard,and is not Source Compatible with Qt4. The Qt4 API is inconsistent and requires modification to fully support CLDR, so the opportunity should be taken to fully overhaul the API. Most apps will be unaffected as they will simply be using the default toString()/fromString() methods.

Object Model

The object model will be:

QLocale - The locale container, provides type of calendar system, date/time formats, and date/time name translations. QCalendarSystem - A private virtual base class implementing Calendar System calculations. Derived implementations like QCalendarSystemGregorian will also be private. It is not intended to expose this class to public access at this time, but it may in the future once stable. QDateTimeParser - Takes a QString, date/time format, QCalendarSystem, and QLocale and returns a QDateTime QDateTimeFormatter - Takes a QDateTime, date/time format, QCalendarSystem, and QLocale and returns a QString QDate - Holds a date as a Julian Day number, a QCalendarSystem calculator instance for converting the JD to/from YMD, a QLocale for use converting the JD to/from YMD and string formats

Note that by default the system QLocale and QCalendarSystem will be used by a default created QDate, but these can both be over-ridden.

Replace the old enums:

  enum QLocale::FormatType { LongFormat, ShortFormat, NarrowFormat };

  enum QDate::MonthNameType { DateFormat = 0, StandaloneFormat };

  enum Qt::DateFormat { TextDate,                     // default Qt
                        ISODate,                      // ISO 8601
                        SystemLocaleDate,             // deprecated
                        LocalDate = SystemLocaleDate, // deprecated
                        LocaleDate,                   // deprecated
                        SystemLocaleShortDate,
                        SystemLocaleLongDate,
                        DefaultLocaleShortDate,
                        DefaultLocaleLongDate };

with new enums:

  // CLDR format length attribute for date/time/number/currency
  enum QLocale::StringFormat { FullFormat,
                               LongFormat,
                               MediumFormat,
                               ShortFormat };

  // CLDR field width attribute
  enum QLocale::FieldFormat { LongName,      // e.g. January
                              ShortName,     // e.g. Jan
                              NarrowName,    // e.g. J
                              LongNumber,    // e.g. 01
                              ShortNumber }; // e.g. 1

  // CLDR context attribute
  enum QLocale::FieldContext { FormatContext,        // Use in a format
                               StandaloneContext };  // Use standalone

  // CLDR calendar attribute
  enum QLocale::CalendarSystem { DefaultCalendar = -1,  // i.e. locale default
                                 GregorianCalendar = 0,
                                 ... };

  // CLDR year type attribute
  // Would prefer in QDateTime namespace, but needed for QLocale::monthName()
  enum QLocale::YearType { StandardYear, LeapYear }

  enum QDateTime::DateTimeFormat { IsoFormat,
                                   RfcFormat,
                                   Rfc3339Format,	
                                   WeekFormat,
                                   OrdinalFormat };

Replace the old name methods:

  QString QLocale::monthName(int month, FormatType format = LongFormat) const;
  QString QLocale::standaloneMonthName(int month, FormatType format = LongFormat) const;
  QString QLocale::dayName(int weekday, FormatType format = LongFormat) const;
  QString QLocale::standaloneDayName(int weekday, FormatType format = LongFormat) const;

  static QString QDate::shortMonthName(int month, MonthNameType type = QDate::DateFormat);
  static QString QDate::shortDayName(int weekday, MonthNameType type = QDate::DateFormat);
  static QString QDate::longMonthName(int month, MonthNameType type = QDate::DateFormat);
  static QString QDate::longDayName(int weekday, MonthNameType type = QDate::DateFormat);

with new name methods:

  QString QLocale::monthName(int month,
                             FieldFormat format = LongName,
                             FieldContext context = FormatContext,
                             YearType yearType = StandardYear,
                             CalendarSystem calendar = DefaultCalendar) const;
  QString QLocale::weekdayName(int weekday,
                               FieldFormat format = LongName,
                               FieldContext context = FormatContext,
                               CalendarSystem calendar = DefaultCalendar) const;

and extend with new feature name methods:

  QString QLocale::quarterName(int quarter,
                               FieldFormat format = LongName,
                               FieldContext context = FormatContext,
                               CalendarSystem calendar = DefaultCalendar) const;
  QString QLocale::eraName(int year,
                           FieldFormat format = LongName,
                           FieldContext context = FormatContext,
                           CalendarSystem calendar = DefaultCalendar) const;
  QString QLocale::calendarName(CalendarSystem calendar = DefaultCalendar,
                                FieldFormat format = LongName,
                                FieldContext context = FormatContext) const;
  QString QLocale::dayPeriodName(QTime time,
                                 FieldFormat format = LongName,
                                 FieldContext context = FormatContext,
                                 CalendarSystem calendar = DefaultCalendar) const;

Note the QDate methods are removed as being redundent, see also the QDate::setLocale() method below.

Modify the date/time format methods to use the new enums:

  QString QLocale::dateFormat(StringFormat format = LongFormat);
  QString QLocale::timeFormat(StringFormat format = LongFormat);
  QString QLocale::dateTimeFormat(StringFormat format = LongFormat);

Remove all the QLocale toString(), toDate(), toTime(), toDateTime() methods, all formatting/parsing to be done in QDate/QTime/QDateTime

Replace all the QDate toString() and fromString() methods with the following:

  QString QDate::toString(const QString &format) const;
  QString QDate::toString(QLocale::StringFormat format = QLocale::LongFormat) const;
  QString QDate::toString(QDateTime::DateTimeFormat format) const;

  static QDate QDate::fromString(const QString &string, const QString &format);
  static QDate QDate::fromString(const QString &string, QLocale::StringFormat format = QLocale::LongFormat);
  static QDate QDate::fromString(const QString &string, QDateTime::DateTimeFormat format);

Repeat exactly the same for QTime and QDateTime.

Add the following new methods to support calendar systems:

  CalendarSystem QLocale::calendarSystem()            // locale default calendar
  QList<CalendarSystem> QLocale::calendarSystems()    // locale preferred list
  QList<CalendarSystem> QLocale::allCalendarSystems() // all calendars list

  void QDate::setCalendarSystem(KLocale::CalendarSystem calendar);
  QLocale::CalendarSystem QDate::calendarSystem();

  void QDate::setLocale(const QLocale & locale);
  QLocale QDate::locale();

  int QDate::eraYear()
  int QDate::monthsInYear()
  int QDate::weeksInYear()
  int QDate::daysInWeek()