[PATCH 23/23] kcalendarsystem: Merge KCalendarSystemQDate into KCalendarSystemGregorian.
Jon Severinsson
jon at severinsson.net
Fri Oct 12 15:13:58 UTC 2012
QDate uses a proleptic gregorian calendar system as of Qt5, so the two
is (or at least should be) identical.
Also update the new merged callendar to match the new (larger) QDate range.
---
kdecore/CMakeLists.txt | 1 -
kdecore/date/kcalendarsystem.cpp | 16 +-
kdecore/date/kcalendarsystemgregorian.cpp | 106 ++------
kdecore/date/kcalendarsystemminguo.cpp | 12 +
kdecore/date/kcalendarsystemqdate.cpp | 411 -----------------------------
kdecore/date/kcalendarsystemqdate_p.h | 75 ------
kdecore/date/kcalendarsystemthai.cpp | 12 +
kdecore/date/kdatetime.cpp | 4 +-
kdecore/localization/klocale.h | 7 +-
kdecore/localization/klocale_kde.cpp | 4 +-
kdecore/tests/kcalendartest.cpp | 196 ++++----------
kdecore/tests/kcalendartest.h | 24 +-
12 filer ändrade, 129 tillägg(+), 739 borttagningar(-)
delete mode 100644 kdecore/date/kcalendarsystemqdate.cpp
delete mode 100644 kdecore/date/kcalendarsystemqdate_p.h
diff --git a/kdecore/CMakeLists.txt b/kdecore/CMakeLists.txt
index 068919f..412ccfc 100644
--- a/kdecore/CMakeLists.txt
+++ b/kdecore/CMakeLists.txt
@@ -153,7 +153,6 @@ set(kdecore_LIB_SRCS
date/kcalendarsystem.cpp
date/kcalendarsystemcoptic.cpp
date/kcalendarsystemethiopian.cpp
- date/kcalendarsystemqdate.cpp
date/kcalendarsystemgregorian.cpp
date/kcalendarsystemislamiccivil.cpp
date/kcalendarsystemhebrew.cpp
diff --git a/kdecore/date/kcalendarsystem.cpp b/kdecore/date/kcalendarsystem.cpp
index 2acaa1a..2e40068 100644
--- a/kdecore/date/kcalendarsystem.cpp
+++ b/kdecore/date/kcalendarsystem.cpp
@@ -41,7 +41,6 @@
#include "kcalendarsystemjapanese_p.h"
#include "kcalendarsystemjulian_p.h"
#include "kcalendarsystemminguo_p.h"
-#include "kcalendarsystemqdate_p.h"
#include "kcalendarsystemthai_p.h"
KCalendarSystem *KCalendarSystem::create(KLocale::CalendarSystem calendarSystem, const KLocale *locale)
@@ -54,14 +53,12 @@ KCalendarSystem *KCalendarSystem::create(KLocale::CalendarSystem calendarSystem,
const KLocale *locale)
{
switch (calendarSystem) {
- case KLocale::QDateCalendar:
- return new KCalendarSystemQDate(config, locale);
+ case KLocale::GregorianCalendar:
+ return new KCalendarSystemGregorian(config, locale);
case KLocale::CopticCalendar:
return new KCalendarSystemCoptic(config, locale);
case KLocale::EthiopianCalendar:
return new KCalendarSystemEthiopian(config, locale);
- case KLocale::GregorianCalendar:
- return new KCalendarSystemGregorian(config, locale);
case KLocale::HebrewCalendar:
return new KCalendarSystemHebrew(config, locale);
case KLocale::IndianNationalCalendar:
@@ -79,7 +76,7 @@ KCalendarSystem *KCalendarSystem::create(KLocale::CalendarSystem calendarSystem,
case KLocale::ThaiCalendar:
return new KCalendarSystemThai(config, locale);
default:
- return new KCalendarSystemQDate(config, locale);
+ return new KCalendarSystemGregorian(config, locale);
}
}
@@ -87,10 +84,9 @@ QList<KLocale::CalendarSystem> KCalendarSystem::calendarSystemsList()
{
QList<KLocale::CalendarSystem> list;
- list.append(KLocale::QDateCalendar);
+ list.append(KLocale::GregorianCalendar);
list.append(KLocale::CopticCalendar);
list.append(KLocale::EthiopianCalendar);
- list.append(KLocale::GregorianCalendar);
list.append(KLocale::HebrewCalendar);
list.append(KLocale::IslamicCivilCalendar);
list.append(KLocale::IndianNationalCalendar);
@@ -106,14 +102,12 @@ QList<KLocale::CalendarSystem> KCalendarSystem::calendarSystemsList()
QString KCalendarSystem::calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale)
{
switch (calendarSystem) {
- case KLocale::QDateCalendar:
+ case KLocale::GregorianCalendar:
return ki18nc("@item Calendar system", "Gregorian").toString(locale);
case KLocale::CopticCalendar:
return ki18nc("@item Calendar system", "Coptic").toString(locale);
case KLocale::EthiopianCalendar:
return ki18nc("@item Calendar system", "Ethiopian").toString(locale);
- case KLocale::GregorianCalendar:
- return ki18nc("@item Calendar system", "Gregorian (Proleptic)").toString(locale);
case KLocale::HebrewCalendar:
return ki18nc("@item Calendar system", "Hebrew").toString(locale);
case KLocale::IslamicCivilCalendar:
diff --git a/kdecore/date/kcalendarsystemgregorian.cpp b/kdecore/date/kcalendarsystemgregorian.cpp
index 12ee9b7..9a0d8c3 100644
--- a/kdecore/date/kcalendarsystemgregorian.cpp
+++ b/kdecore/date/kcalendarsystemgregorian.cpp
@@ -41,8 +41,6 @@ KCalendarSystemGregorianPrivate::~KCalendarSystemGregorianPrivate()
{
}
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
void KCalendarSystemGregorianPrivate::loadDefaultEraList()
{
QString name, shortName, format;
@@ -80,19 +78,10 @@ int KCalendarSystemGregorianPrivate::monthsInYear(int year) const
int KCalendarSystemGregorianPrivate::daysInMonth(int year, int month) const
{
- if (month == 2) {
- if (isLeapYear(year)) {
- return 29;
- } else {
- return 28;
- }
- }
-
- if (month == 4 || month == 6 || month == 9 || month == 11) {
- return 30;
+ if (hasYearZero() && year <= 0) {
+ --year;
}
-
- return 31;
+ return QDate(year, month, 1).daysInMonth();
}
int KCalendarSystemGregorianPrivate::daysInYear(int year) const
@@ -106,19 +95,10 @@ int KCalendarSystemGregorianPrivate::daysInYear(int year) const
bool KCalendarSystemGregorianPrivate::isLeapYear(int year) const
{
- if (!hasYearZero() && year < 1) {
- year = year + 1;
+ if (hasYearZero() && year <= 0) {
+ --year;
}
-
- if (year % 4 == 0) {
- if (year % 100 != 0) {
- return true;
- } else if (year % 400 == 0) {
- return true;
- }
- }
-
- return false;
+ return QDate::isLeapYear(year);
}
bool KCalendarSystemGregorianPrivate::hasLeapMonths() const
@@ -138,7 +118,7 @@ int KCalendarSystemGregorianPrivate::maxMonthsInYear() const
int KCalendarSystemGregorianPrivate::earliestValidYear() const
{
- return -4713;
+ return -9999;
}
int KCalendarSystemGregorianPrivate::latestValidYear() const
@@ -168,7 +148,7 @@ KCalendarSystemGregorian::~KCalendarSystemGregorian()
QString KCalendarSystemGregorian::calendarType() const
{
- return QLatin1String("gregorian-proleptic");
+ return QLatin1String("gregorian");
}
KLocale::CalendarSystem KCalendarSystemGregorian::calendarSystem() const
@@ -183,16 +163,19 @@ QDate KCalendarSystemGregorian::epoch() const
QDate KCalendarSystemGregorian::earliestValidDate() const
{
- // Gregorian 1 Jan 4713 BC, no year zero
- return QDate::fromJulianDay(38);
+ Q_D(const KCalendarSystemGregorian);
+
+ // Set to first day of year 9999 until confirm date formats & widgets support > 9999
+ return QDate(d->hasYearZero() ? -1000 : -9999, 1, 1);
+ // return QDate(std::num_limits<int>::min(), 1, 1);
}
QDate KCalendarSystemGregorian::latestValidDate() const
{
// Set to last day of year 9999 until confirm date formats & widgets support > 9999
// In Gregorian this is 9999-12-31, which is is jd 5373484
- // Can't call setDate( 9999, 12, 31 ) as it creates circular reference!
- return QDate::fromJulianDay(5373484);
+ return QDate(9999, 12, 31);
+ // return QDate(std::num_limits<int>::max(), 12, 31);
}
int KCalendarSystemGregorian::yearStringToInteger(const QString &sNum, int &iLength) const
@@ -224,62 +207,29 @@ bool KCalendarSystemGregorian::julianDayToDate(qint64 jd, int &year, int &month,
{
Q_D(const KCalendarSystemGregorian);
- // Formula from The Calendar FAQ by Claus Tondering
- // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000
- // NOTE: Coded from scratch from mathematical formulas, not copied from
- // the Boost licensed source code
-
- int a = jd + 32044;
- int b = ((4 * a) + 3) / 146097;
- int c = a - ((146097 * b) / 4);
- int dd = ((4 * c) + 3) / 1461;
- int e = c - ((1461 * dd) / 4);
- int m = ((5 * e) + 2) / 153;
- day = e - (((153 * m) + 2) / 5) + 1;
- month = m + 3 - (12 * (m / 10));
- year = (100 * b) + dd - 4800 + (m / 10);
-
- // If year is -ve then is BC. In Gregorian there is no year 0, but the maths
- // is easier if we pretend there is, so internally year of 0 = 1BC = -1 outside
- // Check for Year 0 support as some Gregorian based calendars do have it, e.g. Thai and ISO
- if (!d->hasYearZero() && year < 1) {
- year = year - 1;
+ QDate date = QDate::fromJulianDay(jd);
+ date.getDate(&year, &month, &day);
+
+ if (d->hasYearZero() && year < 0) {
+ ++year;
}
- return true;
+
+ return date.isValid();
}
bool KCalendarSystemGregorian::dateToJulianDay(int year, int month, int day, qint64 &jd) const
{
Q_D(const KCalendarSystemGregorian);
- // Formula from The Calendar FAQ by Claus Tondering
- // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000
- // NOTE: Coded from scratch from mathematical formulas, not copied from
- // the Boost licensed source code
-
- // If year is -ve then is BC. In Gregorian there is no year 0, but the maths
- // is easier if we pretend there is, so internally year of -1 = 1BC = 0 internally
- // Check for Year 0 support as some Gregorian based calendars do have it, e.g. Thai and ISO
- int y;
- if (!d->hasYearZero() && year < 1) {
- y = year + 1;
- } else {
- y = year;
+ if (d->hasYearZero() && year <= 0) {
+ --year;
}
- int a = (14 - month) / 12;
- y = y + 4800 - a;
- int m = month + (12 * a) - 3;
+ QDate date;
+ date.setDate(year, month, day);
- jd = day
- + (((153 * m) + 2) / 5)
- + (365 * y)
- + (y / 4)
- - (y / 100)
- + (y / 400)
- - 32045;
-
- return true;
+ jd = date.toJulianDay();
+ return date.isValid();
}
QString KCalendarSystemGregorian::monthName(int month, int year, MonthNameFormat format) const
diff --git a/kdecore/date/kcalendarsystemminguo.cpp b/kdecore/date/kcalendarsystemminguo.cpp
index 9f1c156..8d2cfb5 100644
--- a/kdecore/date/kcalendarsystemminguo.cpp
+++ b/kdecore/date/kcalendarsystemminguo.cpp
@@ -33,6 +33,8 @@ public:
virtual ~KCalendarSystemMinguoPrivate();
virtual void loadDefaultEraList();
+ virtual int daysInMonth(int year, int month) const;
+ virtual int daysInYear(int year) const;
virtual bool isLeapYear(int year) const;
virtual int earliestValidYear() const;
};
@@ -58,6 +60,16 @@ void KCalendarSystemMinguoPrivate::loadDefaultEraList()
addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
}
+int KCalendarSystemMinguoPrivate::daysInMonth(int year, int month) const
+{
+ return KCalendarSystemGregorianPrivate::daysInMonth(year + 1911, month);
+}
+
+int KCalendarSystemMinguoPrivate::daysInYear(int year) const
+{
+ return KCalendarSystemGregorianPrivate::daysInYear(year + 1911);
+}
+
bool KCalendarSystemMinguoPrivate::isLeapYear(int year) const
{
return KCalendarSystemGregorianPrivate::isLeapYear(year + 1911);
diff --git a/kdecore/date/kcalendarsystemqdate.cpp b/kdecore/date/kcalendarsystemqdate.cpp
deleted file mode 100644
index bcbd2b2..0000000
--- a/kdecore/date/kcalendarsystemqdate.cpp
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- Copyright (c) 2002 Carlos Moro <cfmoro at correo.uniovi.es>
- Copyright (c) 2002-2003 Hans Petter Bieker <bieker at kde.org>
- Copyright 2007, 2010 John Layt <john at layt.net>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-// Derived QDate kde calendar class
-
-#include "kcalendarsystemqdate_p.h"
-#include "kcalendarsystemprivate_p.h"
-#include "kcalendarera_p.h"
-
-#include "kdebug.h"
-#include "klocale.h"
-#include "kconfiggroup.h"
-
-#include <QtCore/QDate>
-#include <QtCore/QCharRef>
-
-class KCalendarSystemQDatePrivate : public KCalendarSystemPrivate
-{
-public:
- explicit KCalendarSystemQDatePrivate(KCalendarSystemQDate *q);
-
- virtual ~KCalendarSystemQDatePrivate();
-
- // Virtual methods each calendar system must re-implement
- virtual void loadDefaultEraList();
- virtual int monthsInYear(int year) const;
- virtual int daysInMonth(int year, int month) const;
- virtual int daysInYear(int year) const;
- virtual bool isLeapYear(int year) const;
- virtual bool hasLeapMonths() const;
- virtual bool hasYearZero() const;
- virtual int maxMonthsInYear() const;
- virtual int earliestValidYear() const;
- virtual int latestValidYear() const;
-
- bool m_useCommonEra;
-};
-
-// Shared d pointer implementations
-
-KCalendarSystemQDatePrivate::KCalendarSystemQDatePrivate(KCalendarSystemQDate *q)
- : KCalendarSystemPrivate(q),
- m_useCommonEra(false)
-
-{
-}
-
-KCalendarSystemQDatePrivate::~KCalendarSystemQDatePrivate()
-{
-}
-
-void KCalendarSystemQDatePrivate::loadDefaultEraList()
-{
- QString name, shortName, format;
-
- KConfigGroup lcg(config(), QString::fromLatin1("Locale"));
- KConfigGroup cg = lcg.group(QString::fromLatin1("KCalendarSystem %1").arg(q->calendarType()));
- m_useCommonEra = cg.readEntry("UseCommonEra", false);
-
- if (m_useCommonEra) {
- name = i18nc("Calendar Era: Gregorian Common Era, years < 0, LongFormat", "Before Common Era");
- shortName = i18nc("Calendar Era: Gregorian Common Era, years < 0, ShortFormat", "BCE");
- } else {
- name = i18nc("Calendar Era: Gregorian Christian Era, years < 0, LongFormat", "Before Christ");
- shortName = i18nc("Calendar Era: Gregorian Christian Era, years < 0, ShortFormat", "BC");
- }
- format = i18nc("(kdedt-format) Gregorian, BC, full era year format used for %EY, e.g. 2000 BC", "%Ey %EC");
- addEra('-', 1, q->epoch().addDays(-1), -1, q->earliestValidDate(), name, shortName, format);
-
- if (m_useCommonEra) {
- name = i18nc("Calendar Era: Gregorian Common Era, years > 0, LongFormat", "Common Era");
- shortName = i18nc("Calendar Era: Gregorian Common Era, years > 0, ShortFormat", "CE");
- } else {
- name = i18nc("Calendar Era: Gregorian Christian Era, years > 0, LongFormat", "Anno Domini");
- shortName = i18nc("Calendar Era: Gregorian Christian Era, years > 0, ShortFormat", "AD");
- }
- format = i18nc("(kdedt-format) Gregorian, AD, full era year format used for %EY, e.g. 2000 AD", "%Ey %EC");
- addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
-}
-
-int KCalendarSystemQDatePrivate::monthsInYear(int year) const
-{
- Q_UNUSED(year)
- return 12;
-}
-
-int KCalendarSystemQDatePrivate::daysInMonth(int year, int month) const
-{
- QDate tempDate(year, month, 1);
- return tempDate.daysInMonth();
-}
-
-int KCalendarSystemQDatePrivate::daysInYear(int year) const
-{
- QDate tempDate(year, 1, 1);
- return tempDate.daysInYear();
-}
-
-bool KCalendarSystemQDatePrivate::isLeapYear(int year) const
-{
- return QDate::isLeapYear(year);
-}
-
-bool KCalendarSystemQDatePrivate::hasLeapMonths() const
-{
- return false;
-}
-
-bool KCalendarSystemQDatePrivate::hasYearZero() const
-{
- return false;
-}
-
-int KCalendarSystemQDatePrivate::maxMonthsInYear() const
-{
- return 12;
-}
-
-int KCalendarSystemQDatePrivate::earliestValidYear() const
-{
- return -4712;
-}
-
-int KCalendarSystemQDatePrivate::latestValidYear() const
-{
- return 9999;
-}
-
-
-KCalendarSystemQDate::KCalendarSystemQDate(const KSharedConfig::Ptr config, const KLocale *locale)
- : KCalendarSystem(*new KCalendarSystemQDatePrivate(this), config, locale)
-{
- d_ptr->loadConfig(calendarType());
-}
-
-KCalendarSystemQDate::KCalendarSystemQDate(KCalendarSystemQDatePrivate &dd, const KSharedConfig::Ptr config, const KLocale *locale)
- : KCalendarSystem(dd, config, locale)
-{
- d_ptr->loadConfig(calendarType());
-}
-
-KCalendarSystemQDate::~KCalendarSystemQDate()
-{
-}
-
-QString KCalendarSystemQDate::calendarType() const
-{
- return QLatin1String("gregorian");
-}
-
-KLocale::CalendarSystem KCalendarSystemQDate::calendarSystem() const
-{
- return KLocale::QDateCalendar;
-}
-
-QDate KCalendarSystemQDate::epoch() const
-{
- // 1 Jan 1 AD in Julian
- return QDate::fromJulianDay(1721424);
-}
-
-QDate KCalendarSystemQDate::earliestValidDate() const
-{
- // 1 Jan 4712 BC, no year zero, cant be 4713BC due to error in QDate that day 0 is not valid
- // and we really need the first in each year to be valid for the date maths
- return QDate::fromJulianDay(366);
-}
-
-QDate KCalendarSystemQDate::latestValidDate() const
-{
- // Set to last day of year 9999 until confirm date formats & widets support > 9999
- // In Gregorian this is 9999-12-31, which is is jd 5373484
- // Can't call setDate( 9999, 12, 31 ) as it creates circular reference!
- return QDate::fromJulianDay(5373484);
-}
-
-int KCalendarSystemQDate::year(const QDate &date) const
-{
- return date.year();
-}
-
-int KCalendarSystemQDate::month(const QDate &date) const
-{
- return date.month();
-}
-
-int KCalendarSystemQDate::day(const QDate &date) const
-{
- return date.day();
-}
-
-int KCalendarSystemQDate::dayOfYear(const QDate &date) const
-{
- return date.dayOfYear();
-}
-
-bool KCalendarSystemQDate::isLunar() const
-{
- return false;
-}
-
-bool KCalendarSystemQDate::isLunisolar() const
-{
- return false;
-}
-
-bool KCalendarSystemQDate::isSolar() const
-{
- return true;
-}
-
-bool KCalendarSystemQDate::isProleptic() const
-{
- return false;
-}
-
-bool KCalendarSystemQDate::julianDayToDate(qint64 jd, int &year, int &month, int &day) const
-{
- QDate date = QDate::fromJulianDay(jd);
-
- date.getDate(&year, &month, &day);
-
- return date.isValid();
-}
-
-bool KCalendarSystemQDate::dateToJulianDay(int year, int month, int day, qint64 &jd) const
-{
- QDate date;
-
- date.setDate(year, month, day);
- jd = date.toJulianDay();
-
- return date.isValid();
-}
-
-QString KCalendarSystemQDate::monthName(int month, int year, MonthNameFormat format) const
-{
- Q_UNUSED(year);
-
- if (format == NarrowName) {
- switch (month) {
- case 1:
- return ki18nc("Julian month 1 - KLocale::NarrowName", "J").toString(locale());
- case 2:
- return ki18nc("Julian month 2 - KLocale::NarrowName", "F").toString(locale());
- case 3:
- return ki18nc("Julian month 3 - KLocale::NarrowName", "M").toString(locale());
- case 4:
- return ki18nc("Julian month 4 - KLocale::NarrowName", "A").toString(locale());
- case 5:
- return ki18nc("Julian month 5 - KLocale::NarrowName", "M").toString(locale());
- case 6:
- return ki18nc("Julian month 6 - KLocale::NarrowName", "J").toString(locale());
- case 7:
- return ki18nc("Julian month 7 - KLocale::NarrowName", "J").toString(locale());
- case 8:
- return ki18nc("Julian month 8 - KLocale::NarrowName", "A").toString(locale());
- case 9:
- return ki18nc("Julian month 9 - KLocale::NarrowName", "S").toString(locale());
- case 10:
- return ki18nc("Julian month 10 - KLocale::NarrowName", "O").toString(locale());
- case 11:
- return ki18nc("Julian month 11 - KLocale::NarrowName", "N").toString(locale());
- case 12:
- return ki18nc("Julian month 12 - KLocale::NarrowName", "D").toString(locale());
- default:
- return QString();
- }
- }
-
- if (format == ShortNamePossessive) {
- switch (month) {
- case 1:
- return ki18nc("Julian month 1 - KLocale::ShortName Possessive", "of Jan").toString(locale());
- case 2:
- return ki18nc("Julian month 2 - KLocale::ShortName Possessive", "of Feb").toString(locale());
- case 3:
- return ki18nc("Julian month 3 - KLocale::ShortName Possessive", "of Mar").toString(locale());
- case 4:
- return ki18nc("Julian month 4 - KLocale::ShortName Possessive", "of Apr").toString(locale());
- case 5:
- return ki18nc("Julian month 5 - KLocale::ShortName Possessive", "of May").toString(locale());
- case 6:
- return ki18nc("Julian month 6 - KLocale::ShortName Possessive", "of Jun").toString(locale());
- case 7:
- return ki18nc("Julian month 7 - KLocale::ShortName Possessive", "of Jul").toString(locale());
- case 8:
- return ki18nc("Julian month 8 - KLocale::ShortName Possessive", "of Aug").toString(locale());
- case 9:
- return ki18nc("Julian month 9 - KLocale::ShortName Possessive", "of Sep").toString(locale());
- case 10:
- return ki18nc("Julian month 10 - KLocale::ShortName Possessive", "of Oct").toString(locale());
- case 11:
- return ki18nc("Julian month 11 - KLocale::ShortName Possessive", "of Nov").toString(locale());
- case 12:
- return ki18nc("Julian month 12 - KLocale::ShortName Possessive", "of Dec").toString(locale());
- default:
- return QString();
- }
- }
-
- if (format == ShortName) {
- switch (month) {
- case 1:
- return ki18nc("Julian month 1 - KLocale::ShortName", "Jan").toString(locale());
- case 2:
- return ki18nc("Julian month 2 - KLocale::ShortName", "Feb").toString(locale());
- case 3:
- return ki18nc("Julian month 3 - KLocale::ShortName", "Mar").toString(locale());
- case 4:
- return ki18nc("Julian month 4 - KLocale::ShortName", "Apr").toString(locale());
- case 5:
- return ki18nc("Julian month 5 - KLocale::ShortName", "May").toString(locale());
- case 6:
- return ki18nc("Julian month 6 - KLocale::ShortName", "Jun").toString(locale());
- case 7:
- return ki18nc("Julian month 7 - KLocale::ShortName", "Jul").toString(locale());
- case 8:
- return ki18nc("Julian month 8 - KLocale::ShortName", "Aug").toString(locale());
- case 9:
- return ki18nc("Julian month 9 - KLocale::ShortName", "Sep").toString(locale());
- case 10:
- return ki18nc("Julian month 10 - KLocale::ShortName", "Oct").toString(locale());
- case 11:
- return ki18nc("Julian month 11 - KLocale::ShortName", "Nov").toString(locale());
- case 12:
- return ki18nc("Julian month 12 - KLocale::ShortName", "Dec").toString(locale());
- default:
- return QString();
- }
- }
-
- if (format == LongNamePossessive) {
- switch (month) {
- case 1:
- return ki18nc("Julian month 1 - KLocale::LongName Possessive", "of January").toString(locale());
- case 2:
- return ki18nc("Julian month 2 - KLocale::LongName Possessive", "of February").toString(locale());
- case 3:
- return ki18nc("Julian month 3 - KLocale::LongName Possessive", "of March").toString(locale());
- case 4:
- return ki18nc("Julian month 4 - KLocale::LongName Possessive", "of April").toString(locale());
- case 5:
- return ki18nc("Julian month 5 - KLocale::LongName Possessive", "of May").toString(locale());
- case 6:
- return ki18nc("Julian month 6 - KLocale::LongName Possessive", "of June").toString(locale());
- case 7:
- return ki18nc("Julian month 7 - KLocale::LongName Possessive", "of July").toString(locale());
- case 8:
- return ki18nc("Julian month 8 - KLocale::LongName Possessive", "of August").toString(locale());
- case 9:
- return ki18nc("Julian month 9 - KLocale::LongName Possessive", "of September").toString(locale());
- case 10:
- return ki18nc("Julian month 10 - KLocale::LongName Possessive", "of October").toString(locale());
- case 11:
- return ki18nc("Julian month 11 - KLocale::LongName Possessive", "of November").toString(locale());
- case 12:
- return ki18nc("Julian month 12 - KLocale::LongName Possessive", "of December").toString(locale());
- default:
- return QString();
- }
- }
-
- // Default to LongName
- switch (month) {
- case 1:
- return ki18nc("Julian month 1 - KLocale::LongName", "January").toString(locale());
- case 2:
- return ki18nc("Julian month 2 - KLocale::LongName", "February").toString(locale());
- case 3:
- return ki18nc("Julian month 3 - KLocale::LongName", "March").toString(locale());
- case 4:
- return ki18nc("Julian month 4 - KLocale::LongName", "April").toString(locale());
- case 5:
- return ki18nc("Julian month 5 - KLocale::LongName", "May").toString(locale());
- case 6:
- return ki18nc("Julian month 6 - KLocale::LongName", "June").toString(locale());
- case 7:
- return ki18nc("Julian month 7 - KLocale::LongName", "July").toString(locale());
- case 8:
- return ki18nc("Julian month 8 - KLocale::LongName", "August").toString(locale());
- case 9:
- return ki18nc("Julian month 9 - KLocale::LongName", "September").toString(locale());
- case 10:
- return ki18nc("Julian month 10 - KLocale::LongName", "October").toString(locale());
- case 11:
- return ki18nc("Julian month 11 - KLocale::LongName", "November").toString(locale());
- case 12:
- return ki18nc("Julian month 12 - KLocale::LongName", "December").toString(locale());
- default:
- return QString();
- }
-}
diff --git a/kdecore/date/kcalendarsystemqdate_p.h b/kdecore/date/kcalendarsystemqdate_p.h
deleted file mode 100644
index 2577f9b..0000000
--- a/kdecore/date/kcalendarsystemqdate_p.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- Copyright (c) 2002 Carlos Moro <cfmoro at correo.uniovi.es>
- Copyright (c) 2002 Hans Petter Bieker <bieker at kde.org>
- Copyright 2007, 2010 John Layt <john at layt.net>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef KCALENDARSYSTEMQDATE_H
-#define KCALENDARSYSTEMQDATE_H
-
-#include "kcalendarsystem.h"
-
-class KCalendarSystemQDatePrivate;
-
-/**
- * @internal
- * This is the QDate calendar implementation which combines the Julian and Gregorian
- * calculations into a single calendar. It should always be used by default in Qt
- * applications for consistency.
- *
- * @b license GNU-LGPL v.2+
- *
- * @see KLocale,KCalendarSystem
- *
- * @author John Layt <john at layt.net>
- */
-class KCalendarSystemQDate: public KCalendarSystem
-{
-public:
- explicit KCalendarSystemQDate(const KSharedConfig::Ptr config, const KLocale *locale);
- virtual ~KCalendarSystemQDate();
-
- virtual QString calendarType() const;
- virtual KLocale::CalendarSystem calendarSystem() const;
-
- virtual QDate epoch() const;
- virtual QDate earliestValidDate() const;
- virtual QDate latestValidDate() const;
-
- virtual int year(const QDate &date) const;
- virtual int month(const QDate &date) const;
- virtual int day(const QDate &date) const;
- virtual int dayOfYear(const QDate &date) const;
-
- virtual QString monthName(int month, int year, MonthNameFormat format = LongName) const;
-
- virtual bool isLunar() const;
- virtual bool isLunisolar() const;
- virtual bool isSolar() const;
- virtual bool isProleptic() const;
-
-protected:
- virtual bool julianDayToDate(qint64 jd, int &year, int &month, int &day) const;
- virtual bool dateToJulianDay(int year, int month, int day, qint64 &jd) const;
- KCalendarSystemQDate(KCalendarSystemQDatePrivate &dd, const KSharedConfig::Ptr config, const KLocale *locale);
-
-private:
- Q_DECLARE_PRIVATE(KCalendarSystemQDate)
-};
-
-#endif
diff --git a/kdecore/date/kcalendarsystemthai.cpp b/kdecore/date/kcalendarsystemthai.cpp
index 61de6e3..64659bb 100644
--- a/kdecore/date/kcalendarsystemthai.cpp
+++ b/kdecore/date/kcalendarsystemthai.cpp
@@ -33,6 +33,8 @@ public:
virtual ~KCalendarSystemThaiPrivate();
virtual void loadDefaultEraList();
+ virtual int daysInMonth(int year, int month) const;
+ virtual int daysInYear(int year) const;
virtual bool isLeapYear(int year) const;
virtual bool hasYearZero() const;
virtual int earliestValidYear() const;
@@ -59,6 +61,16 @@ void KCalendarSystemThaiPrivate::loadDefaultEraList()
addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
}
+int KCalendarSystemThaiPrivate::daysInMonth(int year, int month) const
+{
+ return KCalendarSystemGregorianPrivate::daysInMonth(year - 543, month);
+}
+
+int KCalendarSystemThaiPrivate::daysInYear(int year) const
+{
+ return KCalendarSystemGregorianPrivate::daysInYear(year - 543);
+}
+
bool KCalendarSystemThaiPrivate::isLeapYear(int year) const
{
return KCalendarSystemGregorianPrivate::isLeapYear(year - 543);
diff --git a/kdecore/date/kdatetime.cpp b/kdecore/date/kdatetime.cpp
index f36a8b9..0759c84 100644
--- a/kdecore/date/kdatetime.cpp
+++ b/kdecore/date/kdatetime.cpp
@@ -1421,7 +1421,7 @@ QString KDateTime::toString(const QString &format) const
return QString();
enum { TZNone, UTCOffsetShort, UTCOffset, UTCOffsetColon, TZAbbrev, TZName };
KLocale *locale = KLocale::global();
- QSharedPointer<const KCalendarSystem> calendar(KCalendarSystem::create(KLocale::QDateCalendar, locale));
+ QSharedPointer<const KCalendarSystem> calendar(KCalendarSystem::create(KLocale::GregorianCalendar, locale));
QString result;
QString s;
int num, numLength, zone;
@@ -2435,7 +2435,7 @@ QDateTime fromStr(const QString& string, const QString& format, int& utcOffset,
enum { TZNone, UTCOffset, UTCOffsetColon, TZAbbrev, TZName };
KLocale *locale = KLocale::global();
- QSharedPointer<const KCalendarSystem> calendar(KCalendarSystem::create(KLocale::QDateCalendar, locale));
+ QSharedPointer<const KCalendarSystem> calendar(KCalendarSystem::create(KLocale::GregorianCalendar, locale));
int zone;
int s = 0;
int send = str.length();
diff --git a/kdecore/localization/klocale.h b/kdecore/localization/klocale.h
index 934e5bc..6f9f59d 100644
--- a/kdecore/localization/klocale.h
+++ b/kdecore/localization/klocale.h
@@ -778,14 +778,13 @@ public:
* @see calendarSystem()
*/
enum CalendarSystem {
- QDateCalendar = 1, /**< KDE Default, hybrid of Gregorian and Julian as used by QDate */
+ GregorianCalendar = 1, /**< KDE Default, proleptic Gregorian Calendar as used by QDate */
//BahaiCalendar = 2, /**< Baha'i Calendar */
//BuddhistLunarCalendar = 3, /**< Buddhist Lunar Calendar*/
//ChineseCalendar = 4, /**< Chinese Calendar */
CopticCalendar = 5, /**< Coptic Calendar as used Coptic Church and some parts of Egypt */
EthiopianCalendar = 6, /**< Ethiopian Calendar, aka Ethiopic Calendar */
//EthiopianAmeteAlemCalendar = 7, /**< Ethiopian Amete Alem version, aka Ethiopic Amete Alem */
- GregorianCalendar = 8, /**< Gregorian Calendar, pure proleptic implementation */
HebrewCalendar = 9, /**< Hebrew Calendar, aka Jewish Calendar */
//HinduCalendar = 10, /**< Hindu Lunar Calendar */
//IslamicLunarCalendar = 11, /**< Islamic Lunar Calendar */
@@ -800,7 +799,9 @@ public:
//JucheCalendar = 20, /**< Juche Calendar, used in North Korea */
JulianCalendar = 21, /**< Julian Calendar, as used in Orthodox Churches */
MinguoCalendar= 22, /**< Minguo Calendar, aka ROC, Republic of China or Taiwanese */
- ThaiCalendar = 23 /**< Thai Calendar, aka Buddhist or Thai Buddhist */
+ ThaiCalendar = 23, /**< Thai Calendar, aka Buddhist or Thai Buddhist */
+
+ QDateCalendar = GregorianCalendar /**< @deprecated Alias for GregorianCalendar */
};
//KDE5 move to KDateTime namespace
diff --git a/kdecore/localization/klocale_kde.cpp b/kdecore/localization/klocale_kde.cpp
index d6ff731..bf06997 100644
--- a/kdecore/localization/klocale_kde.cpp
+++ b/kdecore/localization/klocale_kde.cpp
@@ -2973,14 +2973,12 @@ KLocale::CalendarSystem KLocalePrivate::calendarTypeToCalendarSystem(const QStri
QString KLocalePrivate::calendarSystemToCalendarType(KLocale::CalendarSystem calendarSystem) const
{
switch (calendarSystem) {
- case KLocale::QDateCalendar:
+ case KLocale::GregorianCalendar:
return QLatin1String("gregorian");
case KLocale::CopticCalendar:
return QLatin1String("coptic");
case KLocale::EthiopianCalendar:
return QLatin1String("ethiopian");
- case KLocale::GregorianCalendar:
- return QLatin1String("gregorian-proleptic");
case KLocale::HebrewCalendar:
return QLatin1String("hebrew");
case KLocale::IslamicCivilCalendar:
diff --git a/kdecore/tests/kcalendartest.cpp b/kdecore/tests/kcalendartest.cpp
index 099e475..f890703 100644
--- a/kdecore/tests/kcalendartest.cpp
+++ b/kdecore/tests/kcalendartest.cpp
@@ -37,9 +37,9 @@ void KCalendarTest::testTypes()
{
const KCalendarSystem *calendar;
- calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QCOMPARE(calendar->calendarType(), QString("gregorian"));
- QCOMPARE(calendar->calendarSystem(), KLocale::QDateCalendar);
+ QCOMPARE(calendar->calendarSystem(), KLocale::GregorianCalendar);
delete calendar;
calendar = KCalendarSystem::create(KLocale::CopticCalendar);
QCOMPARE(calendar->calendarType(), QString("coptic"));
@@ -49,10 +49,6 @@ void KCalendarTest::testTypes()
QCOMPARE(calendar->calendarType(), QString("ethiopian"));
QCOMPARE(calendar->calendarSystem(), KLocale::EthiopianCalendar);
delete calendar;
- calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
- QCOMPARE(calendar->calendarType(), QString("gregorian-proleptic"));
- QCOMPARE(calendar->calendarSystem(), KLocale::GregorianCalendar);
- delete calendar;
calendar = KCalendarSystem::create(KLocale::HebrewCalendar);
QCOMPARE(calendar->calendarType(), QString("hebrew"));
QCOMPARE(calendar->calendarSystem(), KLocale::HebrewCalendar);
@@ -85,13 +81,15 @@ void KCalendarTest::testTypes()
QCOMPARE(calendar->calendarType(), QString("thai"));
QCOMPARE(calendar->calendarSystem(), KLocale::ThaiCalendar);
delete calendar;
+ calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ QCOMPARE(calendar->calendarType(), QString("gregorian"));
+ QCOMPARE(calendar->calendarSystem(), KLocale::GregorianCalendar);
QList<KLocale::CalendarSystem> list = KCalendarSystem::calendarSystemsList();
- QCOMPARE(list.count(), 12);
- QVERIFY(list.contains(KLocale::QDateCalendar));
+ QCOMPARE(list.count(), 11);
+ QVERIFY(list.contains(KLocale::GregorianCalendar));
QVERIFY(list.contains(KLocale::CopticCalendar));
QVERIFY(list.contains(KLocale::EthiopianCalendar));
- QVERIFY(list.contains(KLocale::GregorianCalendar));
QVERIFY(list.contains(KLocale::HebrewCalendar));
QVERIFY(list.contains(KLocale::IslamicCivilCalendar));
QVERIFY(list.contains(KLocale::IndianNationalCalendar));
@@ -100,11 +98,11 @@ void KCalendarTest::testTypes()
QVERIFY(list.contains(KLocale::JulianCalendar));
QVERIFY(list.contains(KLocale::MinguoCalendar));
QVERIFY(list.contains(KLocale::ThaiCalendar));
+ QVERIFY(list.contains(KLocale::QDateCalendar));
- QCOMPARE(KCalendarSystem::calendarLabel(KLocale::QDateCalendar), QString("Gregorian"));
+ QCOMPARE(KCalendarSystem::calendarLabel(KLocale::GregorianCalendar), QString("Gregorian"));
QCOMPARE(KCalendarSystem::calendarLabel(KLocale::CopticCalendar), QString("Coptic"));
QCOMPARE(KCalendarSystem::calendarLabel(KLocale::EthiopianCalendar), QString("Ethiopian"));
- QCOMPARE(KCalendarSystem::calendarLabel(KLocale::GregorianCalendar), QString("Gregorian (Proleptic)"));
QCOMPARE(KCalendarSystem::calendarLabel(KLocale::HebrewCalendar), QString("Hebrew"));
QCOMPARE(KCalendarSystem::calendarLabel(KLocale::IslamicCivilCalendar), QString("Islamic / Hijri (Civil)"));
QCOMPARE(KCalendarSystem::calendarLabel(KLocale::IndianNationalCalendar), QString("Indian National"));
@@ -113,6 +111,7 @@ void KCalendarTest::testTypes()
QCOMPARE(KCalendarSystem::calendarLabel(KLocale::JulianCalendar), QString("Julian"));
QCOMPARE(KCalendarSystem::calendarLabel(KLocale::MinguoCalendar), QString("Taiwanese"));
QCOMPARE(KCalendarSystem::calendarLabel(KLocale::ThaiCalendar), QString("Thai"));
+ QCOMPARE(KCalendarSystem::calendarLabel(KLocale::QDateCalendar), QString("Gregorian"));
}
@@ -124,7 +123,7 @@ void KCalendarTest::testFormatDate()
KLocale *locale = new KLocale(*KLocale::global());
locale->setDateFormatShort("%y-%m-%d");
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar, locale);
//Test default settings
QDate testDate(2005, 10, 20);
@@ -420,7 +419,7 @@ void KCalendarTest::testFormatUnicode()
{
KLocale *locale = new KLocale(*KLocale::global());
locale->setDateFormatShort("%y-%m-%d");
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar, locale);
QDate testDate(2005, 10, 20);
compareFormatUnicode(calendar, testDate, "yyyy");
@@ -458,7 +457,7 @@ void KCalendarTest::testReadDate()
{
KLocale *locale = new KLocale(*KLocale::global());
locale->setDateFormatShort("%y-%m-%d");
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar, locale);
int currentYear = QDate::currentDate().year();
//Test default settings
@@ -621,7 +620,7 @@ void KCalendarTest::testStrings(KLocale::DigitSet testDigitSet)
{
KLocale *locale = new KLocale(*KLocale::global());
locale->setDigitSet(testDigitSet);
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar, locale);
//Test default settings
QDate testDate(2005, 1, 3);
@@ -690,15 +689,14 @@ void KCalendarTest::testStrings(KLocale::DigitSet testDigitSet)
void KCalendarTest::testIsoWeekDate()
{
KLocale *locale = new KLocale(*KLocale::global());
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar, locale);
int earliestValidYear = calendar->year(calendar->earliestValidDate());
int latestValidYear = calendar->year(calendar->latestValidDate());
QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear - 1, 1, 1), false);
QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear, 1, 1), false); //In prev year
- QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear, 1, 2), false); //In prev year
- QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear, 1, 3), true);
+ QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear, 1, 2), true);
QCOMPARE(calendar->isValidIsoWeekDate(-1, 1, 1), true);
QCOMPARE(calendar->isValidIsoWeekDate(0, 1, 1), false);
QCOMPARE(calendar->isValidIsoWeekDate(1, 1, 1), true);
@@ -719,11 +717,10 @@ void KCalendarTest::testIsoWeekDate()
QCOMPARE(setIsoWeekDate(calendar, earliestValidYear - 1, 1, 1), QDate());
QCOMPARE(setIsoWeekDate(calendar, earliestValidYear, 1, 1), QDate()); //In prev year
- QCOMPARE(setIsoWeekDate(calendar, earliestValidYear, 1, 2), QDate()); //In prev year
- QCOMPARE(setIsoWeekDate(calendar, earliestValidYear, 1, 3), QDate(-4712, 1, 1));
- QCOMPARE(setIsoWeekDate(calendar, -1, 1, 1), QDate(-2, 12, 29));
+ QCOMPARE(setIsoWeekDate(calendar, earliestValidYear, 1, 2), QDate(-9999, 1, 1));
+ QCOMPARE(setIsoWeekDate(calendar, -1, 1, 1), QDate(-1, 1, 3));
QCOMPARE(setIsoWeekDate(calendar, 0, 1, 1), QDate());
- QCOMPARE(setIsoWeekDate(calendar, 1, 1, 1), QDate(1, 1, 3));
+ QCOMPARE(setIsoWeekDate(calendar, 1, 1, 1), QDate(1, 1, 1));
QCOMPARE(setIsoWeekDate(calendar, latestValidYear, 52, 5), QDate(9999, 12, 31));
QCOMPARE(setIsoWeekDate(calendar, latestValidYear, 52, 6), QDate()); //In next year
QCOMPARE(setIsoWeekDate(calendar, latestValidYear, 52, 7), QDate()); //In next year
@@ -828,7 +825,7 @@ QDate KCalendarTest::setIsoWeekDate(const KCalendarSystem * calendar, int year,
void KCalendarTest::testDayOfYearDate()
{
KLocale *locale = new KLocale(*KLocale::global());
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar, locale);
int earliestValidYear = calendar->year(calendar->earliestValidDate());
int latestValidYear = calendar->year(calendar->latestValidDate());
@@ -876,7 +873,7 @@ QDate KCalendarTest::setDayOfYearDate(const KCalendarSystem * calendar, int year
void KCalendarTest::testDateDifference()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate1, testDate2;
// Date Difference
@@ -1004,7 +1001,7 @@ void KCalendarTest::compareMonthDifference(const KCalendarSystem *calendar,
void KCalendarTest::testFirstLast()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate = QDate(2010, 6, 15);
QCOMPARE(calendar->firstDayOfYear(testDate), QDate(2010, 1, 1));
@@ -1023,7 +1020,7 @@ void KCalendarTest::testEra()
KConfigGroup cg = lcg.group(QString("KCalendarSystem %1").arg("gregorian"));
cg.deleteGroup();
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
int earliestValidYear = calendar->year(calendar->earliestValidDate());
int latestValidYear = calendar->year(calendar->latestValidDate());
@@ -1085,7 +1082,7 @@ void KCalendarTest::testEra()
delete calendar;
cg.writeEntry("Era1", "-:1:-0001-01-01::Test Era 1:TE1:05%Ey05%EC05");
cg.writeEntry("Era2", "+:1:0001-01-01::Test Era 2:TE2:^%Ey^%EC^");
- calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
testEraDate(calendar, QDate(2010, 1, 1), 2010, "2010", "2010", "TE2", "Test Era 2");
testEraDate(calendar, QDate(-5, 1, 1), 5, "5", "0005", "TE1", "Test Era 1");
QCOMPARE(calendar->formatDate(QDate(2010, 1, 1), "%EY"), QString("^2010^TE2^"));
@@ -1104,9 +1101,9 @@ QDate KCalendarTest::setEraDate(const KCalendarSystem * calendar, const QString
return resultDate;
}
-void KCalendarTest::testQDateCalendar()
+void KCalendarTest::testGregorianCalendar()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate(2005, 9, 10);
QCOMPARE(calendar->dayOfYear(testDate), 253);
@@ -1275,21 +1272,22 @@ void KCalendarTest::testIndianNational()
delete calendar;
}
-void KCalendarTest::testQDateCalendarBasic()
+void KCalendarTest::testGregorianCalendarBasic()
{
KConfigGroup lcg(KSharedConfig::openConfig(), QString("Locale"));
KConfigGroup cg = lcg.group(QString("KCalendarSystem %1").arg("gregorian"));
cg.deleteGroup();
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
- testCalendarSystemType(calendar, KLocale::QDateCalendar, "gregorian", "Gregorian");
+ testCalendarSystemType(calendar, KLocale::GregorianCalendar, "gregorian", "Gregorian");
+ QCOMPARE(calendar->epoch(), QDate::fromJulianDay(1721426));
QCOMPARE(calendar->epoch(), QDate(1, 1, 1));
- QCOMPARE(calendar->earliestValidDate(), QDate(-4712, 1, 1));
+ QCOMPARE(calendar->earliestValidDate(), QDate(-9999, 1, 1));
QCOMPARE(calendar->latestValidDate(), QDate(9999, 12, 31));
- testValid(calendar, 0, 10000, 13, 32, QDate(-5000, 1, 1));
+ testValid(calendar, 0, 10000, 13, 32, QDate(-10000, 1, 1));
QCOMPARE(calendar->isLeapYear(2007), false);
QCOMPARE(calendar->isLeapYear(2008), true);
@@ -1313,7 +1311,7 @@ void KCalendarTest::testQDateCalendarBasic()
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
- QCOMPARE(calendar->isProleptic(), false);
+ QCOMPARE(calendar->isProleptic(), true);
QCOMPARE(calendar->isLunar(), false);
QCOMPARE(calendar->isLunisolar(), false);
QCOMPARE(calendar->isSolar(), true);
@@ -1323,33 +1321,33 @@ void KCalendarTest::testQDateCalendarBasic()
delete calendar;
}
-void KCalendarTest::testQDateCalendarYmd()
+void KCalendarTest::testGregorianCalendarYmd()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
testYmd(calendar, 2007, 1, 1, QDate(2007, 1, 1).toJulianDay());
delete calendar;
}
-void KCalendarTest::testQDateCalendarSpecialCases()
+void KCalendarTest::testGregorianCalendarSpecialCases()
{
KConfigGroup lcg(KSharedConfig::openConfig(), QString("Locale"));
KConfigGroup cg = lcg.group(QString("KCalendarSystem %1").arg("gregorian"));
cg.deleteGroup();
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
testEraDate(calendar, QDate(2010, 1, 1), 2010, "2010", "2010", "AD", "Anno Domini");
testEraDate(calendar, QDate(-5, 1, 1), 5, "5", "0005", "BC", "Before Christ");
delete calendar;
cg.writeEntry("UseCommonEra", false, KConfigGroup::Global);
- calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
testEraDate(calendar, QDate(2010, 1, 1), 2010, "2010", "2010", "AD", "Anno Domini");
testEraDate(calendar, QDate(-5, 1, 1), 5, "5", "0005", "BC", "Before Christ");
delete calendar;
cg.writeEntry("UseCommonEra", true, KConfigGroup::Global);
- calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
testEraDate(calendar, QDate(2010, 1, 1), 2010, "2010", "2010", "CE", "Common Era");
testEraDate(calendar, QDate(-5, 1, 1), 5, "5", "0005", "BCE", "Before Common Era");
@@ -1358,54 +1356,6 @@ void KCalendarTest::testQDateCalendarSpecialCases()
delete calendar;
}
-
-void KCalendarTest::testGregorianBasic()
-{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
-
- testCalendarSystemType(calendar, KLocale::GregorianCalendar, "gregorian-proleptic", "Gregorian (Proleptic)");
-
- QCOMPARE(calendar->epoch(), QDate::fromJulianDay(1721426));
- QCOMPARE(calendar->earliestValidDate(), QDate::fromJulianDay(38));
- QCOMPARE(calendar->latestValidDate(), QDate(9999, 12, 31));
-
- testValid(calendar, 0, 10000, 13, 32, QDate());
-
- QCOMPARE(calendar->isLeapYear(2007), false);
- QCOMPARE(calendar->isLeapYear(2008), true);
- QCOMPARE(calendar->isLeapYear(1900), false);
- QCOMPARE(calendar->isLeapYear(2000), true);
- QCOMPARE(calendar->isLeapYear(QDate(2007, 1, 1)), false);
- QCOMPARE(calendar->isLeapYear(QDate(2008, 1, 1)), true);
-
- QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
-
- QCOMPARE(calendar->monthsInYear(2007), 12);
- QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
-
- testYear(calendar, QDate(2007, 7, 9), 2007, QString("07"), QString("2007"));
- testMonth(calendar, QDate(2007, 7, 9), 7, QString("7"), QString("07"));
- testDay(calendar, QDate(2007, 7, 9), 9, QString("9"), QString("09"));
-
- testEraDate(calendar, QDate(2005, 1, 1), 2005, "2005", "2005", "AD", "Anno Domini");
- testEraDate(calendar, QDate(-5, 1, 3), 5, "5", "0005", "BC", "Before Christ");
- testMonthName(calendar, 12, 2007, QDate(2007, 12, 20), "D", "Dec", "December", "of Dec", "of December");
-
- QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
-
- QCOMPARE(calendar->isProleptic(), true);
- QCOMPARE(calendar->isLunar(), false);
- QCOMPARE(calendar->isLunisolar(), false);
- QCOMPARE(calendar->isSolar(), true);
-
- testRoundTrip(calendar);
-
- delete calendar;
-}
-
-
-// Test Hebrew Calendar System
-
void KCalendarTest::testHebrewBasic()
{
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::HebrewCalendar);
@@ -2009,47 +1959,9 @@ void KCalendarTest::testRoundTrip(const KCalendarSystem *calendar, bool testFull
}
}
-
-// Tests to compare new base methods are equal to QDate for Gregorian case
-
-void KCalendarTest::testQDateYearMonthDay()
-{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
-
- testQDateYMD(calendar, 2000, 1, 1);
- testQDateYMD(calendar, 2000, 2, 28);
- testQDateYMD(calendar, 2000, 2, 29);
- testQDateYMD(calendar, 2000, 6, 15);
- testQDateYMD(calendar, 2000, 12, 31);
-
- testQDateYMD(calendar, 9999, 1, 1);
- testQDateYMD(calendar, 9999, 6, 15);
- testQDateYMD(calendar, 9999, 12, 31);
-
- testQDateYMD(calendar, 1, 1, 1);
- testQDateYMD(calendar, 1, 6, 15);
- testQDateYMD(calendar, 1, 12, 31);
-
- testQDateYMD(calendar, -4712, 1, 2);
- testQDateYMD(calendar, -4712, 6, 15);
- testQDateYMD(calendar, -4712, 12, 31);
-
- delete calendar;
-}
-
-void KCalendarTest::testQDateYMD(const KCalendarSystem *calendar, int y, int m, int d)
+void KCalendarTest::testGregorianAddYears()
{
- QDate testDate;
-
- calendar->setDate(testDate, y, m, d);
- QCOMPARE(calendar->year(testDate), testDate.year());
- QCOMPARE(calendar->month(testDate), testDate.month());
- QCOMPARE(calendar->day(testDate), testDate.day());
-}
-
-void KCalendarTest::testQDateAddYears()
-{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate;
@@ -2067,9 +1979,9 @@ void KCalendarTest::testQDateAddYears()
delete calendar;
}
-void KCalendarTest::testQDateAddMonths()
+void KCalendarTest::testGregorianAddMonths()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate;
@@ -2108,9 +2020,9 @@ void KCalendarTest::testQDateAddMonths()
delete calendar;
}
-void KCalendarTest::testQDateAddDays()
+void KCalendarTest::testGregorianAddDays()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate;
@@ -2125,9 +2037,9 @@ void KCalendarTest::testQDateAddDays()
delete calendar;
}
-void KCalendarTest::testQDateDaysInYear()
+void KCalendarTest::testGregorianDaysInYear()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate;
@@ -2171,9 +2083,9 @@ void KCalendarTest::testQDateDaysInYear()
}
-void KCalendarTest::testQDateDaysInMonth()
+void KCalendarTest::testGregorianDaysInMonth()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate;
@@ -2216,9 +2128,9 @@ void KCalendarTest::testQDateDaysInMonth()
delete calendar;
}
-void KCalendarTest::testQDateDayOfYear()
+void KCalendarTest::testGregorianDayOfYear()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate;
@@ -2271,9 +2183,9 @@ void KCalendarTest::testQDateDayOfYear()
}
// Don't really need this as Gregorian currently uses QDate directly
-void KCalendarTest::testQDateIsLeapYear()
+void KCalendarTest::testGregorianIsLeapYear()
{
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
QDate testDate;
@@ -2520,7 +2432,7 @@ void KCalendarTest::testKLocalizedDate()
void KCalendarTest::testWeekNumberSystem()
{
KLocale *locale = new KLocale(*KLocale::global());
- const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
+ const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar, locale);
int weekYear = 0;
// Test the 7 days the year can start on:
diff --git a/kdecore/tests/kcalendartest.h b/kdecore/tests/kcalendartest.h
index ecedf7a..b083254 100644
--- a/kdecore/tests/kcalendartest.h
+++ b/kdecore/tests/kcalendartest.h
@@ -87,14 +87,13 @@ private Q_SLOTS:
void testDateDifference();
void testFirstLast();
void testEra();
- void testQDateCalendar();
+ void testGregorianCalendar();
void testHebrew();
void testIndianNational();
void testIslamicCivil();
- void testQDateCalendarBasic();
- void testQDateCalendarYmd();
- void testQDateCalendarSpecialCases();
- void testGregorianBasic();
+ void testGregorianCalendarBasic();
+ void testGregorianCalendarYmd();
+ void testGregorianCalendarSpecialCases();
void testHebrewBasic();
void testHebrewYmd();
void testHebrewCompare();
@@ -108,14 +107,13 @@ private Q_SLOTS:
void testJapaneseSpecialCases();
void testMinguoBasic();
void testThaiBasic();
- void testQDateYearMonthDay();
- void testQDateAddYears();
- void testQDateAddMonths();
- void testQDateAddDays();
- void testQDateDaysInYear();
- void testQDateDaysInMonth();
- void testQDateDayOfYear();
- void testQDateIsLeapYear();
+ void testGregorianAddYears();
+ void testGregorianAddMonths();
+ void testGregorianAddDays();
+ void testGregorianDaysInYear();
+ void testGregorianDaysInMonth();
+ void testGregorianDayOfYear();
+ void testGregorianIsLeapYear();
void testKLocalizedDate();
void testWeekNumberSystem();
};
--
1.7.10.4
More information about the Kde-frameworks-devel
mailing list