~ubuntu-branches/ubuntu/oneiric/kde4libs/oneiric-proposed

« back to all changes in this revision

Viewing changes to kdecore/tests/kcalendartest.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 00:08:34 UTC
  • mto: This revision was merged to the branch mainline in revision 247.
  • Revision ID: package-import@ubuntu.com-20110708000834-dr9a8my4iml90qe5
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2005 Brad Hards <bradh@kde.org>
 
3
    Copyright 2007, 2009, 2010, 2011 John Layt <john@layt.net>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Library General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Library General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to
 
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
    Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
1
21
#include "kcalendartest.h"
2
22
 
3
23
#include <locale.h>
4
24
 
5
 
#include "config.h"
 
25
#include <config.h>
6
26
 
7
27
#include <QtCore/QString>
8
28
 
16
36
 
17
37
#include "kcalendartest.moc"
18
38
 
19
 
QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME( KCalendarTest, "kdecalendarsystems" /*so that the .po exists*/ )
 
39
QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME(KCalendarTest, "kdecalendarsystems" /*so that the .po exists*/)
20
40
 
21
41
void KCalendarTest::testTypes()
22
42
{
23
43
    const KCalendarSystem *calendar;
24
 
    calendar = KCalendarSystem::create( "coptic" );
25
 
    QCOMPARE( calendar->calendarType(), QString("coptic") );
26
 
    QCOMPARE( calendar->calendarSystem(), KLocale::CopticCalendar );
27
 
    delete calendar;
28
 
    calendar = KCalendarSystem::create( "ethiopian" );
29
 
    QCOMPARE( calendar->calendarType(), QString("ethiopian") );
30
 
    QCOMPARE( calendar->calendarSystem(), KLocale::EthiopianCalendar );
31
 
    delete calendar;
32
 
    calendar = KCalendarSystem::create( "gregorian" );
33
 
    QCOMPARE( calendar->calendarType(), QString("gregorian") );
34
 
    QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
35
 
    delete calendar;
36
 
    calendar = KCalendarSystem::create( "gregorian-proleptic" );
37
 
    QCOMPARE( calendar->calendarType(), QString("gregorian-proleptic") );
38
 
    QCOMPARE( calendar->calendarSystem(), KLocale::GregorianCalendar );
39
 
    delete calendar;
40
 
    calendar = KCalendarSystem::create( "hebrew" );
41
 
    QCOMPARE( calendar->calendarType(), QString("hebrew") );
42
 
    QCOMPARE( calendar->calendarSystem(), KLocale::HebrewCalendar );
43
 
    delete calendar;
44
 
    calendar = KCalendarSystem::create( "hijri" );
45
 
    QCOMPARE( calendar->calendarType(), QString("hijri") );
46
 
    QCOMPARE( calendar->calendarSystem(), KLocale::IslamicCivilCalendar );
47
 
    delete calendar;
48
 
    calendar = KCalendarSystem::create( "indian-national" );
49
 
    QCOMPARE( calendar->calendarType(), QString("indian-national") );
50
 
    QCOMPARE( calendar->calendarSystem(), KLocale::IndianNationalCalendar );
51
 
    delete calendar;
52
 
    calendar = KCalendarSystem::create( "jalali" );
53
 
    QCOMPARE( calendar->calendarType(), QString("jalali") );
54
 
    QCOMPARE( calendar->calendarSystem(), KLocale::JalaliCalendar );
55
 
    delete calendar;
56
 
    calendar = KCalendarSystem::create( "japanese" );
57
 
    QCOMPARE( calendar->calendarType(), QString("japanese") );
58
 
    QCOMPARE( calendar->calendarSystem(), KLocale::JapaneseCalendar );
59
 
    delete calendar;
60
 
    calendar = KCalendarSystem::create( "julian" );
61
 
    QCOMPARE( calendar->calendarType(), QString("julian") );
62
 
    QCOMPARE( calendar->calendarSystem(), KLocale::JulianCalendar );
63
 
    delete calendar;
64
 
    calendar = KCalendarSystem::create( "minguo" );
65
 
    QCOMPARE( calendar->calendarType(), QString("minguo") );
66
 
    QCOMPARE( calendar->calendarSystem(), KLocale::MinguoCalendar );
67
 
    delete calendar;
68
 
    calendar = KCalendarSystem::create( "thai" );
69
 
    QCOMPARE( calendar->calendarType(), QString("thai") );
70
 
    QCOMPARE( calendar->calendarSystem(), KLocale::ThaiCalendar );
71
 
    delete calendar;
72
 
    calendar = KCalendarSystem::create( "invalid" );
73
 
    QCOMPARE( calendar->calendarType(), QString("gregorian") );
74
 
    QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
75
 
    delete calendar;
76
 
    calendar = KCalendarSystem::create( QString() );
77
 
    QCOMPARE( calendar->calendarType(), QString("gregorian") );
78
 
    QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
 
44
    calendar = KCalendarSystem::create("coptic");
 
45
    QCOMPARE(calendar->calendarType(), QString("coptic"));
 
46
    QCOMPARE(calendar->calendarSystem(), KLocale::CopticCalendar);
 
47
    delete calendar;
 
48
    calendar = KCalendarSystem::create("ethiopian");
 
49
    QCOMPARE(calendar->calendarType(), QString("ethiopian"));
 
50
    QCOMPARE(calendar->calendarSystem(), KLocale::EthiopianCalendar);
 
51
    delete calendar;
 
52
    calendar = KCalendarSystem::create("gregorian");
 
53
    QCOMPARE(calendar->calendarType(), QString("gregorian"));
 
54
    QCOMPARE(calendar->calendarSystem(), KLocale::QDateCalendar);
 
55
    delete calendar;
 
56
    calendar = KCalendarSystem::create("gregorian-proleptic");
 
57
    QCOMPARE(calendar->calendarType(), QString("gregorian-proleptic"));
 
58
    QCOMPARE(calendar->calendarSystem(), KLocale::GregorianCalendar);
 
59
    delete calendar;
 
60
    calendar = KCalendarSystem::create("hebrew");
 
61
    QCOMPARE(calendar->calendarType(), QString("hebrew"));
 
62
    QCOMPARE(calendar->calendarSystem(), KLocale::HebrewCalendar);
 
63
    delete calendar;
 
64
    calendar = KCalendarSystem::create("hijri");
 
65
    QCOMPARE(calendar->calendarType(), QString("hijri"));
 
66
    QCOMPARE(calendar->calendarSystem(), KLocale::IslamicCivilCalendar);
 
67
    delete calendar;
 
68
    calendar = KCalendarSystem::create("indian-national");
 
69
    QCOMPARE(calendar->calendarType(), QString("indian-national"));
 
70
    QCOMPARE(calendar->calendarSystem(), KLocale::IndianNationalCalendar);
 
71
    delete calendar;
 
72
    calendar = KCalendarSystem::create("jalali");
 
73
    QCOMPARE(calendar->calendarType(), QString("jalali"));
 
74
    QCOMPARE(calendar->calendarSystem(), KLocale::JalaliCalendar);
 
75
    delete calendar;
 
76
    calendar = KCalendarSystem::create("japanese");
 
77
    QCOMPARE(calendar->calendarType(), QString("japanese"));
 
78
    QCOMPARE(calendar->calendarSystem(), KLocale::JapaneseCalendar);
 
79
    delete calendar;
 
80
    calendar = KCalendarSystem::create("julian");
 
81
    QCOMPARE(calendar->calendarType(), QString("julian"));
 
82
    QCOMPARE(calendar->calendarSystem(), KLocale::JulianCalendar);
 
83
    delete calendar;
 
84
    calendar = KCalendarSystem::create("minguo");
 
85
    QCOMPARE(calendar->calendarType(), QString("minguo"));
 
86
    QCOMPARE(calendar->calendarSystem(), KLocale::MinguoCalendar);
 
87
    delete calendar;
 
88
    calendar = KCalendarSystem::create("thai");
 
89
    QCOMPARE(calendar->calendarType(), QString("thai"));
 
90
    QCOMPARE(calendar->calendarSystem(), KLocale::ThaiCalendar);
 
91
    delete calendar;
 
92
    calendar = KCalendarSystem::create("invalid");
 
93
    QCOMPARE(calendar->calendarType(), QString("gregorian"));
 
94
    QCOMPARE(calendar->calendarSystem(), KLocale::QDateCalendar);
 
95
    delete calendar;
 
96
    calendar = KCalendarSystem::create(QString());
 
97
    QCOMPARE(calendar->calendarType(), QString("gregorian"));
 
98
    QCOMPARE(calendar->calendarSystem(), KLocale::QDateCalendar);
79
99
    delete calendar;
80
100
 
81
 
    calendar = KCalendarSystem::create( KLocale::QDateCalendar );
82
 
    QCOMPARE( calendar->calendarType(), QString("gregorian") );
83
 
    QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
84
 
    delete calendar;
85
 
    calendar = KCalendarSystem::create( KLocale::CopticCalendar );
86
 
    QCOMPARE( calendar->calendarType(), QString("coptic") );
87
 
    QCOMPARE( calendar->calendarSystem(), KLocale::CopticCalendar );
88
 
    delete calendar;
89
 
    calendar = KCalendarSystem::create( KLocale::EthiopianCalendar );
90
 
    QCOMPARE( calendar->calendarType(), QString("ethiopian") );
91
 
    QCOMPARE( calendar->calendarSystem(), KLocale::EthiopianCalendar );
92
 
    delete calendar;
93
 
    calendar = KCalendarSystem::create( KLocale::GregorianCalendar );
94
 
    QCOMPARE( calendar->calendarType(), QString("gregorian-proleptic") );
95
 
    QCOMPARE( calendar->calendarSystem(), KLocale::GregorianCalendar );
96
 
    delete calendar;
97
 
    calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
98
 
    QCOMPARE( calendar->calendarType(), QString("hebrew") );
99
 
    QCOMPARE( calendar->calendarSystem(), KLocale::HebrewCalendar );
100
 
    delete calendar;
101
 
    calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
102
 
    QCOMPARE( calendar->calendarType(), QString("hijri") );
103
 
    QCOMPARE( calendar->calendarSystem(), KLocale::IslamicCivilCalendar );
104
 
    delete calendar;
105
 
    calendar = KCalendarSystem::create( KLocale::IndianNationalCalendar );
106
 
    QCOMPARE( calendar->calendarType(), QString("indian-national") );
107
 
    QCOMPARE( calendar->calendarSystem(), KLocale::IndianNationalCalendar );
108
 
    delete calendar;
109
 
    calendar = KCalendarSystem::create( KLocale::JalaliCalendar );
110
 
    QCOMPARE( calendar->calendarType(), QString("jalali") );
111
 
    QCOMPARE( calendar->calendarSystem(), KLocale::JalaliCalendar );
112
 
    delete calendar;
113
 
    calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
114
 
    QCOMPARE( calendar->calendarType(), QString("japanese") );
115
 
    QCOMPARE( calendar->calendarSystem(), KLocale::JapaneseCalendar );
116
 
    delete calendar;
117
 
    calendar = KCalendarSystem::create( KLocale::JulianCalendar );
118
 
    QCOMPARE( calendar->calendarType(), QString("julian") );
119
 
    QCOMPARE( calendar->calendarSystem(), KLocale::JulianCalendar );
120
 
    delete calendar;
121
 
    calendar = KCalendarSystem::create( KLocale::MinguoCalendar );
122
 
    QCOMPARE( calendar->calendarType(), QString("minguo") );
123
 
    QCOMPARE( calendar->calendarSystem(), KLocale::MinguoCalendar );
124
 
    delete calendar;
125
 
    calendar = KCalendarSystem::create( KLocale::ThaiCalendar );
126
 
    QCOMPARE( calendar->calendarType(), QString("thai") );
127
 
    QCOMPARE( calendar->calendarSystem(), KLocale::ThaiCalendar );
 
101
    calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
102
    QCOMPARE(calendar->calendarType(), QString("gregorian"));
 
103
    QCOMPARE(calendar->calendarSystem(), KLocale::QDateCalendar);
 
104
    delete calendar;
 
105
    calendar = KCalendarSystem::create(KLocale::CopticCalendar);
 
106
    QCOMPARE(calendar->calendarType(), QString("coptic"));
 
107
    QCOMPARE(calendar->calendarSystem(), KLocale::CopticCalendar);
 
108
    delete calendar;
 
109
    calendar = KCalendarSystem::create(KLocale::EthiopianCalendar);
 
110
    QCOMPARE(calendar->calendarType(), QString("ethiopian"));
 
111
    QCOMPARE(calendar->calendarSystem(), KLocale::EthiopianCalendar);
 
112
    delete calendar;
 
113
    calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
 
114
    QCOMPARE(calendar->calendarType(), QString("gregorian-proleptic"));
 
115
    QCOMPARE(calendar->calendarSystem(), KLocale::GregorianCalendar);
 
116
    delete calendar;
 
117
    calendar = KCalendarSystem::create(KLocale::HebrewCalendar);
 
118
    QCOMPARE(calendar->calendarType(), QString("hebrew"));
 
119
    QCOMPARE(calendar->calendarSystem(), KLocale::HebrewCalendar);
 
120
    delete calendar;
 
121
    calendar = KCalendarSystem::create(KLocale::IslamicCivilCalendar);
 
122
    QCOMPARE(calendar->calendarType(), QString("hijri"));
 
123
    QCOMPARE(calendar->calendarSystem(), KLocale::IslamicCivilCalendar);
 
124
    delete calendar;
 
125
    calendar = KCalendarSystem::create(KLocale::IndianNationalCalendar);
 
126
    QCOMPARE(calendar->calendarType(), QString("indian-national"));
 
127
    QCOMPARE(calendar->calendarSystem(), KLocale::IndianNationalCalendar);
 
128
    delete calendar;
 
129
    calendar = KCalendarSystem::create(KLocale::JalaliCalendar);
 
130
    QCOMPARE(calendar->calendarType(), QString("jalali"));
 
131
    QCOMPARE(calendar->calendarSystem(), KLocale::JalaliCalendar);
 
132
    delete calendar;
 
133
    calendar = KCalendarSystem::create(KLocale::JapaneseCalendar);
 
134
    QCOMPARE(calendar->calendarType(), QString("japanese"));
 
135
    QCOMPARE(calendar->calendarSystem(), KLocale::JapaneseCalendar);
 
136
    delete calendar;
 
137
    calendar = KCalendarSystem::create(KLocale::JulianCalendar);
 
138
    QCOMPARE(calendar->calendarType(), QString("julian"));
 
139
    QCOMPARE(calendar->calendarSystem(), KLocale::JulianCalendar);
 
140
    delete calendar;
 
141
    calendar = KCalendarSystem::create(KLocale::MinguoCalendar);
 
142
    QCOMPARE(calendar->calendarType(), QString("minguo"));
 
143
    QCOMPARE(calendar->calendarSystem(), KLocale::MinguoCalendar);
 
144
    delete calendar;
 
145
    calendar = KCalendarSystem::create(KLocale::ThaiCalendar);
 
146
    QCOMPARE(calendar->calendarType(), QString("thai"));
 
147
    QCOMPARE(calendar->calendarSystem(), KLocale::ThaiCalendar);
128
148
    delete calendar;
129
149
 
130
150
    QStringList lst = KCalendarSystem::calendarSystems();
131
 
    QCOMPARE( lst.count(), 12 );
132
 
    QVERIFY( lst.contains( "coptic" ) );
133
 
    QVERIFY( lst.contains( "ethiopian" ) );
134
 
    QVERIFY( lst.contains( "gregorian" ) );
135
 
    QVERIFY( lst.contains( "gregorian-proleptic" ) );
136
 
    QVERIFY( lst.contains( "hebrew" ) );
137
 
    QVERIFY( lst.contains( "hijri" ) );
138
 
    QVERIFY( lst.contains( "indian-national" ) );
139
 
    QVERIFY( lst.contains( "jalali" ) );
140
 
    QVERIFY( lst.contains( "japanese" ) );
141
 
    QVERIFY( lst.contains( "julian" ) );
142
 
    QVERIFY( lst.contains( "minguo" ) );
143
 
    QVERIFY( lst.contains( "thai" ) );
 
151
    QCOMPARE(lst.count(), 12);
 
152
    QVERIFY(lst.contains("coptic"));
 
153
    QVERIFY(lst.contains("ethiopian"));
 
154
    QVERIFY(lst.contains("gregorian"));
 
155
    QVERIFY(lst.contains("gregorian-proleptic"));
 
156
    QVERIFY(lst.contains("hebrew"));
 
157
    QVERIFY(lst.contains("hijri"));
 
158
    QVERIFY(lst.contains("indian-national"));
 
159
    QVERIFY(lst.contains("jalali"));
 
160
    QVERIFY(lst.contains("japanese"));
 
161
    QVERIFY(lst.contains("julian"));
 
162
    QVERIFY(lst.contains("minguo"));
 
163
    QVERIFY(lst.contains("thai"));
144
164
 
145
165
    QList<KLocale::CalendarSystem> list = KCalendarSystem::calendarSystemsList();
146
 
    QCOMPARE( list.count(), 12 );
147
 
    QVERIFY( list.contains( KLocale::QDateCalendar ) );
148
 
    QVERIFY( list.contains( KLocale::CopticCalendar ) );
149
 
    QVERIFY( list.contains( KLocale::EthiopianCalendar ) );
150
 
    QVERIFY( list.contains( KLocale::GregorianCalendar ) );
151
 
    QVERIFY( list.contains( KLocale::HebrewCalendar ) );
152
 
    QVERIFY( list.contains( KLocale::IslamicCivilCalendar ) );
153
 
    QVERIFY( list.contains( KLocale::IndianNationalCalendar ) );
154
 
    QVERIFY( list.contains( KLocale::JalaliCalendar ) );
155
 
    QVERIFY( list.contains( KLocale::JapaneseCalendar ) );
156
 
    QVERIFY( list.contains( KLocale::JulianCalendar ) );
157
 
    QVERIFY( list.contains( KLocale::MinguoCalendar ) );
158
 
    QVERIFY( list.contains( KLocale::ThaiCalendar ) );
159
 
 
160
 
    QCOMPARE( KCalendarSystem::calendarLabel( "coptic" ),              QString( "Coptic" ) );
161
 
    QCOMPARE( KCalendarSystem::calendarLabel( "ethiopian" ),           QString( "Ethiopian" ) );
162
 
    QCOMPARE( KCalendarSystem::calendarLabel( "gregorian" ),           QString( "Gregorian" ) );
163
 
    QCOMPARE( KCalendarSystem::calendarLabel( "gregorian-proleptic" ), QString( "Gregorian (Proleptic)" ) );
164
 
    QCOMPARE( KCalendarSystem::calendarLabel( "hebrew" ),              QString( "Hebrew" ) );
165
 
    QCOMPARE( KCalendarSystem::calendarLabel( "hijri" ),               QString( "Islamic / Hijri (Civil)" ) );
166
 
    QCOMPARE( KCalendarSystem::calendarLabel( "indian-national" ),     QString( "Indian National" ) );
167
 
    QCOMPARE( KCalendarSystem::calendarLabel( "jalali" ),              QString( "Jalali" ) );
168
 
    QCOMPARE( KCalendarSystem::calendarLabel( "japanese" ),            QString( "Japanese" ) );
169
 
    QCOMPARE( KCalendarSystem::calendarLabel( "julian" ),              QString( "Julian" ) );
170
 
    QCOMPARE( KCalendarSystem::calendarLabel( "minguo" ),              QString( "Taiwanese" ) );
171
 
    QCOMPARE( KCalendarSystem::calendarLabel( "thai" ),                QString( "Thai" ) );
172
 
 
173
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::QDateCalendar ),          QString( "Gregorian" ) );
174
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::CopticCalendar ),         QString( "Coptic" ) );
175
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::EthiopianCalendar ),      QString( "Ethiopian" ) );
176
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::GregorianCalendar ),      QString( "Gregorian (Proleptic)" ) );
177
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::HebrewCalendar ),         QString( "Hebrew" ) );
178
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::IslamicCivilCalendar ),   QString( "Islamic / Hijri (Civil)" ) );
179
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::IndianNationalCalendar ), QString( "Indian National" ) );
180
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::JalaliCalendar ),         QString( "Jalali" ) );
181
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::JapaneseCalendar ),       QString( "Japanese" ) );
182
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::JulianCalendar ),         QString( "Julian" ) );
183
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::MinguoCalendar ),         QString( "Taiwanese" ) );
184
 
    QCOMPARE( KCalendarSystem::calendarLabel( KLocale::ThaiCalendar ),           QString( "Thai" ) );
 
166
    QCOMPARE(list.count(), 12);
 
167
    QVERIFY(list.contains(KLocale::QDateCalendar));
 
168
    QVERIFY(list.contains(KLocale::CopticCalendar));
 
169
    QVERIFY(list.contains(KLocale::EthiopianCalendar));
 
170
    QVERIFY(list.contains(KLocale::GregorianCalendar));
 
171
    QVERIFY(list.contains(KLocale::HebrewCalendar));
 
172
    QVERIFY(list.contains(KLocale::IslamicCivilCalendar));
 
173
    QVERIFY(list.contains(KLocale::IndianNationalCalendar));
 
174
    QVERIFY(list.contains(KLocale::JalaliCalendar));
 
175
    QVERIFY(list.contains(KLocale::JapaneseCalendar));
 
176
    QVERIFY(list.contains(KLocale::JulianCalendar));
 
177
    QVERIFY(list.contains(KLocale::MinguoCalendar));
 
178
    QVERIFY(list.contains(KLocale::ThaiCalendar));
 
179
 
 
180
    QCOMPARE(KCalendarSystem::calendarLabel("coptic"),              QString("Coptic"));
 
181
    QCOMPARE(KCalendarSystem::calendarLabel("ethiopian"),           QString("Ethiopian"));
 
182
    QCOMPARE(KCalendarSystem::calendarLabel("gregorian"),           QString("Gregorian"));
 
183
    QCOMPARE(KCalendarSystem::calendarLabel("gregorian-proleptic"), QString("Gregorian (Proleptic)"));
 
184
    QCOMPARE(KCalendarSystem::calendarLabel("hebrew"),              QString("Hebrew"));
 
185
    QCOMPARE(KCalendarSystem::calendarLabel("hijri"),               QString("Islamic / Hijri (Civil)"));
 
186
    QCOMPARE(KCalendarSystem::calendarLabel("indian-national"),     QString("Indian National"));
 
187
    QCOMPARE(KCalendarSystem::calendarLabel("jalali"),              QString("Jalali"));
 
188
    QCOMPARE(KCalendarSystem::calendarLabel("japanese"),            QString("Japanese"));
 
189
    QCOMPARE(KCalendarSystem::calendarLabel("julian"),              QString("Julian"));
 
190
    QCOMPARE(KCalendarSystem::calendarLabel("minguo"),              QString("Taiwanese"));
 
191
    QCOMPARE(KCalendarSystem::calendarLabel("thai"),                QString("Thai"));
 
192
 
 
193
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::QDateCalendar),          QString("Gregorian"));
 
194
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::CopticCalendar),         QString("Coptic"));
 
195
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::EthiopianCalendar),      QString("Ethiopian"));
 
196
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::GregorianCalendar),      QString("Gregorian (Proleptic)"));
 
197
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::HebrewCalendar),         QString("Hebrew"));
 
198
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::IslamicCivilCalendar),   QString("Islamic / Hijri (Civil)"));
 
199
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::IndianNationalCalendar), QString("Indian National"));
 
200
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::JalaliCalendar),         QString("Jalali"));
 
201
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::JapaneseCalendar),       QString("Japanese"));
 
202
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::JulianCalendar),         QString("Julian"));
 
203
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::MinguoCalendar),         QString("Taiwanese"));
 
204
    QCOMPARE(KCalendarSystem::calendarLabel(KLocale::ThaiCalendar),           QString("Thai"));
185
205
 
186
206
}
187
207
 
188
208
void KCalendarTest::testFormatDate()
189
209
{
190
 
    KLocale *locale = new KLocale( *KGlobal::locale() );
191
 
    locale->setDateFormatShort( "%y-%m-%d" );
192
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
 
210
    KLocale *locale = new KLocale(*KGlobal::locale());
 
211
    locale->setDateFormatShort("%y-%m-%d");
 
212
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
193
213
 
194
214
    //Test default settings
195
 
    QDate testDate( 2005, 10, 20 );
196
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ), QString( "2005" ) );
197
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ), QString( "20" ) );
198
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ), QString( "05" ) );
199
 
    QCOMPARE( calendar->formatDate( testDate, "%m" ), QString( "10" ) );
200
 
    QCOMPARE( calendar->formatDate( testDate, "%n" ), QString( "10" ) );
201
 
    QCOMPARE( calendar->formatDate( testDate, "%d" ), QString( "20" ) );
202
 
    QCOMPARE( calendar->formatDate( testDate, "%e" ), QString( "20" ) );
203
 
    QCOMPARE( calendar->formatDate( testDate, "%B" ), QString( "October" ) );
204
 
    QCOMPARE( calendar->formatDate( testDate, "%b" ), QString( "Oct" ) );
205
 
    QCOMPARE( calendar->formatDate( testDate, "%h" ), QString( "Oct" ) );
206
 
    QCOMPARE( calendar->formatDate( testDate, "%A" ), QString( "Thursday" ) );
207
 
    QCOMPARE( calendar->formatDate( testDate, "%a" ), QString( "Thu" ) );
208
 
    QCOMPARE( calendar->formatDate( testDate, "%j" ), QString( "293" ) );
209
 
    QCOMPARE( calendar->formatDate( testDate, "%V" ), QString( "42" ) );
210
 
    QCOMPARE( calendar->formatDate( testDate, "%G" ), QString( "2005" ) );
211
 
    QCOMPARE( calendar->formatDate( testDate, "%g" ), QString( "05" ) );
212
 
    QCOMPARE( calendar->formatDate( testDate, "%u" ), QString( "4" ) );
213
 
    QCOMPARE( calendar->formatDate( testDate, "%D" ), QString( "10/20/05" ) );
214
 
    QCOMPARE( calendar->formatDate( testDate, "%F" ), QString( "2005-10-20" ) );
215
 
    QCOMPARE( calendar->formatDate( testDate, "%x" ), QString( "05-10-20" ) );
216
 
    QCOMPARE( calendar->formatDate( testDate, "%%" ), QString( "%" ) );
217
 
    QCOMPARE( calendar->formatDate( testDate, "%t" ), QString( "\t" ) );
 
215
    QDate testDate(2005, 10, 20);
 
216
    QCOMPARE(calendar->formatDate(testDate, "%Y"), QString("2005"));
 
217
    QCOMPARE(calendar->formatDate(testDate, "%C"), QString("20"));
 
218
    QCOMPARE(calendar->formatDate(testDate, "%y"), QString("05"));
 
219
    QCOMPARE(calendar->formatDate(testDate, "%m"), QString("10"));
 
220
    QCOMPARE(calendar->formatDate(testDate, "%n"), QString("10"));
 
221
    QCOMPARE(calendar->formatDate(testDate, "%d"), QString("20"));
 
222
    QCOMPARE(calendar->formatDate(testDate, "%e"), QString("20"));
 
223
    QCOMPARE(calendar->formatDate(testDate, "%B"), QString("October"));
 
224
    QCOMPARE(calendar->formatDate(testDate, "%b"), QString("Oct"));
 
225
    QCOMPARE(calendar->formatDate(testDate, "%h"), QString("Oct"));
 
226
    QCOMPARE(calendar->formatDate(testDate, "%A"), QString("Thursday"));
 
227
    QCOMPARE(calendar->formatDate(testDate, "%a"), QString("Thu"));
 
228
    QCOMPARE(calendar->formatDate(testDate, "%j"), QString("293"));
 
229
    QCOMPARE(calendar->formatDate(testDate, "%V"), QString("42"));
 
230
    QCOMPARE(calendar->formatDate(testDate, "%G"), QString("2005"));
 
231
    QCOMPARE(calendar->formatDate(testDate, "%g"), QString("05"));
 
232
    QCOMPARE(calendar->formatDate(testDate, "%u"), QString("4"));
 
233
    QCOMPARE(calendar->formatDate(testDate, "%D"), QString("10/20/05"));
 
234
    QCOMPARE(calendar->formatDate(testDate, "%F"), QString("2005-10-20"));
 
235
    QCOMPARE(calendar->formatDate(testDate, "%x"), QString("05-10-20"));
 
236
    QCOMPARE(calendar->formatDate(testDate, "%%"), QString("%"));
 
237
    QCOMPARE(calendar->formatDate(testDate, "%t"), QString("\t"));
218
238
 
219
 
    QCOMPARE( calendar->formatDate( testDate, "-%Y-%C-%y-%m-%n-%d-%e-%B-%b-%h-%A-%a-%j-%V-%G-%g-%u:%D:%F:%x:%%-%t-" ),
220
 
              QString( "-2005-20-05-10-10-20-20-October-Oct-Oct-Thursday-Thu-293-42-2005-05-4:10/20/05:2005-10-20:05-10-20:%-\t-" ) );
 
239
    QCOMPARE(calendar->formatDate(testDate, "-%Y-%C-%y-%m-%n-%d-%e-%B-%b-%h-%A-%a-%j-%V-%G-%g-%u:%D:%F:%x:%%-%t-"),
 
240
             QString("-2005-20-05-10-10-20-20-October-Oct-Oct-Thursday-Thu-293-42-2005-05-4:10/20/05:2005-10-20:05-10-20:%-\t-"));
221
241
 
222
242
    //Test the minimum widths are respected
223
 
    QCOMPARE( calendar->formatDate( testDate, "%1Y" ),  QString( "2005" ) );
224
 
    QCOMPARE( calendar->formatDate( testDate, "%1C" ),  QString( "20" ) );
225
 
    QCOMPARE( calendar->formatDate( testDate, "%1y" ),  QString( "05" ) );
226
 
    QCOMPARE( calendar->formatDate( testDate, "%1m" ),  QString( "10" ) );
227
 
    QCOMPARE( calendar->formatDate( testDate, "%1n" ),  QString( "10" ) );
228
 
    QCOMPARE( calendar->formatDate( testDate, "%1d" ),  QString( "20" ) );
229
 
    QCOMPARE( calendar->formatDate( testDate, "%1e" ),  QString( "20" ) );
230
 
    QCOMPARE( calendar->formatDate( testDate, "%01B" ), QString( "October" ) );
231
 
    QCOMPARE( calendar->formatDate( testDate, "%01b" ), QString( "Oct" ) );
232
 
    QCOMPARE( calendar->formatDate( testDate, "%01h" ), QString( "Oct" ) );
233
 
    QCOMPARE( calendar->formatDate( testDate, "%01A" ), QString( "Thursday" ) );
234
 
    QCOMPARE( calendar->formatDate( testDate, "%01a" ), QString( "Thu" ) );
235
 
    QCOMPARE( calendar->formatDate( testDate, "%1j" ),  QString( "293" ) );
236
 
    QCOMPARE( calendar->formatDate( testDate, "%1V" ),  QString( "42" ) );
237
 
    QCOMPARE( calendar->formatDate( testDate, "%1G" ),  QString( "2005" ) );
238
 
    QCOMPARE( calendar->formatDate( testDate, "%1g" ),  QString( "05" ) );
239
 
    QCOMPARE( calendar->formatDate( testDate, "%1u" ),  QString( "4" ) );
240
 
    QCOMPARE( calendar->formatDate( testDate, "%1D" ),  QString( "10/20/05" ) );
241
 
    QCOMPARE( calendar->formatDate( testDate, "%1F" ),  QString( "2005-10-20" ) );
242
 
    QCOMPARE( calendar->formatDate( testDate, "%1x" ),  QString( "05-10-20" ) );
243
 
    QCOMPARE( calendar->formatDate( testDate, "%1%" ),  QString( "%" ) );
244
 
    QCOMPARE( calendar->formatDate( testDate, "%1t" ),  QString( "\t" ) );
 
243
    QCOMPARE(calendar->formatDate(testDate, "%1Y"),  QString("2005"));
 
244
    QCOMPARE(calendar->formatDate(testDate, "%1C"),  QString("20"));
 
245
    QCOMPARE(calendar->formatDate(testDate, "%1y"),  QString("05"));
 
246
    QCOMPARE(calendar->formatDate(testDate, "%1m"),  QString("10"));
 
247
    QCOMPARE(calendar->formatDate(testDate, "%1n"),  QString("10"));
 
248
    QCOMPARE(calendar->formatDate(testDate, "%1d"),  QString("20"));
 
249
    QCOMPARE(calendar->formatDate(testDate, "%1e"),  QString("20"));
 
250
    QCOMPARE(calendar->formatDate(testDate, "%01B"), QString("October"));
 
251
    QCOMPARE(calendar->formatDate(testDate, "%01b"), QString("Oct"));
 
252
    QCOMPARE(calendar->formatDate(testDate, "%01h"), QString("Oct"));
 
253
    QCOMPARE(calendar->formatDate(testDate, "%01A"), QString("Thursday"));
 
254
    QCOMPARE(calendar->formatDate(testDate, "%01a"), QString("Thu"));
 
255
    QCOMPARE(calendar->formatDate(testDate, "%1j"),  QString("293"));
 
256
    QCOMPARE(calendar->formatDate(testDate, "%1V"),  QString("42"));
 
257
    QCOMPARE(calendar->formatDate(testDate, "%1G"),  QString("2005"));
 
258
    QCOMPARE(calendar->formatDate(testDate, "%1g"),  QString("05"));
 
259
    QCOMPARE(calendar->formatDate(testDate, "%1u"),  QString("4"));
 
260
    QCOMPARE(calendar->formatDate(testDate, "%1D"),  QString("10/20/05"));
 
261
    QCOMPARE(calendar->formatDate(testDate, "%1F"),  QString("2005-10-20"));
 
262
    QCOMPARE(calendar->formatDate(testDate, "%1x"),  QString("05-10-20"));
 
263
    QCOMPARE(calendar->formatDate(testDate, "%1%"),  QString("%"));
 
264
    QCOMPARE(calendar->formatDate(testDate, "%1t"),  QString("\t"));
245
265
 
246
 
    testDate.setDate( 2005, 1, 2 );
 
266
    testDate.setDate(2005, 1, 2);
247
267
 
248
268
    //Test various padding options with minimum width
249
 
    QCOMPARE( calendar->formatDate( testDate, "%" ),     QString( "" ) );
250
 
    QCOMPARE( calendar->formatDate( testDate, "%m" ),    QString( "01" ) );
251
 
    QCOMPARE( calendar->formatDate( testDate, "%n" ),    QString( "1" ) );
252
 
    QCOMPARE( calendar->formatDate( testDate, "%d" ),    QString( "02" ) );
253
 
    QCOMPARE( calendar->formatDate( testDate, "%e" ),    QString( "2" ) );
254
 
    QCOMPARE( calendar->formatDate( testDate, "%j" ),    QString( "002" ) );
255
 
    QCOMPARE( calendar->formatDate( testDate, "%_m" ),   QString( " 1" ) );
256
 
    QCOMPARE( calendar->formatDate( testDate, "%_n" ),   QString( "1" ) );
257
 
    QCOMPARE( calendar->formatDate( testDate, "%_d" ),   QString( " 2" ) );
258
 
    QCOMPARE( calendar->formatDate( testDate, "%_e" ),   QString( "2" ) );
259
 
    QCOMPARE( calendar->formatDate( testDate, "%_j" ),   QString( "  2" ) );
260
 
    QCOMPARE( calendar->formatDate( testDate, "%-m" ),   QString( "1" ) );
261
 
    QCOMPARE( calendar->formatDate( testDate, "%-n" ),   QString( "1" ) );
262
 
    QCOMPARE( calendar->formatDate( testDate, "%-d" ),   QString( "2" ) );
263
 
    QCOMPARE( calendar->formatDate( testDate, "%-e" ),   QString( "2" ) );
264
 
    QCOMPARE( calendar->formatDate( testDate, "%-j" ),   QString( "2" ) );
265
 
    QCOMPARE( calendar->formatDate( testDate, "%0m" ),   QString( "01" ) );
266
 
    QCOMPARE( calendar->formatDate( testDate, "%0n" ),   QString( "1" ) );
267
 
    QCOMPARE( calendar->formatDate( testDate, "%0d" ),   QString( "02" ) );
268
 
    QCOMPARE( calendar->formatDate( testDate, "%0e" ),   QString( "2" ) );
269
 
    QCOMPARE( calendar->formatDate( testDate, "%0j" ),   QString( "002" ) );
270
 
    QCOMPARE( calendar->formatDate( testDate, "%-_j" ),  QString( "  2" ) );
271
 
    QCOMPARE( calendar->formatDate( testDate, "%_-j" ),  QString( "2" ) );
272
 
    QCOMPARE( calendar->formatDate( testDate, "%-_0j" ), QString( "002" ) );
 
269
    QCOMPARE(calendar->formatDate(testDate, "%"),     QString(""));
 
270
    QCOMPARE(calendar->formatDate(testDate, "%m"),    QString("01"));
 
271
    QCOMPARE(calendar->formatDate(testDate, "%n"),    QString("1"));
 
272
    QCOMPARE(calendar->formatDate(testDate, "%d"),    QString("02"));
 
273
    QCOMPARE(calendar->formatDate(testDate, "%e"),    QString("2"));
 
274
    QCOMPARE(calendar->formatDate(testDate, "%j"),    QString("002"));
 
275
    QCOMPARE(calendar->formatDate(testDate, "%_m"),   QString(" 1"));
 
276
    QCOMPARE(calendar->formatDate(testDate, "%_n"),   QString("1"));
 
277
    QCOMPARE(calendar->formatDate(testDate, "%_d"),   QString(" 2"));
 
278
    QCOMPARE(calendar->formatDate(testDate, "%_e"),   QString("2"));
 
279
    QCOMPARE(calendar->formatDate(testDate, "%_j"),   QString("  2"));
 
280
    QCOMPARE(calendar->formatDate(testDate, "%-m"),   QString("1"));
 
281
    QCOMPARE(calendar->formatDate(testDate, "%-n"),   QString("1"));
 
282
    QCOMPARE(calendar->formatDate(testDate, "%-d"),   QString("2"));
 
283
    QCOMPARE(calendar->formatDate(testDate, "%-e"),   QString("2"));
 
284
    QCOMPARE(calendar->formatDate(testDate, "%-j"),   QString("2"));
 
285
    QCOMPARE(calendar->formatDate(testDate, "%0m"),   QString("01"));
 
286
    QCOMPARE(calendar->formatDate(testDate, "%0n"),   QString("1"));
 
287
    QCOMPARE(calendar->formatDate(testDate, "%0d"),   QString("02"));
 
288
    QCOMPARE(calendar->formatDate(testDate, "%0e"),   QString("2"));
 
289
    QCOMPARE(calendar->formatDate(testDate, "%0j"),   QString("002"));
 
290
    QCOMPARE(calendar->formatDate(testDate, "%-_j"),  QString("  2"));
 
291
    QCOMPARE(calendar->formatDate(testDate, "%_-j"),  QString("2"));
 
292
    QCOMPARE(calendar->formatDate(testDate, "%-_0j"), QString("002"));
273
293
 
274
294
    //Test various padding options with width override
275
 
    QCOMPARE( calendar->formatDate( testDate, "%1m" ),   QString( "01" ) );
276
 
    QCOMPARE( calendar->formatDate( testDate, "%-05m" ), QString( "00001" ) );
277
 
    QCOMPARE( calendar->formatDate( testDate, "%10m" ),  QString( "0000000001" ) );
278
 
    QCOMPARE( calendar->formatDate( testDate, "%15m" ),  QString( "000000000000001" ) );
279
 
    QCOMPARE( calendar->formatDate( testDate, "%-5m" ),  QString( "1" ) );
280
 
    QCOMPARE( calendar->formatDate( testDate, "%_5m" ),  QString( "    1" ) );
281
 
    QCOMPARE( calendar->formatDate( testDate, "%_15m" ), QString( "              1" ) );
282
 
    QCOMPARE( calendar->formatDate( testDate, "%1B" ),   QString( "January" ) );
283
 
    QCOMPARE( calendar->formatDate( testDate, "%15B" ),  QString( "        January" ) );
284
 
    QCOMPARE( calendar->formatDate( testDate, "%-15B" ), QString( "January" ) );
285
 
    QCOMPARE( calendar->formatDate( testDate, "%_15B" ), QString( "        January" ) );
286
 
    QCOMPARE( calendar->formatDate( testDate, "%015B" ), QString( "00000000January" ) );
 
295
    QCOMPARE(calendar->formatDate(testDate, "%1m"),   QString("01"));
 
296
    QCOMPARE(calendar->formatDate(testDate, "%-05m"), QString("00001"));
 
297
    QCOMPARE(calendar->formatDate(testDate, "%10m"),  QString("0000000001"));
 
298
    QCOMPARE(calendar->formatDate(testDate, "%15m"),  QString("000000000000001"));
 
299
    QCOMPARE(calendar->formatDate(testDate, "%-5m"),  QString("1"));
 
300
    QCOMPARE(calendar->formatDate(testDate, "%_5m"),  QString("    1"));
 
301
    QCOMPARE(calendar->formatDate(testDate, "%_15m"), QString("              1"));
 
302
    QCOMPARE(calendar->formatDate(testDate, "%1B"),   QString("January"));
 
303
    QCOMPARE(calendar->formatDate(testDate, "%15B"),  QString("        January"));
 
304
    QCOMPARE(calendar->formatDate(testDate, "%-15B"), QString("January"));
 
305
    QCOMPARE(calendar->formatDate(testDate, "%_15B"), QString("        January"));
 
306
    QCOMPARE(calendar->formatDate(testDate, "%015B"), QString("00000000January"));
287
307
 
288
308
    //Test week number in previous year
289
 
    QCOMPARE( calendar->formatDate( testDate, "%V" ), QString( "53" ) );
290
 
    QCOMPARE( calendar->formatDate( testDate, "%G" ), QString( "2004" ) );
291
 
    QCOMPARE( calendar->formatDate( testDate, "%g" ), QString( "04" ) );
 
309
    QCOMPARE(calendar->formatDate(testDate, "%V"), QString("53"));
 
310
    QCOMPARE(calendar->formatDate(testDate, "%G"), QString("2004"));
 
311
    QCOMPARE(calendar->formatDate(testDate, "%g"), QString("04"));
292
312
 
293
313
    //test case overrides
294
 
    QCOMPARE( calendar->formatDate( testDate, "%B" ),  QString( "January" ) );
295
 
    QCOMPARE( calendar->formatDate( testDate, "%^B" ), QString( "JANUARY" ) );
296
 
    QCOMPARE( calendar->formatDate( testDate, "%#B" ), QString( "JANUARY" ) );
297
 
    QCOMPARE( calendar->formatDate( testDate, "%m" ),  QString( "01" ) );
298
 
    QCOMPARE( calendar->formatDate( testDate, "%^m" ), QString( "01" ) );
299
 
    QCOMPARE( calendar->formatDate( testDate, "%#m" ), QString( "01" ) );
 
314
    QCOMPARE(calendar->formatDate(testDate, "%B"),  QString("January"));
 
315
    QCOMPARE(calendar->formatDate(testDate, "%^B"), QString("JANUARY"));
 
316
    QCOMPARE(calendar->formatDate(testDate, "%#B"), QString("JANUARY"));
 
317
    QCOMPARE(calendar->formatDate(testDate, "%m"),  QString("01"));
 
318
    QCOMPARE(calendar->formatDate(testDate, "%^m"), QString("01"));
 
319
    QCOMPARE(calendar->formatDate(testDate, "%#m"), QString("01"));
300
320
 
301
321
    //Test various year options
302
322
 
303
 
    testDate.setDate( 789, 1, 1 );
304
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "0789" ) );
305
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "07" ) );
306
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "89" ) );
307
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "789" ) );
308
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "7" ) );
309
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "89" ) );
310
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( " 789" ) );
311
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( " 7" ) );
312
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "89" ) );
313
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "0789" ) );
314
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "07" ) );
315
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "89" ) );
316
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "AD" ) );
317
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "789" ) );
318
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "789 AD" ) );
319
 
 
320
 
    testDate.setDate( 709, 1, 1 );
321
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "0709" ) );
322
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "07" ) );
323
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "09" ) );
324
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "709" ) );
325
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "7" ) );
326
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "9" ) );
327
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( " 709" ) );
328
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( " 7" ) );
329
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( " 9" ) );
330
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "0709" ) );
331
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "07" ) );
332
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "09" ) );
333
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "AD" ) );
334
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "709" ) );
335
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "709 AD" ) );
336
 
 
337
 
    testDate.setDate( 89, 1, 1 );
338
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "0089" ) );
339
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "00" ) );
340
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "89" ) );
341
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "89" ) );
342
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "0" ) );
343
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "89" ) );
344
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "  89" ) );
345
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( " 0" ) );
346
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "89" ) );
347
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "0089" ) );
348
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "00" ) );
349
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "89" ) );
350
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "AD" ) );
351
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "89" ) );
352
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "89 AD" ) );
353
 
 
354
 
    testDate.setDate( 9, 1, 1 );
355
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "0009" ) );
356
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "00" ) );
357
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "09" ) );
358
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "9" ) );
359
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "0" ) );
360
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "9" ) );
361
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "   9" ) );
362
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( " 0" ) );
363
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( " 9" ) );
364
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "0009" ) );
365
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "00" ) );
366
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "09" ) );
367
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "AD" ) );
368
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "9" ) );
369
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "9 AD" ) );
370
 
 
371
 
    testDate.setDate( -9, 1, 1 );
372
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "-0009" ) );
373
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "-00" ) );
374
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "-09" ) );
375
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-9" ) );
376
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-0" ) );
377
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-9" ) );
378
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "  -9" ) );
379
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-0" ) );
380
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-9" ) );
381
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-0009" ) );
382
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-00" ) );
383
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-09" ) );
384
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "BC" ) );
385
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "9" ) );
386
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "9 BC" ) );
387
 
 
388
 
    testDate.setDate( -89, 1, 1 );
389
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "-0089" ) );
390
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "-00" ) );
391
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "-89" ) );
392
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-89" ) );
393
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-0" ) );
394
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-89" ) );
395
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( " -89" ) );
396
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-0" ) );
397
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-89" ) );
398
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-0089" ) );
399
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-00" ) );
400
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-89" ) );
401
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "BC" ) );
402
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "89" ) );
403
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "89 BC" ) );
404
 
 
405
 
    testDate.setDate( -789, 1, 1 );
406
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "-0789" ) );
407
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "-07" ) );
408
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "-89" ) );
409
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-789" ) );
410
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-7" ) );
411
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-89" ) );
412
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-789" ) );
413
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-7" ) );
414
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-89" ) );
415
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-0789" ) );
416
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-07" ) );
417
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-89" ) );
418
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "BC" ) );
419
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "789" ) );
420
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "789 BC" ) );
421
 
 
422
 
    testDate.setDate( -709, 1, 1 );
423
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "-0709" ) );
424
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "-07" ) );
425
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "-09" ) );
426
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-709" ) );
427
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-7" ) );
428
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-9" ) );
429
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-709" ) );
430
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-7" ) );
431
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-9" ) );
432
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-0709" ) );
433
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-07" ) );
434
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-09" ) );
435
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "BC" ) );
436
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "709" ) );
437
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "709 BC" ) );
438
 
 
439
 
    testDate.setDate( -1789, 1, 1 );
440
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "-1789" ) );
441
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "-17" ) );
442
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "-89" ) );
443
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-1789" ) );
444
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-17" ) );
445
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-89" ) );
446
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-1789" ) );
447
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-17" ) );
448
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-89" ) );
449
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-1789" ) );
450
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-17" ) );
451
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-89" ) );
452
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "BC" ) );
453
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "1789" ) );
454
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "1789 BC" ) );
455
 
 
456
 
    testDate.setDate( -1709, 1, 1 );
457
 
    QCOMPARE( calendar->formatDate( testDate, "%Y" ),  QString( "-1709" ) );
458
 
    QCOMPARE( calendar->formatDate( testDate, "%C" ),  QString( "-17" ) );
459
 
    QCOMPARE( calendar->formatDate( testDate, "%y" ),  QString( "-09" ) );
460
 
    QCOMPARE( calendar->formatDate( testDate, "%-Y" ), QString( "-1709" ) );
461
 
    QCOMPARE( calendar->formatDate( testDate, "%-C" ), QString( "-17" ) );
462
 
    QCOMPARE( calendar->formatDate( testDate, "%-y" ), QString( "-9" ) );
463
 
    QCOMPARE( calendar->formatDate( testDate, "%_Y" ), QString( "-1709" ) );
464
 
    QCOMPARE( calendar->formatDate( testDate, "%_C" ), QString( "-17" ) );
465
 
    QCOMPARE( calendar->formatDate( testDate, "%_y" ), QString( "-9" ) );
466
 
    QCOMPARE( calendar->formatDate( testDate, "%0Y" ), QString( "-1709" ) );
467
 
    QCOMPARE( calendar->formatDate( testDate, "%0C" ), QString( "-17" ) );
468
 
    QCOMPARE( calendar->formatDate( testDate, "%0y" ), QString( "-09" ) );
469
 
    QCOMPARE( calendar->formatDate( testDate, "%EC" ), QString( "BC" ) );
470
 
    QCOMPARE( calendar->formatDate( testDate, "%Ey" ), QString( "1709" ) );
471
 
    QCOMPARE( calendar->formatDate( testDate, "%EY" ), QString( "1709 BC" ) );
 
323
    testDate.setDate(789, 1, 1);
 
324
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("0789"));
 
325
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("07"));
 
326
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("89"));
 
327
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("789"));
 
328
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("7"));
 
329
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("89"));
 
330
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString(" 789"));
 
331
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString(" 7"));
 
332
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString("89"));
 
333
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("0789"));
 
334
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("07"));
 
335
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("89"));
 
336
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("AD"));
 
337
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("789"));
 
338
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("789 AD"));
 
339
 
 
340
    testDate.setDate(709, 1, 1);
 
341
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("0709"));
 
342
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("07"));
 
343
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("09"));
 
344
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("709"));
 
345
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("7"));
 
346
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("9"));
 
347
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString(" 709"));
 
348
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString(" 7"));
 
349
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString(" 9"));
 
350
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("0709"));
 
351
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("07"));
 
352
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("09"));
 
353
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("AD"));
 
354
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("709"));
 
355
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("709 AD"));
 
356
 
 
357
    testDate.setDate(89, 1, 1);
 
358
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("0089"));
 
359
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("00"));
 
360
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("89"));
 
361
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("89"));
 
362
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("0"));
 
363
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("89"));
 
364
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString("  89"));
 
365
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString(" 0"));
 
366
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString("89"));
 
367
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("0089"));
 
368
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("00"));
 
369
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("89"));
 
370
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("AD"));
 
371
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("89"));
 
372
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("89 AD"));
 
373
 
 
374
    testDate.setDate(9, 1, 1);
 
375
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("0009"));
 
376
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("00"));
 
377
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("09"));
 
378
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("9"));
 
379
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("0"));
 
380
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("9"));
 
381
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString("   9"));
 
382
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString(" 0"));
 
383
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString(" 9"));
 
384
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("0009"));
 
385
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("00"));
 
386
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("09"));
 
387
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("AD"));
 
388
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("9"));
 
389
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("9 AD"));
 
390
 
 
391
    testDate.setDate(-9, 1, 1);
 
392
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("-0009"));
 
393
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("-00"));
 
394
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("-09"));
 
395
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("-9"));
 
396
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("-0"));
 
397
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("-9"));
 
398
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString("  -9"));
 
399
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString("-0"));
 
400
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString("-9"));
 
401
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("-0009"));
 
402
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("-00"));
 
403
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("-09"));
 
404
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("BC"));
 
405
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("9"));
 
406
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("9 BC"));
 
407
 
 
408
    testDate.setDate(-89, 1, 1);
 
409
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("-0089"));
 
410
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("-00"));
 
411
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("-89"));
 
412
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("-89"));
 
413
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("-0"));
 
414
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("-89"));
 
415
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString(" -89"));
 
416
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString("-0"));
 
417
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString("-89"));
 
418
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("-0089"));
 
419
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("-00"));
 
420
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("-89"));
 
421
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("BC"));
 
422
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("89"));
 
423
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("89 BC"));
 
424
 
 
425
    testDate.setDate(-789, 1, 1);
 
426
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("-0789"));
 
427
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("-07"));
 
428
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("-89"));
 
429
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("-789"));
 
430
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("-7"));
 
431
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("-89"));
 
432
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString("-789"));
 
433
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString("-7"));
 
434
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString("-89"));
 
435
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("-0789"));
 
436
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("-07"));
 
437
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("-89"));
 
438
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("BC"));
 
439
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("789"));
 
440
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("789 BC"));
 
441
 
 
442
    testDate.setDate(-709, 1, 1);
 
443
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("-0709"));
 
444
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("-07"));
 
445
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("-09"));
 
446
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("-709"));
 
447
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("-7"));
 
448
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("-9"));
 
449
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString("-709"));
 
450
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString("-7"));
 
451
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString("-9"));
 
452
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("-0709"));
 
453
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("-07"));
 
454
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("-09"));
 
455
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("BC"));
 
456
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("709"));
 
457
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("709 BC"));
 
458
 
 
459
    testDate.setDate(-1789, 1, 1);
 
460
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("-1789"));
 
461
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("-17"));
 
462
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("-89"));
 
463
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("-1789"));
 
464
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("-17"));
 
465
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("-89"));
 
466
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString("-1789"));
 
467
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString("-17"));
 
468
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString("-89"));
 
469
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("-1789"));
 
470
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("-17"));
 
471
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("-89"));
 
472
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("BC"));
 
473
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("1789"));
 
474
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("1789 BC"));
 
475
 
 
476
    testDate.setDate(-1709, 1, 1);
 
477
    QCOMPARE(calendar->formatDate(testDate, "%Y"),  QString("-1709"));
 
478
    QCOMPARE(calendar->formatDate(testDate, "%C"),  QString("-17"));
 
479
    QCOMPARE(calendar->formatDate(testDate, "%y"),  QString("-09"));
 
480
    QCOMPARE(calendar->formatDate(testDate, "%-Y"), QString("-1709"));
 
481
    QCOMPARE(calendar->formatDate(testDate, "%-C"), QString("-17"));
 
482
    QCOMPARE(calendar->formatDate(testDate, "%-y"), QString("-9"));
 
483
    QCOMPARE(calendar->formatDate(testDate, "%_Y"), QString("-1709"));
 
484
    QCOMPARE(calendar->formatDate(testDate, "%_C"), QString("-17"));
 
485
    QCOMPARE(calendar->formatDate(testDate, "%_y"), QString("-9"));
 
486
    QCOMPARE(calendar->formatDate(testDate, "%0Y"), QString("-1709"));
 
487
    QCOMPARE(calendar->formatDate(testDate, "%0C"), QString("-17"));
 
488
    QCOMPARE(calendar->formatDate(testDate, "%0y"), QString("-09"));
 
489
    QCOMPARE(calendar->formatDate(testDate, "%EC"), QString("BC"));
 
490
    QCOMPARE(calendar->formatDate(testDate, "%Ey"), QString("1709"));
 
491
    QCOMPARE(calendar->formatDate(testDate, "%EY"), QString("1709 BC"));
472
492
 
473
493
    // Test POSIX format
474
 
    testDate.setDate( 2010, 1, 2 );
475
 
    QCOMPARE( calendar->formatDate( testDate, "%Y-%n-%d", KLocale::KdeFormat ),   QString( "2010-1-02" ) );
476
 
    QCOMPARE( calendar->formatDate( testDate, "%Y-%n-%d", KLocale::PosixFormat ), QString( "2010-\n-02" ) );
477
 
    QCOMPARE( calendar->formatDate( testDate, "%e", KLocale::KdeFormat ),   QString( "2" ) );
478
 
    QCOMPARE( calendar->formatDate( testDate, "%e", KLocale::PosixFormat ), QString( " 2" ) );
 
494
    testDate.setDate(2010, 1, 2);
 
495
    QCOMPARE(calendar->formatDate(testDate, "%Y-%n-%d", KLocale::KdeFormat),   QString("2010-1-02"));
 
496
    QCOMPARE(calendar->formatDate(testDate, "%Y-%n-%d", KLocale::PosixFormat), QString("2010-\n-02"));
 
497
    QCOMPARE(calendar->formatDate(testDate, "%e", KLocale::KdeFormat),   QString("2"));
 
498
    QCOMPARE(calendar->formatDate(testDate, "%e", KLocale::PosixFormat), QString(" 2"));
479
499
 
480
500
    delete calendar;
481
501
    delete locale;
483
503
 
484
504
void KCalendarTest::testFormatUnicode()
485
505
{
486
 
    KLocale *locale = new KLocale( *KGlobal::locale() );
487
 
    locale->setDateFormatShort( "%y-%m-%d" );
488
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
489
 
 
490
 
    QDate testDate( 2005, 10, 20 );
491
 
    compareFormatUnicode( calendar, testDate, "yyyy" );
492
 
    compareFormatUnicode( calendar, testDate, "yy" );
493
 
    compareFormatUnicode( calendar, testDate, "MMMM" );
494
 
    compareFormatUnicode( calendar, testDate, "MMM" );
495
 
    compareFormatUnicode( calendar, testDate, "MM" );
496
 
    compareFormatUnicode( calendar, testDate, "M" );
497
 
    compareFormatUnicode( calendar, testDate, "dddd" );
498
 
    compareFormatUnicode( calendar, testDate, "ddd" );
499
 
    compareFormatUnicode( calendar, testDate, "dd" );
500
 
    compareFormatUnicode( calendar, testDate, "d" );
501
 
    compareFormatUnicode( calendar, testDate, "yyyy-MM-dd" );
502
 
 
503
 
    testDate.setDate( -2005, 10, 20 );
504
 
    compareFormatUnicode( calendar, testDate, "yyyy" );
505
 
    compareFormatUnicode( calendar, testDate, "yy" );
506
 
    compareFormatUnicode( calendar, testDate, "MMMM" );
507
 
    compareFormatUnicode( calendar, testDate, "MMM" );
508
 
    compareFormatUnicode( calendar, testDate, "MM" );
509
 
    compareFormatUnicode( calendar, testDate, "M" );
510
 
    compareFormatUnicode( calendar, testDate, "dddd" );
511
 
    compareFormatUnicode( calendar, testDate, "ddd" );
512
 
    compareFormatUnicode( calendar, testDate, "dd" );
513
 
    compareFormatUnicode( calendar, testDate, "d" );
514
 
    compareFormatUnicode( calendar, testDate, "yyyy-MM-dd" );
 
506
    KLocale *locale = new KLocale(*KGlobal::locale());
 
507
    locale->setDateFormatShort("%y-%m-%d");
 
508
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
 
509
 
 
510
    QDate testDate(2005, 10, 20);
 
511
    compareFormatUnicode(calendar, testDate, "yyyy");
 
512
    compareFormatUnicode(calendar, testDate, "yy");
 
513
    compareFormatUnicode(calendar, testDate, "MMMM");
 
514
    compareFormatUnicode(calendar, testDate, "MMM");
 
515
    compareFormatUnicode(calendar, testDate, "MM");
 
516
    compareFormatUnicode(calendar, testDate, "M");
 
517
    compareFormatUnicode(calendar, testDate, "dddd");
 
518
    compareFormatUnicode(calendar, testDate, "ddd");
 
519
    compareFormatUnicode(calendar, testDate, "dd");
 
520
    compareFormatUnicode(calendar, testDate, "d");
 
521
    compareFormatUnicode(calendar, testDate, "yyyy-MM-dd");
 
522
 
 
523
    testDate.setDate(-2005, 10, 20);
 
524
    compareFormatUnicode(calendar, testDate, "yyyy");
 
525
    compareFormatUnicode(calendar, testDate, "yy");
 
526
    compareFormatUnicode(calendar, testDate, "MMMM");
 
527
    compareFormatUnicode(calendar, testDate, "MMM");
 
528
    compareFormatUnicode(calendar, testDate, "MM");
 
529
    compareFormatUnicode(calendar, testDate, "M");
 
530
    compareFormatUnicode(calendar, testDate, "dddd");
 
531
    compareFormatUnicode(calendar, testDate, "ddd");
 
532
    compareFormatUnicode(calendar, testDate, "dd");
 
533
    compareFormatUnicode(calendar, testDate, "d");
 
534
    compareFormatUnicode(calendar, testDate, "yyyy-MM-dd");
515
535
}
516
536
 
517
 
void KCalendarTest::compareFormatUnicode( const KCalendarSystem *calendar, const QDate &testDate, const QString &testFormat )
 
537
void KCalendarTest::compareFormatUnicode(const KCalendarSystem *calendar, const QDate &testDate, const QString &testFormat)
518
538
{
519
 
    QCOMPARE( calendar->formatDate( testDate, testFormat, KLocale::UnicodeFormat ), testDate.toString( testFormat ) );
 
539
    QCOMPARE(calendar->formatDate(testDate, testFormat, KLocale::UnicodeFormat), testDate.toString(testFormat));
520
540
}
521
541
 
522
542
void KCalendarTest::testReadDate()
523
543
{
524
 
    KLocale *locale = new KLocale( *KGlobal::locale() );
525
 
    locale->setDateFormatShort( "%y-%m-%d" );
526
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
 
544
    KLocale *locale = new KLocale(*KGlobal::locale());
 
545
    locale->setDateFormatShort("%y-%m-%d");
 
546
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
527
547
    int currentYear = QDate::currentDate().year();
528
548
 
529
549
    //Test default settings
530
 
    QDate testDate( 2005, 10, 20 );
 
550
    QDate testDate(2005, 10, 20);
531
551
 
532
552
    //Test Month and Day
533
 
    QCOMPARE( calendar->readDate( "2005-01-01",  "%Y-%m-%d" ), QDate( 2005, 1, 1 ) );
534
 
    QCOMPARE( calendar->readDate( "-2005-01-01", "%Y-%m-%d" ), QDate( -2005, 1, 1 ) );
535
 
    QCOMPARE( calendar->readDate( "05-01-01",    "%y-%m-%d" ), QDate( 2005, 1, 1 ) );
536
 
    QCOMPARE( calendar->readDate( "01-01",       "%m-%d" ),    QDate( currentYear, 1, 1 ) );
 
553
    QCOMPARE(calendar->readDate("2005-01-01",  "%Y-%m-%d"), QDate(2005, 1, 1));
 
554
    QCOMPARE(calendar->readDate("-2005-01-01", "%Y-%m-%d"), QDate(-2005, 1, 1));
 
555
    QCOMPARE(calendar->readDate("05-01-01",    "%y-%m-%d"), QDate(2005, 1, 1));
 
556
    QCOMPARE(calendar->readDate("01-01",       "%m-%d"),    QDate(currentYear, 1, 1));
537
557
 
538
558
    //Test Era and Year In Era
539
 
    QCOMPARE( calendar->readDate( "1 1 2005 AD", "%d %m %Ey %EC" ), QDate( 2005, 1, 1 ) );
540
 
    QCOMPARE( calendar->readDate( "1 1 2005 Anno Domini", "%d %m %Ey %EC" ), QDate( 2005, 1, 1 ) );
541
 
    QCOMPARE( calendar->readDate( "1 1 2005 BC", "%d %m %Ey %EC" ), QDate( -2005, 1, 1 ) );
542
 
    QCOMPARE( calendar->readDate( "1 1 2005 Before Christ", "%d %m %Ey %EC" ), QDate( -2005, 1, 1 ) );
543
 
    QCOMPARE( calendar->readDate( "1 1 2005 AD", "%d %m %EY" ), QDate( 2005, 1, 1 ) );
544
 
    QCOMPARE( calendar->readDate( "1 1 2005 Anno Domini", "%d %m %EY" ), QDate( 2005, 1, 1 ) );
545
 
    QCOMPARE( calendar->readDate( "1 1 2005 BC", "%d %m %EY" ), QDate( -2005, 1, 1 ) );
546
 
    QCOMPARE( calendar->readDate( "1 1 2005 Before Christ", "%d %m %EY" ), QDate( -2005, 1, 1 ) );
547
 
    QCOMPARE( calendar->readDate( "1 2005 AD January", "%d %Ey %EC %B" ), QDate( 2005, 1, 1 ) );
548
 
    QCOMPARE( calendar->readDate( "1 2005 AD January", "%d %EY %B" ), QDate( 2005, 1, 1 ) );
549
 
    QCOMPARE( calendar->readDate( "2005 AD January 1", "%Ey %EC %B %d" ), QDate( 2005, 1, 1 ) );
550
 
    QCOMPARE( calendar->readDate( "2005 AD January 1", "%EY %B %d" ), QDate( 2005, 1, 1 ) );
 
559
    QCOMPARE(calendar->readDate("1 1 2005 AD", "%d %m %Ey %EC"), QDate(2005, 1, 1));
 
560
    QCOMPARE(calendar->readDate("1 1 2005 Anno Domini", "%d %m %Ey %EC"), QDate(2005, 1, 1));
 
561
    QCOMPARE(calendar->readDate("1 1 2005 BC", "%d %m %Ey %EC"), QDate(-2005, 1, 1));
 
562
    QCOMPARE(calendar->readDate("1 1 2005 Before Christ", "%d %m %Ey %EC"), QDate(-2005, 1, 1));
 
563
    QCOMPARE(calendar->readDate("1 1 2005 AD", "%d %m %EY"), QDate(2005, 1, 1));
 
564
    QCOMPARE(calendar->readDate("1 1 2005 Anno Domini", "%d %m %EY"), QDate(2005, 1, 1));
 
565
    QCOMPARE(calendar->readDate("1 1 2005 BC", "%d %m %EY"), QDate(-2005, 1, 1));
 
566
    QCOMPARE(calendar->readDate("1 1 2005 Before Christ", "%d %m %EY"), QDate(-2005, 1, 1));
 
567
    QCOMPARE(calendar->readDate("1 2005 AD January", "%d %Ey %EC %B"), QDate(2005, 1, 1));
 
568
    QCOMPARE(calendar->readDate("1 2005 AD January", "%d %EY %B"), QDate(2005, 1, 1));
 
569
    QCOMPARE(calendar->readDate("2005 AD January 1", "%Ey %EC %B %d"), QDate(2005, 1, 1));
 
570
    QCOMPARE(calendar->readDate("2005 AD January 1", "%EY %B %d"), QDate(2005, 1, 1));
551
571
 
552
572
    //Test Day-of-Year
553
 
    QCOMPARE( calendar->readDate( "2005-001", "%Y-%j" ), QDate( 2005, 1, 1 ) );
554
 
    QCOMPARE( calendar->readDate( "2005-1",   "%Y-%j" ), QDate( 2005, 1, 1 ) );
555
 
    QCOMPARE( calendar->readDate( "001",      "%j" ),    QDate( currentYear, 1, 1 ) );
556
 
    QCOMPARE( calendar->readDate( "2005-365", "%Y-%j" ), QDate( 2005, 12, 31 ) );
557
 
    QCOMPARE( calendar->readDate( "2000-366", "%Y-%j" ), QDate( 2000, 12, 31 ) );
 
573
    QCOMPARE(calendar->readDate("2005-001", "%Y-%j"), QDate(2005, 1, 1));
 
574
    QCOMPARE(calendar->readDate("2005-1",   "%Y-%j"), QDate(2005, 1, 1));
 
575
    QCOMPARE(calendar->readDate("001",      "%j"),    QDate(currentYear, 1, 1));
 
576
    QCOMPARE(calendar->readDate("2005-365", "%Y-%j"), QDate(2005, 12, 31));
 
577
    QCOMPARE(calendar->readDate("2000-366", "%Y-%j"), QDate(2000, 12, 31));
558
578
 
559
 
    QCOMPARE( calendar->readDate( "2005-000", "%Y-%j" ), QDate() );
560
 
    QCOMPARE( calendar->readDate( "2005-366", "%Y-%j" ), QDate() );
561
 
    QCOMPARE( calendar->readDate( "2000-367", "%Y-%j" ), QDate() );
 
579
    QCOMPARE(calendar->readDate("2005-000", "%Y-%j"), QDate());
 
580
    QCOMPARE(calendar->readDate("2005-366", "%Y-%j"), QDate());
 
581
    QCOMPARE(calendar->readDate("2000-367", "%Y-%j"), QDate());
562
582
 
563
583
    //Test Weekday and Month names
564
 
    QCOMPARE( calendar->readDate( "Monday 2004-01-05", "%A %Y-%m-%d" ), QDate( 2004,  1,  5 ) );
565
 
    QCOMPARE( calendar->readDate( "Mon 2004-01-05",    "%A %Y-%m-%d" ), QDate( 2004,  1,  5 ) );
566
 
    QCOMPARE( calendar->readDate( "Monday 2004-01-05", "%a %Y-%m-%d" ), QDate( 2004,  1,  5 ) );
567
 
    QCOMPARE( calendar->readDate( "Mon 2004-01-05",    "%a %Y-%m-%d" ), QDate( 2004,  1,  5 ) );
568
 
 
569
 
    QCOMPARE( calendar->readDate( "Sunday 2004-01-11", "%A %Y-%m-%d" ), QDate( 2004,  1, 11 ) );
570
 
    QCOMPARE( calendar->readDate( "Sun 2004-01-11",    "%A %Y-%m-%d" ), QDate( 2004,  1, 11 ) );
571
 
    QCOMPARE( calendar->readDate( "Sunday 2004-01-11", "%a %Y-%m-%d" ), QDate( 2004,  1, 11 ) );
572
 
    QCOMPARE( calendar->readDate( "Sun 2004-01-11",    "%a %Y-%m-%d" ), QDate( 2004,  1, 11 ) );
573
 
 
574
 
    QCOMPARE( calendar->readDate( "2004 January 01",  "%Y %B %d" ), QDate( 2004,  1,  1 ) );
575
 
    QCOMPARE( calendar->readDate( "2004 Jan 01",      "%Y %B %d" ), QDate( 2004,  1,  1 ) );
576
 
    QCOMPARE( calendar->readDate( "2004 January 01",  "%Y %b %d" ), QDate( 2004,  1,  1 ) );
577
 
    QCOMPARE( calendar->readDate( "2004 Jan 01",      "%Y %b %d" ), QDate( 2004,  1,  1 ) );
578
 
 
579
 
    QCOMPARE( calendar->readDate( "2004 December 01", "%Y %B %d" ), QDate( 2004, 12,  1 ) );
580
 
    QCOMPARE( calendar->readDate( "2004 Dec 01",      "%Y %B %d" ), QDate( 2004, 12,  1 ) );
581
 
    QCOMPARE( calendar->readDate( "2004 December 01", "%Y %b %d" ), QDate( 2004, 12,  1 ) );
582
 
    QCOMPARE( calendar->readDate( "2004 Dec 01",      "%Y %b %d" ), QDate( 2004, 12,  1 ) );
583
 
 
584
 
    QCOMPARE( calendar->readDate( "Wednesday 2004 December 01", "%A %Y %B %d" ), QDate( 2004, 12,  1 ) );
585
 
    QCOMPARE( calendar->readDate( "Wed 2004 Dec 01",            "%A %Y %B %d" ), QDate( 2004, 12,  1 ) );
586
 
    QCOMPARE( calendar->readDate( "Wednesday 2004 December 01", "%a %Y %b %d" ), QDate( 2004, 12,  1 ) );
587
 
    QCOMPARE( calendar->readDate( "Wed 2004 Dec 01",            "%a %Y %b %d" ), QDate( 2004, 12,  1 ) );
 
584
    QCOMPARE(calendar->readDate("Monday 2004-01-05", "%A %Y-%m-%d"), QDate(2004,  1,  5));
 
585
    QCOMPARE(calendar->readDate("Mon 2004-01-05",    "%A %Y-%m-%d"), QDate(2004,  1,  5));
 
586
    QCOMPARE(calendar->readDate("Monday 2004-01-05", "%a %Y-%m-%d"), QDate(2004,  1,  5));
 
587
    QCOMPARE(calendar->readDate("Mon 2004-01-05",    "%a %Y-%m-%d"), QDate(2004,  1,  5));
 
588
 
 
589
    QCOMPARE(calendar->readDate("Sunday 2004-01-11", "%A %Y-%m-%d"), QDate(2004,  1, 11));
 
590
    QCOMPARE(calendar->readDate("Sun 2004-01-11",    "%A %Y-%m-%d"), QDate(2004,  1, 11));
 
591
    QCOMPARE(calendar->readDate("Sunday 2004-01-11", "%a %Y-%m-%d"), QDate(2004,  1, 11));
 
592
    QCOMPARE(calendar->readDate("Sun 2004-01-11",    "%a %Y-%m-%d"), QDate(2004,  1, 11));
 
593
 
 
594
    QCOMPARE(calendar->readDate("2004 January 01",  "%Y %B %d"), QDate(2004,  1,  1));
 
595
    QCOMPARE(calendar->readDate("2004 Jan 01",      "%Y %B %d"), QDate(2004,  1,  1));
 
596
    QCOMPARE(calendar->readDate("2004 January 01",  "%Y %b %d"), QDate(2004,  1,  1));
 
597
    QCOMPARE(calendar->readDate("2004 Jan 01",      "%Y %b %d"), QDate(2004,  1,  1));
 
598
 
 
599
    QCOMPARE(calendar->readDate("2004 December 01", "%Y %B %d"), QDate(2004, 12,  1));
 
600
    QCOMPARE(calendar->readDate("2004 Dec 01",      "%Y %B %d"), QDate(2004, 12,  1));
 
601
    QCOMPARE(calendar->readDate("2004 December 01", "%Y %b %d"), QDate(2004, 12,  1));
 
602
    QCOMPARE(calendar->readDate("2004 Dec 01",      "%Y %b %d"), QDate(2004, 12,  1));
 
603
 
 
604
    QCOMPARE(calendar->readDate("Wednesday 2004 December 01", "%A %Y %B %d"), QDate(2004, 12,  1));
 
605
    QCOMPARE(calendar->readDate("Wed 2004 Dec 01",            "%A %Y %B %d"), QDate(2004, 12,  1));
 
606
    QCOMPARE(calendar->readDate("Wednesday 2004 December 01", "%a %Y %b %d"), QDate(2004, 12,  1));
 
607
    QCOMPARE(calendar->readDate("Wed 2004 Dec 01",            "%a %Y %b %d"), QDate(2004, 12,  1));
588
608
 
589
609
    //Test ISO Week and Day-of-Week
590
 
    QCOMPARE( calendar->readDate( "2004-W01-1", "%Y-W%V-%u" ), QDate( 2003, 12, 29 ) );
591
 
    QCOMPARE( calendar->readDate( "2004-W01-2", "%Y-W%V-%u" ), QDate( 2003, 12, 30 ) );
592
 
    QCOMPARE( calendar->readDate( "2004-W01-3", "%Y-W%V-%u" ), QDate( 2003, 12, 31 ) );
593
 
    QCOMPARE( calendar->readDate( "2004-W01-4", "%Y-W%V-%u" ), QDate( 2004, 1, 1 ) );
594
 
    QCOMPARE( calendar->readDate( "2004-W01-5", "%Y-W%V-%u" ), QDate( 2004, 1, 2 ) );
595
 
    QCOMPARE( calendar->readDate( "2004-W01-6", "%Y-W%V-%u" ), QDate( 2004, 1, 3 ) );
596
 
    QCOMPARE( calendar->readDate( "2004-W01-7", "%Y-W%V-%u" ), QDate( 2004, 1, 4 ) );
597
 
 
598
 
    QCOMPARE( calendar->readDate( "2004-W24-1", "%Y-W%V-%u" ), QDate( 2004, 6, 7 ) );
599
 
    QCOMPARE( calendar->readDate( "2004-W24-2", "%Y-W%V-%u" ), QDate( 2004, 6, 8 ) );
600
 
    QCOMPARE( calendar->readDate( "2004-W24-3", "%Y-W%V-%u" ), QDate( 2004, 6, 9 ) );
601
 
    QCOMPARE( calendar->readDate( "2004-W24-4", "%Y-W%V-%u" ), QDate( 2004, 6, 10 ) );
602
 
    QCOMPARE( calendar->readDate( "2004-W24-5", "%Y-W%V-%u" ), QDate( 2004, 6, 11 ) );
603
 
    QCOMPARE( calendar->readDate( "2004-W24-6", "%Y-W%V-%u" ), QDate( 2004, 6, 12 ) );
604
 
    QCOMPARE( calendar->readDate( "2004-W24-7", "%Y-W%V-%u" ), QDate( 2004, 6, 13 ) );
605
 
 
606
 
    QCOMPARE( calendar->readDate( "2004-W53-1", "%Y-W%V-%u" ), QDate( 2004, 12, 27 ) );
607
 
    QCOMPARE( calendar->readDate( "2004-W53-2", "%Y-W%V-%u" ), QDate( 2004, 12, 28 ) );
608
 
    QCOMPARE( calendar->readDate( "2004-W53-3", "%Y-W%V-%u" ), QDate( 2004, 12, 29 ) );
609
 
    QCOMPARE( calendar->readDate( "2004-W53-4", "%Y-W%V-%u" ), QDate( 2004, 12, 30 ) );
610
 
    QCOMPARE( calendar->readDate( "2004-W53-5", "%Y-W%V-%u" ), QDate( 2004, 12, 31 ) );
611
 
    QCOMPARE( calendar->readDate( "2004-W53-6", "%Y-W%V-%u" ), QDate( 2005, 1, 1 ) );
612
 
    QCOMPARE( calendar->readDate( "2004-W53-7", "%Y-W%V-%u" ), QDate( 2005, 1, 2 ) );
613
 
 
614
 
    calendar->setDateIsoWeek( testDate, currentYear, 46, 5 );
615
 
    QCOMPARE( calendar->readDate( "W46-5", "W%V-%u" ), testDate );
616
 
 
617
 
    QCOMPARE( calendar->readDate( "2004-W00-1", "%Y-W%V-%u" ),   QDate() );
618
 
    QCOMPARE( calendar->readDate( "2004-W01-0", "%Y-W%V-%u" ),   QDate() );
619
 
    QCOMPARE( calendar->readDate( "2004-W01-8", "%Y-W%V-%u" ),   QDate() );
620
 
    QCOMPARE( calendar->readDate( "2004-W54-1", "%Y-W%V-%u" ),   QDate() );
621
 
    QCOMPARE( calendar->readDate( "2004-W53-01", "%Y-W%V-%u" ),  QDate() );
622
 
    QCOMPARE( calendar->readDate( "2004-W053-01", "%Y-W%V-%u" ), QDate() );
 
610
    QCOMPARE(calendar->readDate("2004-W01-1", "%Y-W%V-%u"), QDate(2003, 12, 29));
 
611
    QCOMPARE(calendar->readDate("2004-W01-2", "%Y-W%V-%u"), QDate(2003, 12, 30));
 
612
    QCOMPARE(calendar->readDate("2004-W01-3", "%Y-W%V-%u"), QDate(2003, 12, 31));
 
613
    QCOMPARE(calendar->readDate("2004-W01-4", "%Y-W%V-%u"), QDate(2004, 1, 1));
 
614
    QCOMPARE(calendar->readDate("2004-W01-5", "%Y-W%V-%u"), QDate(2004, 1, 2));
 
615
    QCOMPARE(calendar->readDate("2004-W01-6", "%Y-W%V-%u"), QDate(2004, 1, 3));
 
616
    QCOMPARE(calendar->readDate("2004-W01-7", "%Y-W%V-%u"), QDate(2004, 1, 4));
 
617
 
 
618
    QCOMPARE(calendar->readDate("2004-W24-1", "%Y-W%V-%u"), QDate(2004, 6, 7));
 
619
    QCOMPARE(calendar->readDate("2004-W24-2", "%Y-W%V-%u"), QDate(2004, 6, 8));
 
620
    QCOMPARE(calendar->readDate("2004-W24-3", "%Y-W%V-%u"), QDate(2004, 6, 9));
 
621
    QCOMPARE(calendar->readDate("2004-W24-4", "%Y-W%V-%u"), QDate(2004, 6, 10));
 
622
    QCOMPARE(calendar->readDate("2004-W24-5", "%Y-W%V-%u"), QDate(2004, 6, 11));
 
623
    QCOMPARE(calendar->readDate("2004-W24-6", "%Y-W%V-%u"), QDate(2004, 6, 12));
 
624
    QCOMPARE(calendar->readDate("2004-W24-7", "%Y-W%V-%u"), QDate(2004, 6, 13));
 
625
 
 
626
    QCOMPARE(calendar->readDate("2004-W53-1", "%Y-W%V-%u"), QDate(2004, 12, 27));
 
627
    QCOMPARE(calendar->readDate("2004-W53-2", "%Y-W%V-%u"), QDate(2004, 12, 28));
 
628
    QCOMPARE(calendar->readDate("2004-W53-3", "%Y-W%V-%u"), QDate(2004, 12, 29));
 
629
    QCOMPARE(calendar->readDate("2004-W53-4", "%Y-W%V-%u"), QDate(2004, 12, 30));
 
630
    QCOMPARE(calendar->readDate("2004-W53-5", "%Y-W%V-%u"), QDate(2004, 12, 31));
 
631
    QCOMPARE(calendar->readDate("2004-W53-6", "%Y-W%V-%u"), QDate(2005, 1, 1));
 
632
    QCOMPARE(calendar->readDate("2004-W53-7", "%Y-W%V-%u"), QDate(2005, 1, 2));
 
633
 
 
634
    calendar->setDateIsoWeek(testDate, currentYear, 46, 5);
 
635
    QCOMPARE(calendar->readDate("W46-5", "W%V-%u"), testDate);
 
636
 
 
637
    QCOMPARE(calendar->readDate("2004-W00-1", "%Y-W%V-%u"),   QDate());
 
638
    QCOMPARE(calendar->readDate("2004-W01-0", "%Y-W%V-%u"),   QDate());
 
639
    QCOMPARE(calendar->readDate("2004-W01-8", "%Y-W%V-%u"),   QDate());
 
640
    QCOMPARE(calendar->readDate("2004-W54-1", "%Y-W%V-%u"),   QDate());
 
641
    QCOMPARE(calendar->readDate("2004-W53-01", "%Y-W%V-%u"),  QDate());
 
642
    QCOMPARE(calendar->readDate("2004-W053-01", "%Y-W%V-%u"), QDate());
623
643
 
624
644
    //Test all 3 options, should go with most accurate
625
 
    QCOMPARE( calendar->readDate( "2004-01-01-365-W52-1", "%Y-%m-%d-%j-W%V-%u" ), QDate( 2004, 1, 1 ) );
626
 
    QCOMPARE( calendar->readDate( "2004-001-W52-1",       "%Y-%j-W%V-%u" ),       QDate( 2004, 1, 1 ) );
 
645
    QCOMPARE(calendar->readDate("2004-01-01-365-W52-1", "%Y-%m-%d-%j-W%V-%u"), QDate(2004, 1, 1));
 
646
    QCOMPARE(calendar->readDate("2004-001-W52-1",       "%Y-%j-W%V-%u"),       QDate(2004, 1, 1));
627
647
 
628
648
    //Test spaces and literals
629
 
    QCOMPARE( calendar->readDate( "2004- 1-1",    "%Y-%m-%d" ), QDate( 2004, 1, 1 ) );
630
 
    QCOMPARE( calendar->readDate( "2004-1-1",     "%Y-%m-%e" ), QDate( 2004, 1, 1 ) );
631
 
    QCOMPARE( calendar->readDate( "2004 01 01",   "%Y %m %d" ), QDate( 2004, 1, 1 ) );
632
 
    QCOMPARE( calendar->readDate( "2004  01  01", "%Y %m %d" ), QDate( 2004, 1, 1 ) );
633
 
    QCOMPARE( calendar->readDate( "2004W01-1",   "%YW%m-%d" ),  QDate( 2004, 1, 1 ) );
634
 
    QCOMPARE( calendar->readDate( "2004w01-1",   "%YW%m-%d" ),  QDate( 2004, 1, 1 ) );
635
 
    QCOMPARE( calendar->readDate( "2004W01-1",   "%Yw%m-%d" ),  QDate( 2004, 1, 1 ) );
 
649
    QCOMPARE(calendar->readDate("2004- 1-1",    "%Y-%m-%d"), QDate(2004, 1, 1));
 
650
    QCOMPARE(calendar->readDate("2004-1-1",     "%Y-%m-%e"), QDate(2004, 1, 1));
 
651
    QCOMPARE(calendar->readDate("2004 01 01",   "%Y %m %d"), QDate(2004, 1, 1));
 
652
    QCOMPARE(calendar->readDate("2004  01  01", "%Y %m %d"), QDate(2004, 1, 1));
 
653
    QCOMPARE(calendar->readDate("2004W01-1",   "%YW%m-%d"),  QDate(2004, 1, 1));
 
654
    QCOMPARE(calendar->readDate("2004w01-1",   "%YW%m-%d"),  QDate(2004, 1, 1));
 
655
    QCOMPARE(calendar->readDate("2004W01-1",   "%Yw%m-%d"),  QDate(2004, 1, 1));
636
656
 
637
657
    //Test enums and non-strict version of readDate()
638
 
    locale->setDateFormat( "%d/%m/%Y" );
639
 
    locale->setDateFormatShort( "%Y/%m/%d" );
640
 
    QCOMPARE( calendar->readDate( "01/02/2004" ),  QDate(  2004, 2, 1 ) ); //KLocale::NormalFormat
641
 
    QCOMPARE( calendar->readDate( "01/02/-2004" ), QDate( -2004, 2, 1 ) ); //KLocale::NormalFormat
642
 
    QCOMPARE( calendar->readDate( "2004/02/01" ),  QDate(  2004, 2, 1 ) ); //KLocale::ShortFormat
643
 
    QCOMPARE( calendar->readDate( "-2004/02/01" ), QDate( -2004, 2, 1 ) ); //KLocale::ShortFormat
644
 
    QCOMPARE( calendar->readDate( "2004-02-01" ),  QDate(  2004, 2, 1 ) ); //KLocale::IsoFormat
645
 
    QCOMPARE( calendar->readDate( "-2004-02-01" ), QDate( -2004, 2, 1 ) ); //KLocale::IsoFormat
646
 
    QCOMPARE( calendar->readDate( "2004-W02-1" ),  QDate(  2004, 1, 5 ) ); //KLocale::IsoWeekFormat
647
 
    QCOMPARE( calendar->readDate( "2004-001" ),    QDate(  2004, 1, 1 ) ); //KLocale::IsoOrdinalFormat
648
 
    QCOMPARE( calendar->readDate( "-2004-001" ),   QDate( -2004, 1, 1 ) ); //KLocale::IsoOrdinalFormat
 
658
    locale->setDateFormat("%d/%m/%Y");
 
659
    locale->setDateFormatShort("%Y/%m/%d");
 
660
    QCOMPARE(calendar->readDate("01/02/2004"),  QDate(2004, 2, 1));        //KLocale::NormalFormat
 
661
    QCOMPARE(calendar->readDate("01/02/-2004"), QDate(-2004, 2, 1));       //KLocale::NormalFormat
 
662
    QCOMPARE(calendar->readDate("2004/02/01"),  QDate(2004, 2, 1));        //KLocale::ShortFormat
 
663
    QCOMPARE(calendar->readDate("-2004/02/01"), QDate(-2004, 2, 1));       //KLocale::ShortFormat
 
664
    QCOMPARE(calendar->readDate("2004-02-01"),  QDate(2004, 2, 1));        //KLocale::IsoFormat
 
665
    QCOMPARE(calendar->readDate("-2004-02-01"), QDate(-2004, 2, 1));       //KLocale::IsoFormat
 
666
    QCOMPARE(calendar->readDate("2004-W02-1"),  QDate(2004, 1, 5));        //KLocale::IsoWeekFormat
 
667
    QCOMPARE(calendar->readDate("2004-001"),    QDate(2004, 1, 1));        //KLocale::IsoOrdinalFormat
 
668
    QCOMPARE(calendar->readDate("-2004-001"),   QDate(-2004, 1, 1));       //KLocale::IsoOrdinalFormat
649
669
 
650
670
    //Test enums and strict version of readDate()
651
 
    QCOMPARE( calendar->readDate( "01/02/2004",   KLocale::NormalFormat ),     QDate(  2004, 2, 1 ) );
652
 
    QCOMPARE( calendar->readDate( "01/02/-2004",  KLocale::NormalFormat ),     QDate( -2004, 2, 1 ) );
653
 
    QCOMPARE( calendar->readDate( "2004/02/01",   KLocale::ShortFormat ),      QDate(  2004, 2, 1 ) );
654
 
    QCOMPARE( calendar->readDate( "-2004/02/01",  KLocale::ShortFormat ),      QDate( -2004, 2, 1 ) );
655
 
    QCOMPARE( calendar->readDate( "2004-02-01",   KLocale::IsoFormat ),        QDate(  2004, 2, 1 ) );
656
 
    QCOMPARE( calendar->readDate( "-2004-02-01",  KLocale::IsoFormat ),        QDate( -2004, 2, 1 ) );
657
 
    QCOMPARE( calendar->readDate( "2004-W02-1",   KLocale::IsoWeekFormat ),    QDate(  2004, 1, 5 ) );
658
 
    QCOMPARE( calendar->readDate( "2004-001",     KLocale::IsoOrdinalFormat ), QDate(  2004, 1, 1 ) );
659
 
    QCOMPARE( calendar->readDate( "-2004-001",    KLocale::IsoOrdinalFormat ), QDate( -2004, 1, 1 ) );
 
671
    QCOMPARE(calendar->readDate("01/02/2004",   KLocale::NormalFormat),     QDate(2004, 2, 1));
 
672
    QCOMPARE(calendar->readDate("01/02/-2004",  KLocale::NormalFormat),     QDate(-2004, 2, 1));
 
673
    QCOMPARE(calendar->readDate("2004/02/01",   KLocale::ShortFormat),      QDate(2004, 2, 1));
 
674
    QCOMPARE(calendar->readDate("-2004/02/01",  KLocale::ShortFormat),      QDate(-2004, 2, 1));
 
675
    QCOMPARE(calendar->readDate("2004-02-01",   KLocale::IsoFormat),        QDate(2004, 2, 1));
 
676
    QCOMPARE(calendar->readDate("-2004-02-01",  KLocale::IsoFormat),        QDate(-2004, 2, 1));
 
677
    QCOMPARE(calendar->readDate("2004-W02-1",   KLocale::IsoWeekFormat),    QDate(2004, 1, 5));
 
678
    QCOMPARE(calendar->readDate("2004-001",     KLocale::IsoOrdinalFormat), QDate(2004, 1, 1));
 
679
    QCOMPARE(calendar->readDate("-2004-001",    KLocale::IsoOrdinalFormat), QDate(-2004, 1, 1));
660
680
 
661
681
    //Test ISO standard date form with no spaces
662
 
    locale->setDateFormatShort( "%Y%m%d" );
663
 
    QCOMPARE( calendar->readDate( "20040201" ),  QDate(  2004, 2, 1 ) );
664
 
    QCOMPARE( calendar->readDate( "-20040201" ), QDate( -2004, 2, 1 ) );
 
682
    locale->setDateFormatShort("%Y%m%d");
 
683
    QCOMPARE(calendar->readDate("20040201"),  QDate(2004, 2, 1));
 
684
    QCOMPARE(calendar->readDate("-20040201"), QDate(-2004, 2, 1));
665
685
 
666
686
    // Test POSIX format
667
 
    testDate.setDate( 2010, 1, 2 );
668
 
    QCOMPARE( calendar->readDate( "2010-1-2", "%Y-%n-%d", 0, KLocale::KdeFormat ),       QDate( 2010, 1, 2 ) );
669
 
    QCOMPARE( calendar->readDate( "2010-\n-2",  "%Y-%n-%d", 0, KLocale::PosixFormat ),   QDate() );
670
 
    QCOMPARE( calendar->readDate( "2010-1\n-2", "%Y-%n\n-%d", 0, KLocale::KdeFormat ),   QDate( 2010, 1, 2 ) );
671
 
    QCOMPARE( calendar->readDate( "2010-1\n-2", "%Y-%m%n-%d", 0, KLocale::PosixFormat ), QDate( 2010, 1, 2 ) );
672
 
    QCOMPARE( calendar->readDate( "2010-1-2", "%Y-%m-%e", 0, KLocale::KdeFormat ),       QDate( 2010, 1, 2 ) );
673
 
    QCOMPARE( calendar->readDate( "2010-1-2", "%Y-%m-%e", 0, KLocale::PosixFormat ),     QDate( 2010, 1, 2 ) );
 
687
    testDate.setDate(2010, 1, 2);
 
688
    QCOMPARE(calendar->readDate("2010-1-2", "%Y-%n-%d", 0, KLocale::KdeFormat),       QDate(2010, 1, 2));
 
689
    QCOMPARE(calendar->readDate("2010-\n-2",  "%Y-%n-%d", 0, KLocale::PosixFormat),   QDate());
 
690
    QCOMPARE(calendar->readDate("2010-1\n-2", "%Y-%n\n-%d", 0, KLocale::KdeFormat),   QDate(2010, 1, 2));
 
691
    QCOMPARE(calendar->readDate("2010-1\n-2", "%Y-%m%n-%d", 0, KLocale::PosixFormat), QDate(2010, 1, 2));
 
692
    QCOMPARE(calendar->readDate("2010-1-2", "%Y-%m-%e", 0, KLocale::KdeFormat),       QDate(2010, 1, 2));
 
693
    QCOMPARE(calendar->readDate("2010-1-2", "%Y-%m-%e", 0, KLocale::PosixFormat),     QDate(2010, 1, 2));
674
694
 
675
695
    delete calendar;
676
696
    delete locale;
678
698
 
679
699
void KCalendarTest::testStringForms()
680
700
{
681
 
    testStrings( KLocale::ArabicDigits );
682
 
    testStrings( KLocale::ArabicIndicDigits );
 
701
    testStrings(KLocale::ArabicDigits);
 
702
    testStrings(KLocale::ArabicIndicDigits);
683
703
}
684
704
 
685
 
void KCalendarTest::testStrings( KLocale::DigitSet testDigitSet )
 
705
void KCalendarTest::testStrings(KLocale::DigitSet testDigitSet)
686
706
{
687
 
    KLocale *locale = new KLocale( *KGlobal::locale() );
688
 
    locale->setDigitSet( testDigitSet );
689
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
 
707
    KLocale *locale = new KLocale(*KGlobal::locale());
 
708
    locale->setDigitSet(testDigitSet);
 
709
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
690
710
 
691
711
    //Test default settings
692
 
    QDate testDate( 2005, 1, 3 );
 
712
    QDate testDate(2005, 1, 3);
693
713
 
694
714
    //Test Year String
695
 
    QCOMPARE( calendar->yearString( testDate ), locale->convertDigits( "2005", locale->dateTimeDigitSet() ) );
696
 
    QCOMPARE( calendar->yearString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "2005", locale->dateTimeDigitSet() ) );
697
 
    QCOMPARE( calendar->yearString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "05", locale->dateTimeDigitSet() ) );
 
715
    QCOMPARE(calendar->yearString(testDate), locale->convertDigits("2005", locale->dateTimeDigitSet()));
 
716
    QCOMPARE(calendar->yearString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("2005", locale->dateTimeDigitSet()));
 
717
    QCOMPARE(calendar->yearString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("05", locale->dateTimeDigitSet()));
698
718
 
699
719
    //Test Month String
700
 
    QCOMPARE( calendar->monthString( testDate ), locale->convertDigits( "01", locale->dateTimeDigitSet() ) );
701
 
    QCOMPARE( calendar->monthString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "01", locale->dateTimeDigitSet() ) );
702
 
    QCOMPARE( calendar->monthString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "1", locale->dateTimeDigitSet() ) );
 
720
    QCOMPARE(calendar->monthString(testDate), locale->convertDigits("01", locale->dateTimeDigitSet()));
 
721
    QCOMPARE(calendar->monthString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("01", locale->dateTimeDigitSet()));
 
722
    QCOMPARE(calendar->monthString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("1", locale->dateTimeDigitSet()));
703
723
 
704
724
    //Test Day String
705
 
    QCOMPARE( calendar->dayString( testDate ), locale->convertDigits( "03", locale->dateTimeDigitSet() ) );
706
 
    QCOMPARE( calendar->dayString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "03", locale->dateTimeDigitSet() ) );
707
 
    QCOMPARE( calendar->dayString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "3", locale->dateTimeDigitSet() ) );
 
725
    QCOMPARE(calendar->dayString(testDate), locale->convertDigits("03", locale->dateTimeDigitSet()));
 
726
    QCOMPARE(calendar->dayString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("03", locale->dateTimeDigitSet()));
 
727
    QCOMPARE(calendar->dayString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("3", locale->dateTimeDigitSet()));
708
728
 
709
729
    //Test Day of Year String
710
 
    QCOMPARE( calendar->dayOfYearString( testDate ), locale->convertDigits( "003", locale->dateTimeDigitSet() ) );
711
 
    QCOMPARE( calendar->dayOfYearString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "003", locale->dateTimeDigitSet() ) );
712
 
    QCOMPARE( calendar->dayOfYearString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "3", locale->dateTimeDigitSet() ) );
 
730
    QCOMPARE(calendar->dayOfYearString(testDate), locale->convertDigits("003", locale->dateTimeDigitSet()));
 
731
    QCOMPARE(calendar->dayOfYearString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("003", locale->dateTimeDigitSet()));
 
732
    QCOMPARE(calendar->dayOfYearString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("3", locale->dateTimeDigitSet()));
713
733
 
714
734
    //Test Day of Week String
715
 
    QCOMPARE( calendar->dayOfWeekString( testDate ), locale->convertDigits( "1", locale->dateTimeDigitSet() ) );
 
735
    QCOMPARE(calendar->dayOfWeekString(testDate), locale->convertDigits("1", locale->dateTimeDigitSet()));
716
736
 
717
737
    //Test Week Number String
718
 
    QCOMPARE( calendar->weekNumberString( testDate ), locale->convertDigits( "01", locale->dateTimeDigitSet() ) );
719
 
    QCOMPARE( calendar->weekNumberString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "01", locale->dateTimeDigitSet() ) );
720
 
    QCOMPARE( calendar->weekNumberString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "1", locale->dateTimeDigitSet() ) );
 
738
    QCOMPARE(calendar->weekNumberString(testDate), locale->convertDigits("01", locale->dateTimeDigitSet()));
 
739
    QCOMPARE(calendar->weekNumberString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("01", locale->dateTimeDigitSet()));
 
740
    QCOMPARE(calendar->weekNumberString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("1", locale->dateTimeDigitSet()));
721
741
 
722
742
    //Test Months In Year String
723
 
    QCOMPARE( calendar->monthsInYearString( testDate ), locale->convertDigits( "12", locale->dateTimeDigitSet() ) );
724
 
    QCOMPARE( calendar->monthsInYearString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "12", locale->dateTimeDigitSet() ) );
725
 
    QCOMPARE( calendar->monthsInYearString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "12", locale->dateTimeDigitSet() ) );
 
743
    QCOMPARE(calendar->monthsInYearString(testDate), locale->convertDigits("12", locale->dateTimeDigitSet()));
 
744
    QCOMPARE(calendar->monthsInYearString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("12", locale->dateTimeDigitSet()));
 
745
    QCOMPARE(calendar->monthsInYearString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("12", locale->dateTimeDigitSet()));
726
746
 
727
747
    //Test Weeks In Year String
728
 
    QCOMPARE( calendar->weeksInYearString( testDate ), locale->convertDigits( "52", locale->dateTimeDigitSet() ) );
729
 
    QCOMPARE( calendar->weeksInYearString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "52", locale->dateTimeDigitSet() ) );
730
 
    QCOMPARE( calendar->weeksInYearString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "52", locale->dateTimeDigitSet() ) );
 
748
    QCOMPARE(calendar->weeksInYearString(testDate), locale->convertDigits("52", locale->dateTimeDigitSet()));
 
749
    QCOMPARE(calendar->weeksInYearString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("52", locale->dateTimeDigitSet()));
 
750
    QCOMPARE(calendar->weeksInYearString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("52", locale->dateTimeDigitSet()));
731
751
 
732
752
    //Test Days In Year String
733
 
    QCOMPARE( calendar->daysInYearString( testDate ), locale->convertDigits( "365", locale->dateTimeDigitSet() ) );
734
 
    QCOMPARE( calendar->daysInYearString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "365", locale->dateTimeDigitSet() ) );
735
 
    QCOMPARE( calendar->daysInYearString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "365", locale->dateTimeDigitSet() ) );
 
753
    QCOMPARE(calendar->daysInYearString(testDate), locale->convertDigits("365", locale->dateTimeDigitSet()));
 
754
    QCOMPARE(calendar->daysInYearString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("365", locale->dateTimeDigitSet()));
 
755
    QCOMPARE(calendar->daysInYearString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("365", locale->dateTimeDigitSet()));
736
756
 
737
757
    //Test Days In Month String
738
 
    QCOMPARE( calendar->daysInMonthString( testDate ), locale->convertDigits( "31", locale->dateTimeDigitSet() ) );
739
 
    QCOMPARE( calendar->daysInMonthString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "31", locale->dateTimeDigitSet() ) );
740
 
    QCOMPARE( calendar->daysInMonthString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "31", locale->dateTimeDigitSet() ) );
 
758
    QCOMPARE(calendar->daysInMonthString(testDate), locale->convertDigits("31", locale->dateTimeDigitSet()));
 
759
    QCOMPARE(calendar->daysInMonthString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("31", locale->dateTimeDigitSet()));
 
760
    QCOMPARE(calendar->daysInMonthString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("31", locale->dateTimeDigitSet()));
741
761
 
742
762
    //Test Days In Week String
743
 
    QCOMPARE( calendar->daysInWeekString( testDate ), locale->convertDigits( "7", locale->dateTimeDigitSet() ) );
 
763
    QCOMPARE(calendar->daysInWeekString(testDate), locale->convertDigits("7", locale->dateTimeDigitSet()));
744
764
 
745
765
    //Test Year In Era String
746
 
    testDate.setDate( 5, 1, 1 );
747
 
    QCOMPARE( calendar->yearInEraString( testDate ), locale->convertDigits( "5", locale->dateTimeDigitSet() ) );
748
 
    QCOMPARE( calendar->yearInEraString( testDate, KCalendarSystem::LongFormat ), locale->convertDigits( "0005", locale->dateTimeDigitSet() ) );
749
 
    QCOMPARE( calendar->yearInEraString( testDate, KCalendarSystem::ShortFormat ), locale->convertDigits( "5", locale->dateTimeDigitSet() ) );
 
766
    testDate.setDate(5, 1, 1);
 
767
    QCOMPARE(calendar->yearInEraString(testDate), locale->convertDigits("5", locale->dateTimeDigitSet()));
 
768
    QCOMPARE(calendar->yearInEraString(testDate, KCalendarSystem::LongFormat), locale->convertDigits("0005", locale->dateTimeDigitSet()));
 
769
    QCOMPARE(calendar->yearInEraString(testDate, KCalendarSystem::ShortFormat), locale->convertDigits("5", locale->dateTimeDigitSet()));
750
770
 
751
771
    delete calendar;
752
772
    delete locale;
754
774
 
755
775
void KCalendarTest::testIsoWeekDate()
756
776
{
757
 
    KLocale *locale = new KLocale( *KGlobal::locale() );
758
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
759
 
 
760
 
    int earliestValidYear = calendar->year( calendar->earliestValidDate() );
761
 
    int latestValidYear = calendar->year( calendar->latestValidDate() );
762
 
 
763
 
    QCOMPARE( calendar->isValidIsoWeekDate( earliestValidYear - 1, 1, 1 ), false );
764
 
    QCOMPARE( calendar->isValidIsoWeekDate( earliestValidYear,     1, 1 ), false ); //In prev year
765
 
    QCOMPARE( calendar->isValidIsoWeekDate( earliestValidYear,     1, 2 ), false ); //In prev year
766
 
    QCOMPARE( calendar->isValidIsoWeekDate( earliestValidYear,     1, 3 ), true );
767
 
    QCOMPARE( calendar->isValidIsoWeekDate( -1,                    1, 1 ), true );
768
 
    QCOMPARE( calendar->isValidIsoWeekDate( 0,                     1, 1 ), false );
769
 
    QCOMPARE( calendar->isValidIsoWeekDate( 1,                     1, 1 ), true );
770
 
    QCOMPARE( calendar->isValidIsoWeekDate( latestValidYear,      52, 5 ), true );
771
 
    QCOMPARE( calendar->isValidIsoWeekDate( latestValidYear,      52, 6 ), false ); //In following year
772
 
    QCOMPARE( calendar->isValidIsoWeekDate( latestValidYear,      52, 7 ), false ); //In following year
773
 
    QCOMPARE( calendar->isValidIsoWeekDate( latestValidYear + 1,   1, 1 ), false );
774
 
 
775
 
    QCOMPARE( calendar->isValidIsoWeekDate( 2004,  0, 1 ), false );
776
 
    QCOMPARE( calendar->isValidIsoWeekDate( 2004,  1, 1 ), true );
777
 
    QCOMPARE( calendar->isValidIsoWeekDate( 2004, 53, 1 ), true );
778
 
    QCOMPARE( calendar->isValidIsoWeekDate( 2000, 54, 1 ), false );
779
 
 
780
 
    QCOMPARE( calendar->isValidIsoWeekDate( 2004, 1, 0 ), false );
781
 
    QCOMPARE( calendar->isValidIsoWeekDate( 2004, 1, 1 ), true );
782
 
    QCOMPARE( calendar->isValidIsoWeekDate( 2004, 1, 7 ), true );
783
 
    QCOMPARE( calendar->isValidIsoWeekDate( 2004, 1, 8 ), false );
784
 
 
785
 
    QCOMPARE( setIsoWeekDate( calendar, earliestValidYear - 1, 1, 1 ), QDate() );
786
 
    QCOMPARE( setIsoWeekDate( calendar, earliestValidYear,     1, 1 ), QDate() ); //In prev year
787
 
    QCOMPARE( setIsoWeekDate( calendar, earliestValidYear,     1, 2 ), QDate() ); //In prev year
788
 
    QCOMPARE( setIsoWeekDate( calendar, earliestValidYear,     1, 3 ), QDate( -4712,  1,  1 ) );
789
 
    QCOMPARE( setIsoWeekDate( calendar, -1,                    1, 1 ), QDate(    -2, 12, 29 ) );
790
 
    QCOMPARE( setIsoWeekDate( calendar, 0,                     1, 1 ), QDate() );
791
 
    QCOMPARE( setIsoWeekDate( calendar, 1,                     1, 1 ), QDate(     1,  1,  3 ) );
792
 
    QCOMPARE( setIsoWeekDate( calendar, latestValidYear,      52, 5 ), QDate(  9999, 12, 31 ) );
793
 
    QCOMPARE( setIsoWeekDate( calendar, latestValidYear,      52, 6 ), QDate() ); //In next year
794
 
    QCOMPARE( setIsoWeekDate( calendar, latestValidYear,      52, 7 ), QDate() ); //In next year
795
 
    QCOMPARE( setIsoWeekDate( calendar, latestValidYear + 1,   1, 1 ), QDate() );
796
 
 
797
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  0, 1 ), QDate() );
798
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 1 ), QDate( 2003, 12, 29 ) );
799
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 53, 1 ), QDate( 2004, 12, 27 ) );
800
 
    QCOMPARE( setIsoWeekDate( calendar, 2000, 54, 1 ), QDate() );
801
 
 
802
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 0 ), QDate() );
803
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 1 ), QDate( 2003, 12, 29 ) );
804
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 7 ), QDate( 2004,  1,  4 ) );
805
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 8 ), QDate() );
806
 
 
807
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 1 ), QDate( 2003, 12, 29 ) );
808
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 2 ), QDate( 2003, 12, 30 ) );
809
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 3 ), QDate( 2003, 12, 31 ) );
810
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 4 ), QDate( 2004,  1,  1 ) );
811
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 5 ), QDate( 2004,  1,  2 ) );
812
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 6 ), QDate( 2004,  1,  3 ) );
813
 
    QCOMPARE( setIsoWeekDate( calendar, 2004,  1, 7 ), QDate( 2004,  1,  4 ) );
814
 
 
815
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 24, 1 ), QDate( 2004, 6,  7 ) );
816
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 24, 2 ), QDate( 2004, 6,  8 ) );
817
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 24, 3 ), QDate( 2004, 6,  9 ) );
818
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 24, 4 ), QDate( 2004, 6, 10 ) );
819
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 24, 5 ), QDate( 2004, 6, 11 ) );
820
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 24, 6 ), QDate( 2004, 6, 12 ) );
821
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 24, 7 ), QDate( 2004, 6, 13 ) );
822
 
 
823
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 53, 1 ), QDate( 2004, 12, 27 ) );
824
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 53, 2 ), QDate( 2004, 12, 28 ) );
825
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 53, 3 ), QDate( 2004, 12, 29 ) );
826
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 53, 4 ), QDate( 2004, 12, 30 ) );
827
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 53, 5 ), QDate( 2004, 12, 31 ) );
828
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 53, 6 ), QDate( 2005,  1,  1 ) );
829
 
    QCOMPARE( setIsoWeekDate( calendar, 2004, 53, 7 ), QDate( 2005,  1,  2 ) );
 
777
    KLocale *locale = new KLocale(*KGlobal::locale());
 
778
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
 
779
 
 
780
    int earliestValidYear = calendar->year(calendar->earliestValidDate());
 
781
    int latestValidYear = calendar->year(calendar->latestValidDate());
 
782
 
 
783
    QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear - 1, 1, 1), false);
 
784
    QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear,     1, 1), false);     //In prev year
 
785
    QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear,     1, 2), false);     //In prev year
 
786
    QCOMPARE(calendar->isValidIsoWeekDate(earliestValidYear,     1, 3), true);
 
787
    QCOMPARE(calendar->isValidIsoWeekDate(-1,                    1, 1), true);
 
788
    QCOMPARE(calendar->isValidIsoWeekDate(0,                     1, 1), false);
 
789
    QCOMPARE(calendar->isValidIsoWeekDate(1,                     1, 1), true);
 
790
    QCOMPARE(calendar->isValidIsoWeekDate(latestValidYear,      52, 5), true);
 
791
    QCOMPARE(calendar->isValidIsoWeekDate(latestValidYear,      52, 6), false);     //In following year
 
792
    QCOMPARE(calendar->isValidIsoWeekDate(latestValidYear,      52, 7), false);     //In following year
 
793
    QCOMPARE(calendar->isValidIsoWeekDate(latestValidYear + 1,   1, 1), false);
 
794
 
 
795
    QCOMPARE(calendar->isValidIsoWeekDate(2004,  0, 1), false);
 
796
    QCOMPARE(calendar->isValidIsoWeekDate(2004,  1, 1), true);
 
797
    QCOMPARE(calendar->isValidIsoWeekDate(2004, 53, 1), true);
 
798
    QCOMPARE(calendar->isValidIsoWeekDate(2000, 54, 1), false);
 
799
 
 
800
    QCOMPARE(calendar->isValidIsoWeekDate(2004, 1, 0), false);
 
801
    QCOMPARE(calendar->isValidIsoWeekDate(2004, 1, 1), true);
 
802
    QCOMPARE(calendar->isValidIsoWeekDate(2004, 1, 7), true);
 
803
    QCOMPARE(calendar->isValidIsoWeekDate(2004, 1, 8), false);
 
804
 
 
805
    QCOMPARE(setIsoWeekDate(calendar, earliestValidYear - 1, 1, 1), QDate());
 
806
    QCOMPARE(setIsoWeekDate(calendar, earliestValidYear,     1, 1), QDate());     //In prev year
 
807
    QCOMPARE(setIsoWeekDate(calendar, earliestValidYear,     1, 2), QDate());     //In prev year
 
808
    QCOMPARE(setIsoWeekDate(calendar, earliestValidYear,     1, 3), QDate(-4712,  1,  1));
 
809
    QCOMPARE(setIsoWeekDate(calendar, -1,                    1, 1), QDate(-2, 12, 29));
 
810
    QCOMPARE(setIsoWeekDate(calendar, 0,                     1, 1), QDate());
 
811
    QCOMPARE(setIsoWeekDate(calendar, 1,                     1, 1), QDate(1,  1,  3));
 
812
    QCOMPARE(setIsoWeekDate(calendar, latestValidYear,      52, 5), QDate(9999, 12, 31));
 
813
    QCOMPARE(setIsoWeekDate(calendar, latestValidYear,      52, 6), QDate());     //In next year
 
814
    QCOMPARE(setIsoWeekDate(calendar, latestValidYear,      52, 7), QDate());     //In next year
 
815
    QCOMPARE(setIsoWeekDate(calendar, latestValidYear + 1,   1, 1), QDate());
 
816
 
 
817
    QCOMPARE(setIsoWeekDate(calendar, 2004,  0, 1), QDate());
 
818
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 1), QDate(2003, 12, 29));
 
819
    QCOMPARE(setIsoWeekDate(calendar, 2004, 53, 1), QDate(2004, 12, 27));
 
820
    QCOMPARE(setIsoWeekDate(calendar, 2000, 54, 1), QDate());
 
821
 
 
822
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 0), QDate());
 
823
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 1), QDate(2003, 12, 29));
 
824
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 7), QDate(2004,  1,  4));
 
825
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 8), QDate());
 
826
 
 
827
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 1), QDate(2003, 12, 29));
 
828
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 2), QDate(2003, 12, 30));
 
829
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 3), QDate(2003, 12, 31));
 
830
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 4), QDate(2004,  1,  1));
 
831
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 5), QDate(2004,  1,  2));
 
832
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 6), QDate(2004,  1,  3));
 
833
    QCOMPARE(setIsoWeekDate(calendar, 2004,  1, 7), QDate(2004,  1,  4));
 
834
 
 
835
    QCOMPARE(setIsoWeekDate(calendar, 2004, 24, 1), QDate(2004, 6,  7));
 
836
    QCOMPARE(setIsoWeekDate(calendar, 2004, 24, 2), QDate(2004, 6,  8));
 
837
    QCOMPARE(setIsoWeekDate(calendar, 2004, 24, 3), QDate(2004, 6,  9));
 
838
    QCOMPARE(setIsoWeekDate(calendar, 2004, 24, 4), QDate(2004, 6, 10));
 
839
    QCOMPARE(setIsoWeekDate(calendar, 2004, 24, 5), QDate(2004, 6, 11));
 
840
    QCOMPARE(setIsoWeekDate(calendar, 2004, 24, 6), QDate(2004, 6, 12));
 
841
    QCOMPARE(setIsoWeekDate(calendar, 2004, 24, 7), QDate(2004, 6, 13));
 
842
 
 
843
    QCOMPARE(setIsoWeekDate(calendar, 2004, 53, 1), QDate(2004, 12, 27));
 
844
    QCOMPARE(setIsoWeekDate(calendar, 2004, 53, 2), QDate(2004, 12, 28));
 
845
    QCOMPARE(setIsoWeekDate(calendar, 2004, 53, 3), QDate(2004, 12, 29));
 
846
    QCOMPARE(setIsoWeekDate(calendar, 2004, 53, 4), QDate(2004, 12, 30));
 
847
    QCOMPARE(setIsoWeekDate(calendar, 2004, 53, 5), QDate(2004, 12, 31));
 
848
    QCOMPARE(setIsoWeekDate(calendar, 2004, 53, 6), QDate(2005,  1,  1));
 
849
    QCOMPARE(setIsoWeekDate(calendar, 2004, 53, 7), QDate(2005,  1,  2));
830
850
 
831
851
    delete calendar;
832
852
    delete locale;
834
854
 
835
855
void KCalendarTest::testHebrewStrings()
836
856
{
837
 
/*
838
 
    Ref table for numbers to Hebrew chars
839
 
 
840
 
    Value     1       2       3        4        5       6         7        8      9
841
 
 
842
 
    x 1    Alef �0�2  Bet  �0�3  Gimel �0�4  Dalet �0�5  He   �0�6  Vav  �0�7    Zayen �0�8  Het  �0�9  Tet  �0�0
843
 
           0x05D0  0x05D1  0x05D2   0x05D3   0x05D4  0x05D5    0x05D6   0x05D7  0x05D8
844
 
 
845
 
    x 10   Yod  �0�1  Kaf  �0�3  Lamed �0�4  Mem  �0�6   Nun  �0�8  Samekh �0�9  Ayin �0�0   Pe   �0�2  Tzadi �0�4
846
 
           0x05D9  0x05DB  0x05DC   0x05DE   0x05E0  0x05E1    0x05E2   0x05E4  0x05E6
847
 
 
848
 
    x 100  Qof  �0�5  Resh �0�6  Shin �0�7   Tav  �0�8
849
 
           0x05E7  0x05E8  0x05E9   0x05EA
850
 
 
851
 
    Note special cases 15 = 9 + 6 �0�0�0�7 and 16 = 9 + 7 �0�0�0�8
852
 
*/
 
857
    /*
 
858
        Ref table for numbers to Hebrew chars
 
859
 
 
860
        Value     1       2       3        4        5       6         7        8      9
 
861
 
 
862
        x 1    Alef �0�2  Bet  �0�3  Gimel �0�4  Dalet �0�5  He   �0�6  Vav  �0�7    Zayen �0�8  Het  �0�9  Tet  �0�0
 
863
               0x05D0  0x05D1  0x05D2   0x05D3   0x05D4  0x05D5    0x05D6   0x05D7  0x05D8
 
864
 
 
865
        x 10   Yod  �0�1  Kaf  �0�3  Lamed �0�4  Mem  �0�6   Nun  �0�8  Samekh �0�9  Ayin �0�0   Pe   �0�2  Tzadi �0�4
 
866
               0x05D9  0x05DB  0x05DC   0x05DE   0x05E0  0x05E1    0x05E2   0x05E4  0x05E6
 
867
 
 
868
        x 100  Qof  �0�5  Resh �0�6  Shin �0�7   Tav  �0�8
 
869
               0x05E7  0x05E8  0x05E9   0x05EA
 
870
 
 
871
        Note special cases 15 = 9 + 6 �0�0�0�7 and 16 = 9 + 7 �0�0�0�8
 
872
    */
853
873
 
854
874
    QString oldLocale = setlocale(LC_ALL, "he.utf8");
855
 
    KLocale *locale = new KLocale( *KGlobal::locale() );
 
875
    KLocale *locale = new KLocale(*KGlobal::locale());
856
876
    locale->setLanguage(QStringList() << "he");
857
877
    locale->insertCatalog("kdecalendarsystems");
858
 
    locale->setDateFormat( "%d %B %Y" );
859
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::HebrewCalendar, locale );
860
 
    if ( locale->language() == "he" ) {
 
878
    locale->setDateFormat("%d %B %Y");
 
879
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::HebrewCalendar, locale);
 
880
    if (locale->language() == "he") {
861
881
        QDate testDate;
862
882
        QString yearString, monthString, dayString, testString, resultString;
863
 
        calendar->setDate( testDate, 5765, 1, 1 );
 
883
        calendar->setDate(testDate, 5765, 1, 1);
864
884
        // Have to use unicode values, for some reason directly using the chars doesn't work?
865
 
        yearString.append( QChar(0x05EA) ).append( QChar(0x05E9) ).append( QChar(0x05E1) ).append( QChar('\"') ).append( QChar(0x05D4) );
 
885
        yearString.append(QChar(0x05EA)).append(QChar(0x05E9)).append(QChar(0x05E1)).append(QChar('\"')).append(QChar(0x05D4));
866
886
        monthString = "�0�8�0�7�0�6�0�1";
867
 
        dayString.append( QChar(0x05D0) ).append( QChar('\'') );
 
887
        dayString.append(QChar(0x05D0)).append(QChar('\''));
868
888
        testString = yearString + ' ' + monthString + ' ' + dayString;
869
 
        QCOMPARE( calendar->readDate( calendar->formatDate( testDate, KLocale::LongDate ), KLocale::NormalFormat ), testDate );
870
 
        QCOMPARE( calendar->formatDate( testDate, "%Y" ), yearString );
 
889
        QCOMPARE(calendar->readDate(calendar->formatDate(testDate, KLocale::LongDate), KLocale::NormalFormat), testDate);
 
890
        QCOMPARE(calendar->formatDate(testDate, "%Y"), yearString);
871
891
        // Skip month name for now as won't translate for some reason, confirmed works visually in GUI
872
892
        //QCOMPARE( calendar->formatDate( testDate, "%B" ), monthString );
873
 
        QCOMPARE( calendar->formatDate( testDate, "%d" ), dayString );
 
893
        QCOMPARE(calendar->formatDate(testDate, "%d"), dayString);
874
894
        //QCOMPARE( calendar->formatDate( testDate,  locale->dateFormat() ), testString );
875
895
        //QCOMPARE( calendar->readDate( testString ), testDate );
876
 
        for ( int yy = 5400; yy <= 6400; ++yy ) {
877
 
            calendar->setDate( testDate, yy, 1, 1 );
878
 
            QCOMPARE( calendar->readDate( calendar->formatDate( testDate, KLocale::LongDate ), KLocale::NormalFormat ), testDate );
 
896
        for (int yy = 5400; yy <= 6400; ++yy) {
 
897
            calendar->setDate(testDate, yy, 1, 1);
 
898
            QCOMPARE(calendar->readDate(calendar->formatDate(testDate, KLocale::LongDate), KLocale::NormalFormat), testDate);
879
899
        }
880
900
    } else {
881
901
        kDebug() << "Cannot set Hebrew language, please install and re-test!";
882
902
    }
883
 
    setlocale( LC_ALL, oldLocale.toLatin1() );
 
903
    setlocale(LC_ALL, oldLocale.toLatin1());
884
904
}
885
905
 
886
 
QDate KCalendarTest::setIsoWeekDate( const KCalendarSystem * calendar, int year, int isoWeek, int dayOfWeek )
 
906
QDate KCalendarTest::setIsoWeekDate(const KCalendarSystem * calendar, int year, int isoWeek, int dayOfWeek)
887
907
{
888
908
    QDate resultDate;
889
 
    calendar->setDateIsoWeek( resultDate, year, isoWeek, dayOfWeek );
 
909
    calendar->setDateIsoWeek(resultDate, year, isoWeek, dayOfWeek);
890
910
    return resultDate;
891
911
}
892
912
 
893
913
void KCalendarTest::testDayOfYearDate()
894
914
{
895
 
    KLocale *locale = new KLocale( *KGlobal::locale() );
896
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
897
 
 
898
 
    int earliestValidYear = calendar->year( calendar->earliestValidDate() );
899
 
    int latestValidYear = calendar->year( calendar->latestValidDate() );
900
 
 
901
 
    QCOMPARE( calendar->isValid( earliestValidYear - 1, 1 ), false );
902
 
    QCOMPARE( calendar->isValid( earliestValidYear,     1 ), true );
903
 
    QCOMPARE( calendar->isValid( -1,                    1 ), true );
904
 
    QCOMPARE( calendar->isValid( 0,                     1 ), false );
905
 
    QCOMPARE( calendar->isValid( 1,                     1 ), true );
906
 
    QCOMPARE( calendar->isValid( latestValidYear,       1 ), true );
907
 
    QCOMPARE( calendar->isValid( latestValidYear + 1,   1 ), false );
908
 
 
909
 
    QCOMPARE( calendar->isValid( 2005,   0 ), false );
910
 
    QCOMPARE( calendar->isValid( 2005,   1 ), true );
911
 
    QCOMPARE( calendar->isValid( 2005, 365 ), true );
912
 
    QCOMPARE( calendar->isValid( 2005, 366 ), false );
913
 
    QCOMPARE( calendar->isValid( 2000, 366 ), true );
914
 
    QCOMPARE( calendar->isValid( 2000, 367 ), false );
915
 
 
916
 
    QCOMPARE( setDayOfYearDate( calendar, earliestValidYear - 1, 1 ), QDate() );
917
 
    QCOMPARE( setDayOfYearDate( calendar, earliestValidYear,     1 ), QDate( earliestValidYear, 1, 1 ) );
918
 
    QCOMPARE( setDayOfYearDate( calendar, -1,                    1 ), QDate( -1,                1, 1 ) );
919
 
    QCOMPARE( setDayOfYearDate( calendar, 0,                     1 ), QDate() );
920
 
    QCOMPARE( setDayOfYearDate( calendar, 1,                     1 ), QDate( 1,                 1, 1 ) );
921
 
    QCOMPARE( setDayOfYearDate( calendar, latestValidYear,       1 ), QDate( latestValidYear,   1, 1 ) );
922
 
    QCOMPARE( setDayOfYearDate( calendar, latestValidYear + 1,   1 ), QDate() );
923
 
 
924
 
    QCOMPARE( setDayOfYearDate( calendar, 2005,   0 ), QDate() );
925
 
    QCOMPARE( setDayOfYearDate( calendar, 2005,   1 ), QDate( 2005,  1,  1 ) );
926
 
    QCOMPARE( setDayOfYearDate( calendar, 2005, 365 ), QDate( 2005, 12, 31 ) );
927
 
    QCOMPARE( setDayOfYearDate( calendar, 2005, 366 ), QDate() );
928
 
    QCOMPARE( setDayOfYearDate( calendar, 2000, 366 ), QDate( 2000, 12, 31 ) );
929
 
    QCOMPARE( setDayOfYearDate( calendar, 2000, 367 ), QDate() );
 
915
    KLocale *locale = new KLocale(*KGlobal::locale());
 
916
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
 
917
 
 
918
    int earliestValidYear = calendar->year(calendar->earliestValidDate());
 
919
    int latestValidYear = calendar->year(calendar->latestValidDate());
 
920
 
 
921
    QCOMPARE(calendar->isValid(earliestValidYear - 1, 1), false);
 
922
    QCOMPARE(calendar->isValid(earliestValidYear,     1), true);
 
923
    QCOMPARE(calendar->isValid(-1,                    1), true);
 
924
    QCOMPARE(calendar->isValid(0,                     1), false);
 
925
    QCOMPARE(calendar->isValid(1,                     1), true);
 
926
    QCOMPARE(calendar->isValid(latestValidYear,       1), true);
 
927
    QCOMPARE(calendar->isValid(latestValidYear + 1,   1), false);
 
928
 
 
929
    QCOMPARE(calendar->isValid(2005,   0), false);
 
930
    QCOMPARE(calendar->isValid(2005,   1), true);
 
931
    QCOMPARE(calendar->isValid(2005, 365), true);
 
932
    QCOMPARE(calendar->isValid(2005, 366), false);
 
933
    QCOMPARE(calendar->isValid(2000, 366), true);
 
934
    QCOMPARE(calendar->isValid(2000, 367), false);
 
935
 
 
936
    QCOMPARE(setDayOfYearDate(calendar, earliestValidYear - 1, 1), QDate());
 
937
    QCOMPARE(setDayOfYearDate(calendar, earliestValidYear,     1), QDate(earliestValidYear, 1, 1));
 
938
    QCOMPARE(setDayOfYearDate(calendar, -1,                    1), QDate(-1,                1, 1));
 
939
    QCOMPARE(setDayOfYearDate(calendar, 0,                     1), QDate());
 
940
    QCOMPARE(setDayOfYearDate(calendar, 1,                     1), QDate(1,                 1, 1));
 
941
    QCOMPARE(setDayOfYearDate(calendar, latestValidYear,       1), QDate(latestValidYear,   1, 1));
 
942
    QCOMPARE(setDayOfYearDate(calendar, latestValidYear + 1,   1), QDate());
 
943
 
 
944
    QCOMPARE(setDayOfYearDate(calendar, 2005,   0), QDate());
 
945
    QCOMPARE(setDayOfYearDate(calendar, 2005,   1), QDate(2005,  1,  1));
 
946
    QCOMPARE(setDayOfYearDate(calendar, 2005, 365), QDate(2005, 12, 31));
 
947
    QCOMPARE(setDayOfYearDate(calendar, 2005, 366), QDate());
 
948
    QCOMPARE(setDayOfYearDate(calendar, 2000, 366), QDate(2000, 12, 31));
 
949
    QCOMPARE(setDayOfYearDate(calendar, 2000, 367), QDate());
930
950
 
931
951
    delete calendar;
932
952
    delete locale;
933
953
}
934
954
 
935
 
QDate KCalendarTest::setDayOfYearDate( const KCalendarSystem * calendar, int year, int dayOfYear )
 
955
QDate KCalendarTest::setDayOfYearDate(const KCalendarSystem * calendar, int year, int dayOfYear)
936
956
{
937
957
    QDate resultDate;
938
 
    calendar->setDate( resultDate, year, dayOfYear );
 
958
    calendar->setDate(resultDate, year, dayOfYear);
939
959
    return resultDate;
940
960
}
941
961
 
942
962
void KCalendarTest::testDateDifference()
943
963
{
944
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
 
964
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
945
965
    QDate testDate1, testDate2;
946
966
 
947
967
    // Date Difference
948
968
 
949
 
    compareDateDifference( calendar, QDate( 2010, 6,  1 ), QDate( 2010, 6,  1 ),  0,  0,  0 );
950
 
    compareDateDifference( calendar, QDate( 2010, 6, 10 ), QDate( 2010, 6, 20 ),  0,  0, 10 );
951
 
    compareDateDifference( calendar, QDate( 2010, 6,  1 ), QDate( 2010, 7,  1 ),  0,  1,  0 );
952
 
    compareDateDifference( calendar, QDate( 2010, 6, 10 ), QDate( 2010, 7, 20 ),  0,  1, 10 );
953
 
    compareDateDifference( calendar, QDate( 2010, 6, 20 ), QDate( 2010, 7, 10 ),  0,  0, 20 );
954
 
    compareDateDifference( calendar, QDate( 2010, 6, 30 ), QDate( 2010, 7, 31 ),  0,  1,  1 );
955
 
    compareDateDifference( calendar, QDate( 2010, 8, 31 ), QDate( 2010, 9, 30 ),  0,  1,  0 );
956
 
    compareDateDifference( calendar, QDate( 2010, 7,  1 ), QDate( 2011, 6,  1 ),  0, 11,  0 );
957
 
    compareDateDifference( calendar, QDate( 2010, 7, 10 ), QDate( 2011, 6, 20 ),  0, 11, 10 );
958
 
    compareDateDifference( calendar, QDate( 2010, 7, 20 ), QDate( 2011, 6, 10 ),  0, 10, 21 );
959
 
    compareDateDifference( calendar, QDate( 2010, 7, 31 ), QDate( 2011, 6, 30 ),  0, 11,  0 );
960
 
    compareDateDifference( calendar, QDate( 2010, 8, 30 ), QDate( 2011, 7, 31 ),  0, 11,  1 );
961
 
    compareDateDifference( calendar, QDate( 2010, 6, 10 ), QDate( 2011, 6, 10 ),  1,  0,  0 );
962
 
    compareDateDifference( calendar, QDate( 2010, 6, 10 ), QDate( 2011, 6, 20 ),  1,  0, 10 );
963
 
    compareDateDifference( calendar, QDate( 2010, 6, 10 ), QDate( 2011, 7, 10 ),  1,  1,  0 );
964
 
    compareDateDifference( calendar, QDate( 2010, 6, 10 ), QDate( 2011, 7, 20 ),  1,  1, 10 );
965
 
    compareDateDifference( calendar, QDate( 2010, 6, 20 ), QDate( 2011, 8, 10 ),  1,  1, 21 );
966
 
    compareDateDifference( calendar, QDate( 2010, 6, 30 ), QDate( 2011, 7, 31 ),  1,  1,  1 );
967
 
    compareDateDifference( calendar, QDate( 2010, 8, 31 ), QDate( 2011, 9, 30 ),  1,  1,  0 );
968
 
    compareDateDifference( calendar, QDate( 2010, 7, 31 ), QDate( 2012, 6, 30 ),  1, 11,  0 );
969
 
    compareDateDifference( calendar, QDate( 2010, 8, 30 ), QDate( 2012, 7, 31 ),  1, 11,  1 );
970
 
    compareDateDifference( calendar, QDate( 2000, 2, 29 ), QDate( 2001, 2, 28 ),  1,  0,  0 );
971
 
    compareDateDifference( calendar, QDate( 2000, 2, 29 ), QDate( 2001, 3,  1 ),  1,  0,  1 );
972
 
    compareDateDifference( calendar, QDate( 2000, 2, 29 ), QDate( 2001, 4,  1 ),  1,  1,  3 );
973
 
    calendar->setDate( testDate1, -1, 1, 1 );
974
 
    calendar->setDate( testDate2,  1, 1, 1 );
975
 
    compareDateDifference( calendar, testDate1, testDate2,  1,  0,  0 );
 
969
    compareDateDifference(calendar, QDate(2010, 6,  1), QDate(2010, 6,  1),  0,  0,  0);
 
970
    compareDateDifference(calendar, QDate(2010, 6, 10), QDate(2010, 6, 20),  0,  0, 10);
 
971
    compareDateDifference(calendar, QDate(2010, 6,  1), QDate(2010, 7,  1),  0,  1,  0);
 
972
    compareDateDifference(calendar, QDate(2010, 6, 10), QDate(2010, 7, 20),  0,  1, 10);
 
973
    compareDateDifference(calendar, QDate(2010, 6, 20), QDate(2010, 7, 10),  0,  0, 20);
 
974
    compareDateDifference(calendar, QDate(2010, 6, 30), QDate(2010, 7, 31),  0,  1,  1);
 
975
    compareDateDifference(calendar, QDate(2010, 8, 31), QDate(2010, 9, 30),  0,  1,  0);
 
976
    compareDateDifference(calendar, QDate(2010, 7,  1), QDate(2011, 6,  1),  0, 11,  0);
 
977
    compareDateDifference(calendar, QDate(2010, 7, 10), QDate(2011, 6, 20),  0, 11, 10);
 
978
    compareDateDifference(calendar, QDate(2010, 7, 20), QDate(2011, 6, 10),  0, 10, 21);
 
979
    compareDateDifference(calendar, QDate(2010, 7, 31), QDate(2011, 6, 30),  0, 11,  0);
 
980
    compareDateDifference(calendar, QDate(2010, 8, 30), QDate(2011, 7, 31),  0, 11,  1);
 
981
    compareDateDifference(calendar, QDate(2010, 6, 10), QDate(2011, 6, 10),  1,  0,  0);
 
982
    compareDateDifference(calendar, QDate(2010, 6, 10), QDate(2011, 6, 20),  1,  0, 10);
 
983
    compareDateDifference(calendar, QDate(2010, 6, 10), QDate(2011, 7, 10),  1,  1,  0);
 
984
    compareDateDifference(calendar, QDate(2010, 6, 10), QDate(2011, 7, 20),  1,  1, 10);
 
985
    compareDateDifference(calendar, QDate(2010, 6, 20), QDate(2011, 8, 10),  1,  1, 21);
 
986
    compareDateDifference(calendar, QDate(2010, 6, 30), QDate(2011, 7, 31),  1,  1,  1);
 
987
    compareDateDifference(calendar, QDate(2010, 8, 31), QDate(2011, 9, 30),  1,  1,  0);
 
988
    compareDateDifference(calendar, QDate(2010, 7, 31), QDate(2012, 6, 30),  1, 11,  0);
 
989
    compareDateDifference(calendar, QDate(2010, 8, 30), QDate(2012, 7, 31),  1, 11,  1);
 
990
    compareDateDifference(calendar, QDate(2000, 2, 29), QDate(2001, 2, 28),  1,  0,  0);
 
991
    compareDateDifference(calendar, QDate(2000, 2, 29), QDate(2001, 3,  1),  1,  0,  1);
 
992
    compareDateDifference(calendar, QDate(2000, 2, 29), QDate(2001, 4,  1),  1,  1,  3);
 
993
    calendar->setDate(testDate1, -1, 1, 1);
 
994
    calendar->setDate(testDate2,  1, 1, 1);
 
995
    compareDateDifference(calendar, testDate1, testDate2,  1,  0,  0);
976
996
 
977
997
    // Years Difference
978
998
 
979
 
    compareYearDifference( calendar, QDate( 2010, 1,  1 ), QDate( 2010,  1,  1 ), 0 );
980
 
    compareYearDifference( calendar, QDate( 2010, 1,  1 ), QDate( 2010, 12, 31 ), 0 );
981
 
    compareYearDifference( calendar, QDate( 2010, 6,  1 ), QDate( 2010,  7,  1 ), 0 );
982
 
    compareYearDifference( calendar, QDate( 2010, 6,  1 ), QDate( 2011,  5,  1 ), 0 );
983
 
    compareYearDifference( calendar, QDate( 2010, 6,  1 ), QDate( 2011,  7,  1 ), 1 );
984
 
    compareYearDifference( calendar, QDate( 2010, 6, 20 ), QDate( 2012,  6, 20 ), 2 );
985
 
    compareYearDifference( calendar, QDate( 2010, 6, 20 ), QDate( 2012,  6, 30 ), 2 );
986
 
    compareYearDifference( calendar, QDate( 2010, 6, 20 ), QDate( 2012,  6, 10 ), 1 );
987
 
    compareYearDifference( calendar, QDate( 2000, 2, 29 ), QDate( 2001,  2, 28 ), 1 );
988
 
    calendar->setDate( testDate1, -1, 12, 31 );
989
 
    calendar->setDate( testDate2,  1,  1,  1 );
990
 
    compareYearDifference( calendar, testDate1, testDate2, 0 );
991
 
    calendar->setDate( testDate1, -1,  1,  1 );
992
 
    compareYearDifference( calendar, testDate1, testDate2, 1 );
 
999
    compareYearDifference(calendar, QDate(2010, 1,  1), QDate(2010,  1,  1), 0);
 
1000
    compareYearDifference(calendar, QDate(2010, 1,  1), QDate(2010, 12, 31), 0);
 
1001
    compareYearDifference(calendar, QDate(2010, 6,  1), QDate(2010,  7,  1), 0);
 
1002
    compareYearDifference(calendar, QDate(2010, 6,  1), QDate(2011,  5,  1), 0);
 
1003
    compareYearDifference(calendar, QDate(2010, 6,  1), QDate(2011,  7,  1), 1);
 
1004
    compareYearDifference(calendar, QDate(2010, 6, 20), QDate(2012,  6, 20), 2);
 
1005
    compareYearDifference(calendar, QDate(2010, 6, 20), QDate(2012,  6, 30), 2);
 
1006
    compareYearDifference(calendar, QDate(2010, 6, 20), QDate(2012,  6, 10), 1);
 
1007
    compareYearDifference(calendar, QDate(2000, 2, 29), QDate(2001,  2, 28), 1);
 
1008
    calendar->setDate(testDate1, -1, 12, 31);
 
1009
    calendar->setDate(testDate2,  1,  1,  1);
 
1010
    compareYearDifference(calendar, testDate1, testDate2, 0);
 
1011
    calendar->setDate(testDate1, -1,  1,  1);
 
1012
    compareYearDifference(calendar, testDate1, testDate2, 1);
993
1013
 
994
1014
    // Months Difference
995
1015
 
996
 
    compareMonthDifference( calendar, QDate( 2010, 1,  1 ), QDate( 2010,  1,  1 ), 0 );
997
 
    compareMonthDifference( calendar, QDate( 2010, 1,  1 ), QDate( 2010,  2,  1 ), 1 );
998
 
    compareMonthDifference( calendar, QDate( 2010, 1, 10 ), QDate( 2010,  2,  1 ), 0 );
999
 
    compareMonthDifference( calendar, QDate( 2010, 1, 10 ), QDate( 2010,  2, 20 ), 1 );
1000
 
    compareMonthDifference( calendar, QDate( 2010, 1,  1 ), QDate( 2011,  1,  1 ), 12 );
1001
 
    compareMonthDifference( calendar, QDate( 2010, 1,  1 ), QDate( 2011,  2,  1 ), 13 );
1002
 
    compareMonthDifference( calendar, QDate( 2010, 1, 10 ), QDate( 2011,  2,  1 ), 12 );
1003
 
    compareMonthDifference( calendar, QDate( 2010, 1, 10 ), QDate( 2011,  2, 20 ), 13 );
1004
 
    compareMonthDifference( calendar, QDate( 2000, 2, 29 ), QDate( 2001,  2, 27 ), 11 );
1005
 
    compareMonthDifference( calendar, QDate( 2000, 2, 29 ), QDate( 2001,  2, 28 ), 12 );
1006
 
    compareMonthDifference( calendar, QDate( 2000, 2, 27 ), QDate( 2001,  2, 28 ), 12 );
1007
 
    compareMonthDifference( calendar, QDate( 2000, 2, 29 ), QDate( 2001,  3,  1 ), 12 );
1008
 
    calendar->setDate( testDate1, -1, 12, 31 );
1009
 
    calendar->setDate( testDate2,  1,  1,  1 );
1010
 
    compareMonthDifference( calendar, testDate1, testDate2, 0 );
1011
 
    calendar->setDate( testDate1, -1, 12,  1 );
1012
 
    compareMonthDifference( calendar, testDate1, testDate2, 1 );
 
1016
    compareMonthDifference(calendar, QDate(2010, 1,  1), QDate(2010,  1,  1), 0);
 
1017
    compareMonthDifference(calendar, QDate(2010, 1,  1), QDate(2010,  2,  1), 1);
 
1018
    compareMonthDifference(calendar, QDate(2010, 1, 10), QDate(2010,  2,  1), 0);
 
1019
    compareMonthDifference(calendar, QDate(2010, 1, 10), QDate(2010,  2, 20), 1);
 
1020
    compareMonthDifference(calendar, QDate(2010, 1,  1), QDate(2011,  1,  1), 12);
 
1021
    compareMonthDifference(calendar, QDate(2010, 1,  1), QDate(2011,  2,  1), 13);
 
1022
    compareMonthDifference(calendar, QDate(2010, 1, 10), QDate(2011,  2,  1), 12);
 
1023
    compareMonthDifference(calendar, QDate(2010, 1, 10), QDate(2011,  2, 20), 13);
 
1024
    compareMonthDifference(calendar, QDate(2000, 2, 29), QDate(2001,  2, 27), 11);
 
1025
    compareMonthDifference(calendar, QDate(2000, 2, 29), QDate(2001,  2, 28), 12);
 
1026
    compareMonthDifference(calendar, QDate(2000, 2, 27), QDate(2001,  2, 28), 12);
 
1027
    compareMonthDifference(calendar, QDate(2000, 2, 29), QDate(2001,  3,  1), 12);
 
1028
    calendar->setDate(testDate1, -1, 12, 31);
 
1029
    calendar->setDate(testDate2,  1,  1,  1);
 
1030
    compareMonthDifference(calendar, testDate1, testDate2, 0);
 
1031
    calendar->setDate(testDate1, -1, 12,  1);
 
1032
    compareMonthDifference(calendar, testDate1, testDate2, 1);
1013
1033
 
1014
1034
    // Days Difference
1015
1035
 
1016
1036
    // Directly uses QDate::toJulianDay() so only basic testing needed
1017
 
    testDate1.setDate( 2010, 1, 1 );
1018
 
    testDate2.setDate( 2010, 1, 2 );
1019
 
    QCOMPARE( calendar->daysDifference( testDate1, testDate2 ), 1 );
1020
 
    QCOMPARE( calendar->daysDifference( testDate2, testDate1 ), -1 );
 
1037
    testDate1.setDate(2010, 1, 1);
 
1038
    testDate2.setDate(2010, 1, 2);
 
1039
    QCOMPARE(calendar->daysDifference(testDate1, testDate2), 1);
 
1040
    QCOMPARE(calendar->daysDifference(testDate2, testDate1), -1);
1021
1041
 
1022
1042
    // Test for crossing Julian/Gregorian switch!!!
1023
1043
}
1024
1044
 
1025
 
void KCalendarTest::compareDateDifference( const KCalendarSystem *calendar,
1026
 
                                           const QDate &lowDate, const QDate &highDate,
1027
 
                                           int yearsDiff, int monthsDiff, int daysDiff )
 
1045
void KCalendarTest::compareDateDifference(const KCalendarSystem *calendar,
 
1046
        const QDate &lowDate, const QDate &highDate,
 
1047
        int yearsDiff, int monthsDiff, int daysDiff)
1028
1048
{
1029
1049
    int y, m, d, s;
1030
 
    if ( highDate >= lowDate ) {
1031
 
        calendar->dateDifference( lowDate, highDate, &y, &m, &d, &s );
1032
 
        QCOMPARE( y, yearsDiff);
1033
 
        QCOMPARE( m, monthsDiff);
1034
 
        QCOMPARE( d, daysDiff);
1035
 
        QCOMPARE( s, 1);
1036
 
    }
1037
 
    if ( highDate > lowDate ) {
1038
 
        calendar->dateDifference( highDate, lowDate, &y, &m, &d, &s );
1039
 
        QCOMPARE( y, yearsDiff );
1040
 
        QCOMPARE( m, monthsDiff );
1041
 
        QCOMPARE( d, daysDiff );
1042
 
        QCOMPARE( s, -1 );
1043
 
    }
1044
 
}
1045
 
 
1046
 
void KCalendarTest::compareYearDifference( const KCalendarSystem *calendar,
1047
 
                                           const QDate &lowDate, const QDate &highDate,
1048
 
                                           int yearsDiff )
1049
 
{
1050
 
    if ( highDate >= lowDate ) {
1051
 
        QCOMPARE( calendar->yearsDifference( lowDate, highDate ), yearsDiff );
1052
 
    }
1053
 
    if ( highDate > lowDate ) {
1054
 
        QCOMPARE( calendar->yearsDifference( highDate, lowDate ), -yearsDiff );
1055
 
    }
1056
 
}
1057
 
 
1058
 
void KCalendarTest::compareMonthDifference( const KCalendarSystem *calendar,
1059
 
                                            const QDate &lowDate, const QDate &highDate,
1060
 
                                            int monthsDiff )
1061
 
{
1062
 
    if ( highDate >= lowDate ) {
1063
 
        QCOMPARE( calendar->monthsDifference( lowDate, highDate ), monthsDiff );
1064
 
    }
1065
 
    if ( highDate > lowDate ) {
1066
 
        QCOMPARE( calendar->monthsDifference( highDate, lowDate ), -monthsDiff );
 
1050
    if (highDate >= lowDate) {
 
1051
        calendar->dateDifference(lowDate, highDate, &y, &m, &d, &s);
 
1052
        QCOMPARE(y, yearsDiff);
 
1053
        QCOMPARE(m, monthsDiff);
 
1054
        QCOMPARE(d, daysDiff);
 
1055
        QCOMPARE(s, 1);
 
1056
    }
 
1057
    if (highDate > lowDate) {
 
1058
        calendar->dateDifference(highDate, lowDate, &y, &m, &d, &s);
 
1059
        QCOMPARE(y, yearsDiff);
 
1060
        QCOMPARE(m, monthsDiff);
 
1061
        QCOMPARE(d, daysDiff);
 
1062
        QCOMPARE(s, -1);
 
1063
    }
 
1064
}
 
1065
 
 
1066
void KCalendarTest::compareYearDifference(const KCalendarSystem *calendar,
 
1067
        const QDate &lowDate, const QDate &highDate,
 
1068
        int yearsDiff)
 
1069
{
 
1070
    if (highDate >= lowDate) {
 
1071
        QCOMPARE(calendar->yearsDifference(lowDate, highDate), yearsDiff);
 
1072
    }
 
1073
    if (highDate > lowDate) {
 
1074
        QCOMPARE(calendar->yearsDifference(highDate, lowDate), -yearsDiff);
 
1075
    }
 
1076
}
 
1077
 
 
1078
void KCalendarTest::compareMonthDifference(const KCalendarSystem *calendar,
 
1079
        const QDate &lowDate, const QDate &highDate,
 
1080
        int monthsDiff)
 
1081
{
 
1082
    if (highDate >= lowDate) {
 
1083
        QCOMPARE(calendar->monthsDifference(lowDate, highDate), monthsDiff);
 
1084
    }
 
1085
    if (highDate > lowDate) {
 
1086
        QCOMPARE(calendar->monthsDifference(highDate, lowDate), -monthsDiff);
1067
1087
    }
1068
1088
}
1069
1089
 
1070
1090
void KCalendarTest::testFirstLast()
1071
1091
{
1072
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1073
 
    QDate testDate = QDate( 2010, 6, 15 );
 
1092
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
1093
    QDate testDate = QDate(2010, 6, 15);
1074
1094
 
1075
 
    QCOMPARE( calendar->firstDayOfYear( testDate ),  QDate( 2010,  1, 1 ) );
1076
 
    QCOMPARE( calendar->lastDayOfYear( testDate ),   QDate( 2010, 12, 31 ) );
1077
 
    QCOMPARE( calendar->firstDayOfYear( 2010 ),      QDate( 2010,  1,  1 ) );
1078
 
    QCOMPARE( calendar->lastDayOfYear( 2010 ),       QDate( 2010, 12, 31 ) );
1079
 
    QCOMPARE( calendar->firstDayOfMonth( testDate ), QDate( 2010,  6,  1 ) );
1080
 
    QCOMPARE( calendar->lastDayOfMonth( testDate ),  QDate( 2010,  6, 30 ) );
1081
 
    QCOMPARE( calendar->firstDayOfMonth( 2010, 6 ),  QDate( 2010,  6,  1 ) );
1082
 
    QCOMPARE( calendar->lastDayOfMonth( 2010, 6 ),   QDate( 2010,  6, 30 ) );
 
1095
    QCOMPARE(calendar->firstDayOfYear(testDate),  QDate(2010,  1, 1));
 
1096
    QCOMPARE(calendar->lastDayOfYear(testDate),   QDate(2010, 12, 31));
 
1097
    QCOMPARE(calendar->firstDayOfYear(2010),      QDate(2010,  1,  1));
 
1098
    QCOMPARE(calendar->lastDayOfYear(2010),       QDate(2010, 12, 31));
 
1099
    QCOMPARE(calendar->firstDayOfMonth(testDate), QDate(2010,  6,  1));
 
1100
    QCOMPARE(calendar->lastDayOfMonth(testDate),  QDate(2010,  6, 30));
 
1101
    QCOMPARE(calendar->firstDayOfMonth(2010, 6),  QDate(2010,  6,  1));
 
1102
    QCOMPARE(calendar->lastDayOfMonth(2010, 6),   QDate(2010,  6, 30));
1083
1103
}
1084
1104
 
1085
1105
void KCalendarTest::testEra()
1086
1106
{
1087
 
    KConfigGroup lcg( KGlobal::config(), QString( "Locale" ) );
1088
 
    KConfigGroup cg = lcg.group( QString( "KCalendarSystem %1" ).arg( "gregorian" ) );
 
1107
    KConfigGroup lcg(KGlobal::config(), QString("Locale"));
 
1108
    KConfigGroup cg = lcg.group(QString("KCalendarSystem %1").arg("gregorian"));
1089
1109
    cg.deleteGroup();
1090
1110
 
1091
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
 
1111
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
1092
1112
 
1093
 
    int earliestValidYear = calendar->year( calendar->earliestValidDate() );
1094
 
    int latestValidYear = calendar->year( calendar->latestValidDate() );
 
1113
    int earliestValidYear = calendar->year(calendar->earliestValidDate());
 
1114
    int latestValidYear = calendar->year(calendar->latestValidDate());
1095
1115
 
1096
1116
    QDate testDate;
1097
 
    calendar->setDate( testDate, 2005, 1, 1 );
1098
 
    QCOMPARE( calendar->yearInEra( testDate ), 2005 );
1099
 
    QCOMPARE( calendar->eraName( testDate ), QString( "AD" ) );
1100
 
    QCOMPARE( calendar->eraName( testDate, KCalendarSystem::ShortFormat ), QString( "AD" ) );
1101
 
    QCOMPARE( calendar->eraName( testDate, KCalendarSystem::LongFormat ), QString( "Anno Domini" ) );
1102
 
    calendar->setDate( testDate, -5, 1, 1 );
1103
 
    QCOMPARE( calendar->yearInEra( testDate ), 5 );
1104
 
    QCOMPARE( calendar->eraName( testDate ), QString( "BC" ) );
1105
 
    QCOMPARE( calendar->eraName( testDate, KCalendarSystem::ShortFormat ), QString( "BC" ) );
1106
 
    QCOMPARE( calendar->eraName( testDate, KCalendarSystem::LongFormat ), QString( "Before Christ" ) );
1107
 
 
1108
 
    QCOMPARE( calendar->isValid( "BC",            qAbs( earliestValidYear - 1 ), 1, 1 ), false );
1109
 
    QCOMPARE( calendar->isValid( "BC",            qAbs( earliestValidYear ),     1, 1 ), true );
1110
 
    QCOMPARE( calendar->isValid( "Before Christ", qAbs( earliestValidYear ),     1, 1 ), true );
1111
 
    QCOMPARE( calendar->isValid( "BC",            -1,                            1, 1 ), true );
1112
 
    QCOMPARE( calendar->isValid( "Before Christ", -1,                            1, 1 ), true );
1113
 
    QCOMPARE( calendar->isValid( "BC", 0,                                        1, 1 ), false );
1114
 
    QCOMPARE( calendar->isValid( "AD", 1,                                        1, 1 ), true );
1115
 
    QCOMPARE( calendar->isValid( "Anno Domini",   1,                             1, 1 ), true );
1116
 
    QCOMPARE( calendar->isValid( "AD",            latestValidYear,               1, 1 ), true );
1117
 
    QCOMPARE( calendar->isValid( "Anno Domini",   latestValidYear,               1, 1 ), true );
1118
 
    QCOMPARE( calendar->isValid( "AD",            latestValidYear + 1,           1, 1 ), false );
1119
 
 
1120
 
    QCOMPARE( calendar->isValid( "AD", 2005,  0,  1 ), false );
1121
 
    QCOMPARE( calendar->isValid( "AD", 2005, 13,  1 ), false );
1122
 
    QCOMPARE( calendar->isValid( "AD", 2005,  1,  0 ), false );
1123
 
    QCOMPARE( calendar->isValid( "AD", 2005,  1, 32 ), false );
1124
 
    QCOMPARE( calendar->isValid( "AD", 2005,  1,  1 ), true );
1125
 
    QCOMPARE( calendar->isValid( "AD", 2005,  1, 31 ), true );
1126
 
    QCOMPARE( calendar->isValid( "AD", 2005, 12,  1 ), true );
1127
 
    QCOMPARE( calendar->isValid( "AD", 2005, 12, 31 ), true );
1128
 
 
1129
 
    QCOMPARE( setEraDate( calendar, "BC",            qAbs( earliestValidYear - 1 ), 1, 1 ), QDate() );
1130
 
    QCOMPARE( setEraDate( calendar, "BC",            qAbs( earliestValidYear ),     1, 1 ), QDate( earliestValidYear, 1, 1 ) );
1131
 
    QCOMPARE( setEraDate( calendar, "Before Christ", qAbs( earliestValidYear ),     1, 1 ), QDate( earliestValidYear, 1, 1 ) );
1132
 
    QCOMPARE( setEraDate( calendar, "BC",            1,                             1, 1 ), QDate( -1,                1, 1 ) );
1133
 
    QCOMPARE( setEraDate( calendar, "Before Christ", 1,                             1, 1 ), QDate( -1,                1, 1 ) );
1134
 
    QCOMPARE( setEraDate( calendar, "BC",            0,                             1, 1 ), QDate() );
1135
 
    QCOMPARE( setEraDate( calendar, "AD",            1,                             1, 1 ), QDate( 1,                 1, 1 ) );
1136
 
    QCOMPARE( setEraDate( calendar, "Anno Domini",   1,                             1, 1 ), QDate( 1,                 1, 1 ) );
1137
 
    QCOMPARE( setEraDate( calendar, "AD",            latestValidYear,               1, 1 ), QDate( latestValidYear,   1, 1 ) );
1138
 
    QCOMPARE( setEraDate( calendar, "Anno Domini",   latestValidYear,               1, 1 ), QDate( latestValidYear,   1, 1 ) );
1139
 
    QCOMPARE( setEraDate( calendar, "AD",            latestValidYear + 1,           1, 1 ), QDate() );
1140
 
 
1141
 
    QCOMPARE( setEraDate( calendar, "AD", 2005,  0,  1 ), QDate() );
1142
 
    QCOMPARE( setEraDate( calendar, "AD", 2005, 13,  1 ), QDate() );
1143
 
    QCOMPARE( setEraDate( calendar, "AD", 2005,  1,  0 ), QDate() );
1144
 
    QCOMPARE( setEraDate( calendar, "AD", 2005,  1, 32 ), QDate() );
1145
 
    QCOMPARE( setEraDate( calendar, "AD", 2005,  1,  1 ), QDate( 2005,  1,  1 ) );
1146
 
    QCOMPARE( setEraDate( calendar, "AD", 2005,  1, 31 ), QDate( 2005,  1, 31 ) );
1147
 
    QCOMPARE( setEraDate( calendar, "AD", 2005, 12,  1 ), QDate( 2005, 12,  1 ) );
1148
 
    QCOMPARE( setEraDate( calendar, "AD", 2005, 12, 31 ), QDate( 2005, 12, 31 ) );
 
1117
    calendar->setDate(testDate, 2005, 1, 1);
 
1118
    QCOMPARE(calendar->yearInEra(testDate), 2005);
 
1119
    QCOMPARE(calendar->eraName(testDate), QString("AD"));
 
1120
    QCOMPARE(calendar->eraName(testDate, KCalendarSystem::ShortFormat), QString("AD"));
 
1121
    QCOMPARE(calendar->eraName(testDate, KCalendarSystem::LongFormat), QString("Anno Domini"));
 
1122
    calendar->setDate(testDate, -5, 1, 1);
 
1123
    QCOMPARE(calendar->yearInEra(testDate), 5);
 
1124
    QCOMPARE(calendar->eraName(testDate), QString("BC"));
 
1125
    QCOMPARE(calendar->eraName(testDate, KCalendarSystem::ShortFormat), QString("BC"));
 
1126
    QCOMPARE(calendar->eraName(testDate, KCalendarSystem::LongFormat), QString("Before Christ"));
 
1127
 
 
1128
    QCOMPARE(calendar->isValid("BC",            qAbs(earliestValidYear - 1), 1, 1), false);
 
1129
    QCOMPARE(calendar->isValid("BC",            qAbs(earliestValidYear),     1, 1), true);
 
1130
    QCOMPARE(calendar->isValid("Before Christ", qAbs(earliestValidYear),     1, 1), true);
 
1131
    QCOMPARE(calendar->isValid("BC",            -1,                            1, 1), true);
 
1132
    QCOMPARE(calendar->isValid("Before Christ", -1,                            1, 1), true);
 
1133
    QCOMPARE(calendar->isValid("BC", 0,                                        1, 1), false);
 
1134
    QCOMPARE(calendar->isValid("AD", 1,                                        1, 1), true);
 
1135
    QCOMPARE(calendar->isValid("Anno Domini",   1,                             1, 1), true);
 
1136
    QCOMPARE(calendar->isValid("AD",            latestValidYear,               1, 1), true);
 
1137
    QCOMPARE(calendar->isValid("Anno Domini",   latestValidYear,               1, 1), true);
 
1138
    QCOMPARE(calendar->isValid("AD",            latestValidYear + 1,           1, 1), false);
 
1139
 
 
1140
    QCOMPARE(calendar->isValid("AD", 2005,  0,  1), false);
 
1141
    QCOMPARE(calendar->isValid("AD", 2005, 13,  1), false);
 
1142
    QCOMPARE(calendar->isValid("AD", 2005,  1,  0), false);
 
1143
    QCOMPARE(calendar->isValid("AD", 2005,  1, 32), false);
 
1144
    QCOMPARE(calendar->isValid("AD", 2005,  1,  1), true);
 
1145
    QCOMPARE(calendar->isValid("AD", 2005,  1, 31), true);
 
1146
    QCOMPARE(calendar->isValid("AD", 2005, 12,  1), true);
 
1147
    QCOMPARE(calendar->isValid("AD", 2005, 12, 31), true);
 
1148
 
 
1149
    QCOMPARE(setEraDate(calendar, "BC",            qAbs(earliestValidYear - 1), 1, 1), QDate());
 
1150
    QCOMPARE(setEraDate(calendar, "BC",            qAbs(earliestValidYear),     1, 1), QDate(earliestValidYear, 1, 1));
 
1151
    QCOMPARE(setEraDate(calendar, "Before Christ", qAbs(earliestValidYear),     1, 1), QDate(earliestValidYear, 1, 1));
 
1152
    QCOMPARE(setEraDate(calendar, "BC",            1,                             1, 1), QDate(-1,                1, 1));
 
1153
    QCOMPARE(setEraDate(calendar, "Before Christ", 1,                             1, 1), QDate(-1,                1, 1));
 
1154
    QCOMPARE(setEraDate(calendar, "BC",            0,                             1, 1), QDate());
 
1155
    QCOMPARE(setEraDate(calendar, "AD",            1,                             1, 1), QDate(1,                 1, 1));
 
1156
    QCOMPARE(setEraDate(calendar, "Anno Domini",   1,                             1, 1), QDate(1,                 1, 1));
 
1157
    QCOMPARE(setEraDate(calendar, "AD",            latestValidYear,               1, 1), QDate(latestValidYear,   1, 1));
 
1158
    QCOMPARE(setEraDate(calendar, "Anno Domini",   latestValidYear,               1, 1), QDate(latestValidYear,   1, 1));
 
1159
    QCOMPARE(setEraDate(calendar, "AD",            latestValidYear + 1,           1, 1), QDate());
 
1160
 
 
1161
    QCOMPARE(setEraDate(calendar, "AD", 2005,  0,  1), QDate());
 
1162
    QCOMPARE(setEraDate(calendar, "AD", 2005, 13,  1), QDate());
 
1163
    QCOMPARE(setEraDate(calendar, "AD", 2005,  1,  0), QDate());
 
1164
    QCOMPARE(setEraDate(calendar, "AD", 2005,  1, 32), QDate());
 
1165
    QCOMPARE(setEraDate(calendar, "AD", 2005,  1,  1), QDate(2005,  1,  1));
 
1166
    QCOMPARE(setEraDate(calendar, "AD", 2005,  1, 31), QDate(2005,  1, 31));
 
1167
    QCOMPARE(setEraDate(calendar, "AD", 2005, 12,  1), QDate(2005, 12,  1));
 
1168
    QCOMPARE(setEraDate(calendar, "AD", 2005, 12, 31), QDate(2005, 12, 31));
1149
1169
 
1150
1170
    delete calendar;
1151
 
    cg.writeEntry( "Era1", "-:1:-0001-01-01::Test Era 1:TE1:�0�5%Ey�0�5%EC�0�5" );
1152
 
    cg.writeEntry( "Era2", "+:1:0001-01-01::Test Era 2:TE2:^%Ey^%EC^" );
1153
 
    calendar = KCalendarSystem::create( "gregorian" );
1154
 
    testEraDate( calendar, QDate( 2010,  1,  1 ), 2010, "2010", "2010", "TE2", "Test Era 2" );
1155
 
    testEraDate( calendar, QDate(   -5,  1,  1 ),    5, "5",    "0005", "TE1", "Test Era 1" );
1156
 
    QCOMPARE( calendar->formatDate( QDate( 2010, 1, 1 ), "%EY"), QString( "^2010^TE2^" ) );
1157
 
    QCOMPARE( calendar->formatDate( QDate(   -5, 1, 1 ), "%EY"), QString( "�0�55�0�5TE1�0�5" ) );
 
1171
    cg.writeEntry("Era1", "-:1:-0001-01-01::Test Era 1:TE1:�0�5%Ey�0�5%EC�0�5");
 
1172
    cg.writeEntry("Era2", "+:1:0001-01-01::Test Era 2:TE2:^%Ey^%EC^");
 
1173
    calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
1174
    testEraDate(calendar, QDate(2010,  1,  1), 2010, "2010", "2010", "TE2", "Test Era 2");
 
1175
    testEraDate(calendar, QDate(-5,  1,  1),    5, "5",    "0005", "TE1", "Test Era 1");
 
1176
    QCOMPARE(calendar->formatDate(QDate(2010, 1, 1), "%EY"), QString("^2010^TE2^"));
 
1177
    QCOMPARE(calendar->formatDate(QDate(-5, 1, 1), "%EY"), QString("�0�55�0�5TE1�0�5"));
1158
1178
 
1159
1179
    cg.deleteGroup();
1160
1180
    cg.markAsClean();
1162
1182
    delete calendar;
1163
1183
}
1164
1184
 
1165
 
QDate KCalendarTest::setEraDate( const KCalendarSystem * calendar, const QString &era, int yearInEra, int month, int day )
 
1185
QDate KCalendarTest::setEraDate(const KCalendarSystem * calendar, const QString &era, int yearInEra, int month, int day)
1166
1186
{
1167
1187
    QDate resultDate;
1168
 
    calendar->setDate( resultDate, era, yearInEra, month, day );
 
1188
    calendar->setDate(resultDate, era, yearInEra, month, day);
1169
1189
    return resultDate;
1170
1190
}
1171
1191
 
1172
 
void KCalendarTest::testGregorian()
 
1192
void KCalendarTest::testQDateCalendar()
1173
1193
{
1174
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1175
 
    QDate testDate( 2005, 9, 10 );
1176
 
 
1177
 
    QCOMPARE( calendar->dayOfYear( testDate ), 253 );
1178
 
 
1179
 
    QVERIFY( calendar->setYMD( testDate, 2000, 3, 1 ) );
1180
 
    QCOMPARE( calendar->year( testDate ), 2000 );
1181
 
    QCOMPARE( calendar->month( testDate ), 3 );
1182
 
    QCOMPARE( calendar->day( testDate ), 1 );
1183
 
    QCOMPARE( calendar->daysInYear( testDate ), 366 );
1184
 
 
1185
 
    QDate newDate = calendar->addYears( testDate, 4);
1186
 
    QCOMPARE( newDate.year(), 2004 );
1187
 
    QCOMPARE( calendar->daysInYear( newDate ), 366 );
1188
 
 
1189
 
    newDate = calendar->addMonths( testDate, -4 );
1190
 
    QCOMPARE( newDate.year(), 1999 );
1191
 
    QCOMPARE( newDate.month(), 11 );
1192
 
    QCOMPARE( newDate.day(), 1 );
1193
 
 
1194
 
    newDate = calendar->addDays( newDate, 20 );
1195
 
    QCOMPARE( newDate.year(), 1999 );
1196
 
    QCOMPARE( newDate.month(), 11 );
1197
 
    QCOMPARE( newDate.day(), 21 );
 
1194
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
1195
    QDate testDate(2005, 9, 10);
 
1196
 
 
1197
    QCOMPARE(calendar->dayOfYear(testDate), 253);
 
1198
 
 
1199
    QVERIFY(calendar->setDate(testDate, 2000, 3, 1));
 
1200
    QCOMPARE(calendar->year(testDate), 2000);
 
1201
    QCOMPARE(calendar->month(testDate), 3);
 
1202
    QCOMPARE(calendar->day(testDate), 1);
 
1203
    QCOMPARE(calendar->daysInYear(testDate), 366);
 
1204
 
 
1205
    QDate newDate = calendar->addYears(testDate, 4);
 
1206
    QCOMPARE(newDate.year(), 2004);
 
1207
    QCOMPARE(calendar->daysInYear(newDate), 366);
 
1208
 
 
1209
    newDate = calendar->addMonths(testDate, -4);
 
1210
    QCOMPARE(newDate.year(), 1999);
 
1211
    QCOMPARE(newDate.month(), 11);
 
1212
    QCOMPARE(newDate.day(), 1);
 
1213
 
 
1214
    newDate = calendar->addDays(newDate, 20);
 
1215
    QCOMPARE(newDate.year(), 1999);
 
1216
    QCOMPARE(newDate.month(), 11);
 
1217
    QCOMPARE(newDate.day(), 21);
1198
1218
 
1199
1219
    delete calendar;
1200
1220
}
1201
1221
 
1202
1222
void KCalendarTest::testHebrew()
1203
1223
{
1204
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
1205
 
    QDate testDate( 2005, 9, 10 ); // 5756-13-06
1206
 
    QCOMPARE( calendar->dayOfYear( testDate ), 360 );
1207
 
 
1208
 
    QVERIFY( calendar->setYMD( testDate, 5760, 12, 24 ) );
1209
 
    QCOMPARE( calendar->year( testDate ), 5760 );
1210
 
    QCOMPARE( calendar->month( testDate ), 12 );
1211
 
    QCOMPARE( calendar->day( testDate ), 24 );
1212
 
    QCOMPARE( calendar->daysInYear( testDate ), 385 );
1213
 
 
1214
 
    testDate = calendar->addYears( testDate, 4);
1215
 
    QCOMPARE( calendar->year( testDate ), 5764 );
1216
 
    QCOMPARE( calendar->month( testDate ), 12 );
1217
 
    QCOMPARE( calendar->day( testDate ), 24 );
1218
 
    QCOMPARE( calendar->daysInYear( testDate ), 355 );
1219
 
 
1220
 
    testDate = calendar->addMonths( testDate, -4 );
1221
 
    QCOMPARE( calendar->year( testDate ), 5764 );
1222
 
    QCOMPARE( calendar->month( testDate ), 8 );
1223
 
    QCOMPARE( calendar->day( testDate ), 24 );
1224
 
    QCOMPARE( calendar->daysInYear( testDate ), 355 );
1225
 
 
1226
 
    testDate = calendar->addDays( testDate, 20 );
1227
 
    QCOMPARE( calendar->year( testDate ), 5764 );
1228
 
    QCOMPARE( calendar->month( testDate ), 9 );
1229
 
    QCOMPARE( calendar->day( testDate ), 15 );
1230
 
    QCOMPARE( calendar->daysInYear( testDate ), 355 );
 
1224
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::HebrewCalendar);
 
1225
    QDate testDate(2005, 9, 10);   // 5756-13-06
 
1226
    QCOMPARE(calendar->dayOfYear(testDate), 360);
 
1227
 
 
1228
    QVERIFY(calendar->setDate(testDate, 5760, 12, 24));
 
1229
    QCOMPARE(calendar->year(testDate), 5760);
 
1230
    QCOMPARE(calendar->month(testDate), 12);
 
1231
    QCOMPARE(calendar->day(testDate), 24);
 
1232
    QCOMPARE(calendar->daysInYear(testDate), 385);
 
1233
 
 
1234
    testDate = calendar->addYears(testDate, 4);
 
1235
    QCOMPARE(calendar->year(testDate), 5764);
 
1236
    QCOMPARE(calendar->month(testDate), 12);
 
1237
    QCOMPARE(calendar->day(testDate), 24);
 
1238
    QCOMPARE(calendar->daysInYear(testDate), 355);
 
1239
 
 
1240
    testDate = calendar->addMonths(testDate, -4);
 
1241
    QCOMPARE(calendar->year(testDate), 5764);
 
1242
    QCOMPARE(calendar->month(testDate), 8);
 
1243
    QCOMPARE(calendar->day(testDate), 24);
 
1244
    QCOMPARE(calendar->daysInYear(testDate), 355);
 
1245
 
 
1246
    testDate = calendar->addDays(testDate, 20);
 
1247
    QCOMPARE(calendar->year(testDate), 5764);
 
1248
    QCOMPARE(calendar->month(testDate), 9);
 
1249
    QCOMPARE(calendar->day(testDate), 15);
 
1250
    QCOMPARE(calendar->daysInYear(testDate), 355);
1231
1251
 
1232
1252
    delete calendar;
1233
1253
}
1234
1254
 
1235
 
void KCalendarTest::testHijri()
 
1255
void KCalendarTest::testIslamicCivil()
1236
1256
{
1237
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
1238
 
 
1239
 
    QDate testDate( 2008, 12, 29 ); //1430-01-01, jd 2454830, not leap
1240
 
    QCOMPARE( calendar->year(testDate), 1430 );
1241
 
    QCOMPARE( calendar->month(testDate), 1 );
1242
 
    QCOMPARE( calendar->day(testDate), 1 );
1243
 
    QCOMPARE( calendar->isLeapYear( testDate ), false );
1244
 
    QCOMPARE( calendar->daysInYear(testDate), 354 );
1245
 
    QCOMPARE( calendar->daysInMonth(testDate), 30 );
1246
 
    QCOMPARE( calendar->dayOfYear(testDate), 1 );
1247
 
 
1248
 
    testDate.setDate( 2009, 12, 17 ); //1430-12-29, jd 2455183, not leap
1249
 
    QCOMPARE( calendar->year(testDate), 1430 );
1250
 
    QCOMPARE( calendar->month(testDate), 12 );
1251
 
    QCOMPARE( calendar->day(testDate), 29 );
1252
 
    QCOMPARE( calendar->isLeapYear( testDate ), false );
1253
 
    QCOMPARE( calendar->daysInYear(testDate), 354 );
1254
 
    QCOMPARE( calendar->daysInMonth(testDate), 29 );
1255
 
    QCOMPARE( calendar->dayOfYear(testDate), 354 );
1256
 
 
1257
 
    testDate.setDate( 2009, 12, 18 ); //1431-01-01, jd 2455184, leap
1258
 
    QCOMPARE( calendar->year(testDate), 1431 );
1259
 
    QCOMPARE( calendar->month(testDate), 1 );
1260
 
    QCOMPARE( calendar->day(testDate), 1 );
1261
 
    QCOMPARE( calendar->isLeapYear( testDate ), true );
1262
 
    QCOMPARE( calendar->daysInYear(testDate), 355 );
1263
 
    QCOMPARE( calendar->daysInMonth(testDate), 30 );
1264
 
    QCOMPARE( calendar->dayOfYear(testDate), 1 );
1265
 
 
1266
 
    testDate.setDate( 2010, 12, 7 ); //1431-12-30, jd 2455538, leap
1267
 
    QCOMPARE( calendar->year(testDate), 1431 );
1268
 
    QCOMPARE( calendar->month(testDate), 12 );
1269
 
    QCOMPARE( calendar->day(testDate), 30 );
1270
 
    QCOMPARE( calendar->isLeapYear( testDate ), true );
1271
 
    QCOMPARE( calendar->daysInYear(testDate), 355 );
1272
 
    QCOMPARE( calendar->daysInMonth(testDate), 30 );
1273
 
    QCOMPARE( calendar->dayOfYear(testDate), 355 );
1274
 
 
1275
 
    testDate.setDate( 2005, 9, 10 ); //1426-08-06
1276
 
    QCOMPARE( calendar->year(testDate), 1426 );
1277
 
    QCOMPARE( calendar->month(testDate), 8 );
1278
 
    QCOMPARE( calendar->day(testDate), 6 );
1279
 
    QCOMPARE( calendar->daysInYear(testDate), 355 );
1280
 
    QCOMPARE( calendar->daysInMonth(testDate), 29 );
1281
 
    QCOMPARE( calendar->weeksInYear(testDate.year()), 50 );
1282
 
    QCOMPARE( calendar->weekNumber(testDate), 31 );
1283
 
    QCOMPARE( calendar->dayOfYear(testDate), 213 );
1284
 
 
1285
 
    QVERIFY( calendar->setYMD( testDate, 2000, 3, 1 ) );
1286
 
    QCOMPARE( calendar->year(testDate), 2000 );
1287
 
    QCOMPARE( calendar->month(testDate), 3 );
1288
 
    QCOMPARE( calendar->day(testDate), 1 );
 
1257
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::IslamicCivilCalendar);
 
1258
 
 
1259
    QDate testDate(2008, 12, 29);   //1430-01-01, jd 2454830, not leap
 
1260
    QCOMPARE(calendar->year(testDate), 1430);
 
1261
    QCOMPARE(calendar->month(testDate), 1);
 
1262
    QCOMPARE(calendar->day(testDate), 1);
 
1263
    QCOMPARE(calendar->isLeapYear(testDate), false);
 
1264
    QCOMPARE(calendar->daysInYear(testDate), 354);
 
1265
    QCOMPARE(calendar->daysInMonth(testDate), 30);
 
1266
    QCOMPARE(calendar->dayOfYear(testDate), 1);
 
1267
 
 
1268
    testDate.setDate(2009, 12, 17);   //1430-12-29, jd 2455183, not leap
 
1269
    QCOMPARE(calendar->year(testDate), 1430);
 
1270
    QCOMPARE(calendar->month(testDate), 12);
 
1271
    QCOMPARE(calendar->day(testDate), 29);
 
1272
    QCOMPARE(calendar->isLeapYear(testDate), false);
 
1273
    QCOMPARE(calendar->daysInYear(testDate), 354);
 
1274
    QCOMPARE(calendar->daysInMonth(testDate), 29);
 
1275
    QCOMPARE(calendar->dayOfYear(testDate), 354);
 
1276
 
 
1277
    testDate.setDate(2009, 12, 18);   //1431-01-01, jd 2455184, leap
 
1278
    QCOMPARE(calendar->year(testDate), 1431);
 
1279
    QCOMPARE(calendar->month(testDate), 1);
 
1280
    QCOMPARE(calendar->day(testDate), 1);
 
1281
    QCOMPARE(calendar->isLeapYear(testDate), true);
 
1282
    QCOMPARE(calendar->daysInYear(testDate), 355);
 
1283
    QCOMPARE(calendar->daysInMonth(testDate), 30);
 
1284
    QCOMPARE(calendar->dayOfYear(testDate), 1);
 
1285
 
 
1286
    testDate.setDate(2010, 12, 7);   //1431-12-30, jd 2455538, leap
 
1287
    QCOMPARE(calendar->year(testDate), 1431);
 
1288
    QCOMPARE(calendar->month(testDate), 12);
 
1289
    QCOMPARE(calendar->day(testDate), 30);
 
1290
    QCOMPARE(calendar->isLeapYear(testDate), true);
 
1291
    QCOMPARE(calendar->daysInYear(testDate), 355);
 
1292
    QCOMPARE(calendar->daysInMonth(testDate), 30);
 
1293
    QCOMPARE(calendar->dayOfYear(testDate), 355);
 
1294
 
 
1295
    testDate.setDate(2005, 9, 10);   //1426-08-06
 
1296
    QCOMPARE(calendar->year(testDate), 1426);
 
1297
    QCOMPARE(calendar->month(testDate), 8);
 
1298
    QCOMPARE(calendar->day(testDate), 6);
 
1299
    QCOMPARE(calendar->daysInYear(testDate), 355);
 
1300
    QCOMPARE(calendar->daysInMonth(testDate), 29);
 
1301
    QCOMPARE(calendar->weeksInYear(testDate.year()), 50);
 
1302
    QCOMPARE(calendar->weekNumber(testDate), 31);
 
1303
    QCOMPARE(calendar->dayOfYear(testDate), 213);
 
1304
 
 
1305
    QVERIFY(calendar->setDate(testDate, 2000, 3, 1));
 
1306
    QCOMPARE(calendar->year(testDate), 2000);
 
1307
    QCOMPARE(calendar->month(testDate), 3);
 
1308
    QCOMPARE(calendar->day(testDate), 1);
1289
1309
 
1290
1310
    QDate newDate = calendar->addYears(testDate, 4);
1291
 
    QCOMPARE( newDate.year(), 2566 );
1292
 
    QCOMPARE( calendar->daysInYear(newDate), 355 );
1293
 
 
1294
 
    newDate = calendar->addMonths( testDate, -4 );
1295
 
    QCOMPARE( newDate.year(), 2561 );
1296
 
    QCOMPARE( newDate.month(), 11 );
1297
 
    QCOMPARE( newDate.day(), 10 );
1298
 
 
1299
 
    newDate = calendar->addDays( newDate, 20 );
1300
 
    QCOMPARE( newDate.year(), 2561 );
1301
 
    QCOMPARE( newDate.month(), 11 );
1302
 
    QCOMPARE( newDate.day(), 30 );
 
1311
    QCOMPARE(newDate.year(), 2566);
 
1312
    QCOMPARE(calendar->daysInYear(newDate), 355);
 
1313
 
 
1314
    newDate = calendar->addMonths(testDate, -4);
 
1315
    QCOMPARE(newDate.year(), 2561);
 
1316
    QCOMPARE(newDate.month(), 11);
 
1317
    QCOMPARE(newDate.day(), 10);
 
1318
 
 
1319
    newDate = calendar->addDays(newDate, 20);
 
1320
    QCOMPARE(newDate.year(), 2561);
 
1321
    QCOMPARE(newDate.month(), 11);
 
1322
    QCOMPARE(newDate.day(), 30);
1303
1323
 
1304
1324
    delete calendar;
1305
1325
}
1307
1327
 
1308
1328
void KCalendarTest::testIndianNational()
1309
1329
{
1310
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IndianNationalCalendar );
1311
 
    QDate testDate( 2005, 9, 10 );
1312
 
 
1313
 
    calendar->setYMD( testDate, 2000, 1, 1 );
1314
 
    calendar->setYMD( testDate, 2000, 1, 10 );
1315
 
    calendar->setYMD( testDate, 2000, 2, 10 );
1316
 
    calendar->setYMD( testDate, 2000, 5, 20 );
1317
 
    calendar->setYMD( testDate, 2000, 7, 1 );
1318
 
    calendar->setYMD( testDate, 2000, 7, 10 );
1319
 
    calendar->setYMD( testDate, 2000, 9, 10 );
1320
 
    calendar->setYMD( testDate, 2000, 12, 20 );
1321
 
 
1322
 
    QCOMPARE( calendar->isLeapYear( 2009 ), false );
1323
 
    QCOMPARE( calendar->isLeapYear( testDate ), false );
1324
 
 
1325
 
    QVERIFY( calendar->setYMD( testDate, 2000, 3, 1 ) );
1326
 
    QCOMPARE( calendar->year( testDate ), 2000 );
1327
 
    QCOMPARE( calendar->month( testDate ), 3 );
1328
 
    QCOMPARE( calendar->day( testDate ), 1 );
 
1330
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::IndianNationalCalendar);
 
1331
    QDate testDate(2005, 9, 10);
 
1332
 
 
1333
    calendar->setDate(testDate, 2000, 1, 1);
 
1334
    calendar->setDate(testDate, 2000, 1, 10);
 
1335
    calendar->setDate(testDate, 2000, 2, 10);
 
1336
    calendar->setDate(testDate, 2000, 5, 20);
 
1337
    calendar->setDate(testDate, 2000, 7, 1);
 
1338
    calendar->setDate(testDate, 2000, 7, 10);
 
1339
    calendar->setDate(testDate, 2000, 9, 10);
 
1340
    calendar->setDate(testDate, 2000, 12, 20);
 
1341
 
 
1342
    QCOMPARE(calendar->isLeapYear(2009), false);
 
1343
    QCOMPARE(calendar->isLeapYear(testDate), false);
 
1344
 
 
1345
    QVERIFY(calendar->setDate(testDate, 2000, 3, 1));
 
1346
    QCOMPARE(calendar->year(testDate), 2000);
 
1347
    QCOMPARE(calendar->month(testDate), 3);
 
1348
    QCOMPARE(calendar->day(testDate), 1);
1329
1349
 
1330
1350
    // Test some key dates
1331
 
    testYmd( calendar,    0,  1,  1, QDate(   78,  3, 24 ).toJulianDay() );
1332
 
    testYmd( calendar,    0, 12, 30, QDate(   79,  3, 23 ).toJulianDay() );
1333
 
    testYmd( calendar, 1922,  1,  1, QDate( 2000,  3, 21 ).toJulianDay() );
1334
 
    testYmd( calendar, 1922, 12, 30, QDate( 2001,  3, 21 ).toJulianDay() );
1335
 
    testYmd( calendar, 1932,  1,  1, QDate( 2010,  3, 22 ).toJulianDay() );
1336
 
    testYmd( calendar, 1932, 12, 30, QDate( 2011,  3, 21 ).toJulianDay() );
1337
 
 
1338
 
    testRoundTrip( calendar );
1339
 
 
1340
 
    delete calendar;
1341
 
}
 
1351
    testYmd(calendar,    0,  1,  1, QDate(78,  3, 24).toJulianDay());
 
1352
    testYmd(calendar,    0, 12, 30, QDate(79,  3, 23).toJulianDay());
 
1353
    testYmd(calendar, 1922,  1,  1, QDate(2000,  3, 21).toJulianDay());
 
1354
    testYmd(calendar, 1922, 12, 30, QDate(2001,  3, 21).toJulianDay());
 
1355
    testYmd(calendar, 1932,  1,  1, QDate(2010,  3, 22).toJulianDay());
 
1356
    testYmd(calendar, 1932, 12, 30, QDate(2011,  3, 21).toJulianDay());
 
1357
 
 
1358
    testRoundTrip(calendar);
 
1359
 
 
1360
    delete calendar;
 
1361
}
 
1362
 
 
1363
void KCalendarTest::testQDateCalendarBasic()
 
1364
{
 
1365
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
1366
 
 
1367
    testCalendarSystemType(calendar, KLocale::QDateCalendar, "gregorian", "Gregorian");
 
1368
 
 
1369
    QCOMPARE(calendar->epoch(), QDate(1, 1, 1));
 
1370
    QCOMPARE(calendar->earliestValidDate(), QDate(-4712, 1, 1));
 
1371
    QCOMPARE(calendar->latestValidDate(), QDate(9999, 12, 31));
 
1372
 
 
1373
    testValid(calendar, 0, 10000, 13, 32, QDate(-5000, 1, 1));
 
1374
 
 
1375
    QCOMPARE(calendar->isLeapYear(2007), false);
 
1376
    QCOMPARE(calendar->isLeapYear(2008), true);
 
1377
    QCOMPARE(calendar->isLeapYear(1900), false);
 
1378
    QCOMPARE(calendar->isLeapYear(2000), true);
 
1379
    QCOMPARE(calendar->isLeapYear(QDate(2007, 1, 1)), false);
 
1380
    QCOMPARE(calendar->isLeapYear(QDate(2008, 1, 1)), true);
 
1381
 
 
1382
    QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
 
1383
 
 
1384
    QCOMPARE(calendar->monthsInYear(2007),                12);
 
1385
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1386
 
 
1387
    testYear(calendar, QDate(2007, 7, 9), 2007, QString("07"), QString("2007"));
 
1388
    testMonth(calendar, QDate(2007, 7, 9),    7, QString("7"),  QString("07"));
 
1389
    testDay(calendar, QDate(2007, 7, 9),    9, QString("9"),  QString("09"));
 
1390
 
 
1391
    testEraDate(calendar, QDate(2005, 1, 1), 2005, "2005", "2005", "AD", "Anno Domini");
 
1392
    testEraDate(calendar, QDate(-5, 1, 1),    5, "5",    "0005", "BC", "Before Christ");
 
1393
 
 
1394
    testWeekDayName(calendar, 6, QDate(2007, 7, 28), "S", "Sat", "Saturday");
 
1395
    testMonthName(calendar, 12, 2007, QDate(2007, 12, 20), "D", "Dec", "December", "of Dec", "of December");
 
1396
 
 
1397
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1398
 
 
1399
    QCOMPARE(calendar->weekStartDay(), 1);
 
1400
    QCOMPARE(calendar->weekDayOfPray(), 7);
 
1401
 
 
1402
    QCOMPARE(calendar->isProleptic(), false);
 
1403
    QCOMPARE(calendar->isLunar(), false);
 
1404
    QCOMPARE(calendar->isLunisolar(), false);
 
1405
    QCOMPARE(calendar->isSolar(), true);
 
1406
 
 
1407
    testRoundTrip(calendar);
 
1408
 
 
1409
    delete calendar;
 
1410
}
 
1411
 
 
1412
void KCalendarTest::testQDateCalendarYmd()
 
1413
{
 
1414
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
1415
    testYmd(calendar, 2007, 1, 1, QDate(2007, 1, 1).toJulianDay());
 
1416
    delete calendar;
 
1417
}
 
1418
 
 
1419
void KCalendarTest::testQDateCalendarSpecialCases()
 
1420
{
 
1421
    KConfigGroup lcg(KGlobal::config(), QString("Locale"));
 
1422
    KConfigGroup cg = lcg.group(QString("KCalendarSystem %1").arg("gregorian"));
 
1423
    cg.deleteGroup();
 
1424
 
 
1425
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
1426
 
 
1427
    testEraDate(calendar, QDate(2010,  1,  1), 2010, "2010", "2010", "AD", "Anno Domini");
 
1428
    testEraDate(calendar, QDate(-5,  1,  1),    5, "5",    "0005", "BC", "Before Christ");
 
1429
 
 
1430
    delete calendar;
 
1431
    cg.writeEntry("UseCommonEra", false, KConfigGroup::Global);
 
1432
    calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
1433
    testEraDate(calendar, QDate(2010,  1,  1), 2010, "2010", "2010", "AD", "Anno Domini");
 
1434
    testEraDate(calendar, QDate(-5,  1,  1),    5, "5",    "0005", "BC", "Before Christ");
 
1435
 
 
1436
    delete calendar;
 
1437
    cg.writeEntry("UseCommonEra", true, KConfigGroup::Global);
 
1438
    calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
1439
    testEraDate(calendar, QDate(2010,  1,  1), 2010, "2010", "2010", "CE", "Common Era");
 
1440
    testEraDate(calendar, QDate(-5,  1,  1),    5, "5",    "0005", "BCE", "Before Common Era");
 
1441
 
 
1442
    cg.deleteGroup();
 
1443
    cg.markAsClean();
 
1444
    delete calendar;
 
1445
}
 
1446
 
1342
1447
 
1343
1448
void KCalendarTest::testGregorianBasic()
1344
1449
{
1345
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1346
 
 
1347
 
    testCalendarSystemType( calendar, KLocale::QDateCalendar, "gregorian", "Gregorian" );
1348
 
 
1349
 
    QCOMPARE( calendar->epoch(), QDate( 1, 1, 1 ) );
1350
 
    QCOMPARE( calendar->earliestValidDate(), QDate( -4712, 1, 1 ) );
1351
 
    QCOMPARE( calendar->latestValidDate(), QDate( 9999, 12, 31 ) );
1352
 
 
1353
 
    testValid( calendar, 0, 10000, 13, 32, QDate( -5000, 1, 1 ) );
1354
 
 
1355
 
    QCOMPARE( calendar->isLeapYear( 2007 ), false );
1356
 
    QCOMPARE( calendar->isLeapYear( 2008 ), true );
1357
 
    QCOMPARE( calendar->isLeapYear( 1900 ), false );
1358
 
    QCOMPARE( calendar->isLeapYear( 2000 ), true );
1359
 
    QCOMPARE( calendar->isLeapYear( QDate( 2007, 1, 1 ) ), false );
1360
 
    QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), true );
1361
 
 
1362
 
    QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1363
 
 
1364
 
    QCOMPARE( calendar->monthsInYear( 2007 ),                12 );
1365
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1366
 
 
1367
 
    testYear(  calendar, QDate( 2007, 7, 9 ), 2007, QString("07"), QString("2007") );
1368
 
    testMonth( calendar, QDate( 2007, 7, 9 ),    7, QString("7"),  QString("07") );
1369
 
    testDay(   calendar, QDate( 2007, 7, 9 ),    9, QString("9"),  QString("09") );
1370
 
 
1371
 
    testEraDate( calendar, QDate( 2005, 1, 1 ), 2005, "2005", "2005", "AD", "Anno Domini" );
1372
 
    testEraDate( calendar, QDate(   -5, 1, 1 ),    5, "5",    "0005", "BC", "Before Christ" );
1373
 
 
1374
 
    testWeekDayName( calendar, 6, QDate( 2007, 7, 28 ), "Sat", "Saturday" );
1375
 
    testMonthName( calendar, 12, 2007, QDate( 2007, 12, 20 ), "Dec", "December", "of Dec", "of December" );
1376
 
 
1377
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1378
 
 
1379
 
    QCOMPARE( calendar->weekStartDay(), 1 );
1380
 
    QCOMPARE( calendar->weekDayOfPray(), 7 );
1381
 
 
1382
 
    QCOMPARE( calendar->isProleptic(), false );
1383
 
    QCOMPARE( calendar->isLunar(), false );
1384
 
    QCOMPARE( calendar->isLunisolar(), false );
1385
 
    QCOMPARE( calendar->isSolar(), true );
1386
 
 
1387
 
    testRoundTrip( calendar );
1388
 
 
1389
 
    delete calendar;
1390
 
}
1391
 
 
1392
 
void KCalendarTest::testGregorianYmd()
1393
 
{
1394
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1395
 
    testYmd( calendar, 2007, 1, 1, QDate( 2007, 1, 1 ).toJulianDay() );
1396
 
    delete calendar;
1397
 
}
1398
 
 
1399
 
void KCalendarTest::testGregorianSpecialCases()
1400
 
{
1401
 
    KConfigGroup lcg( KGlobal::config(), QString( "Locale" ) );
1402
 
    KConfigGroup cg = lcg.group( QString( "KCalendarSystem %1" ).arg( "gregorian" ) );
1403
 
    cg.deleteGroup();
1404
 
 
1405
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1406
 
 
1407
 
    testEraDate( calendar, QDate( 2010,  1,  1 ), 2010, "2010", "2010", "AD", "Anno Domini" );
1408
 
    testEraDate( calendar, QDate(   -5,  1,  1 ),    5, "5",    "0005", "BC", "Before Christ" );
1409
 
 
1410
 
    delete calendar;
1411
 
    cg.writeEntry( "UseCommonEra", false, KConfigGroup::Global );
1412
 
    calendar = KCalendarSystem::create( "gregorian" );
1413
 
    testEraDate( calendar, QDate( 2010,  1,  1 ), 2010, "2010", "2010", "AD", "Anno Domini" );
1414
 
    testEraDate( calendar, QDate(   -5,  1,  1 ),    5, "5",    "0005", "BC", "Before Christ" );
1415
 
 
1416
 
    delete calendar;
1417
 
    cg.writeEntry( "UseCommonEra", true, KConfigGroup::Global );
1418
 
    calendar = KCalendarSystem::create( "gregorian" );
1419
 
    testEraDate( calendar, QDate( 2010,  1,  1 ), 2010, "2010", "2010", "CE", "Common Era" );
1420
 
    testEraDate( calendar, QDate(   -5,  1,  1 ),    5, "5",    "0005", "BCE", "Before Common Era" );
1421
 
 
1422
 
    cg.deleteGroup();
1423
 
    cg.markAsClean();
1424
 
    delete calendar;
1425
 
}
1426
 
 
1427
 
 
1428
 
void KCalendarTest::testGregorianProlepticBasic()
1429
 
{
1430
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::GregorianCalendar );
1431
 
 
1432
 
    testCalendarSystemType( calendar, KLocale::GregorianCalendar, "gregorian-proleptic", "Gregorian (Proleptic)" );
1433
 
 
1434
 
    QCOMPARE( calendar->epoch(), QDate::fromJulianDay( 1721426 ) );
1435
 
    QCOMPARE( calendar->earliestValidDate(), QDate::fromJulianDay( 38 ) );
1436
 
    QCOMPARE( calendar->latestValidDate(), QDate( 9999, 12, 31 ) );
1437
 
 
1438
 
    testValid( calendar, 0, 10000, 13, 32, QDate() );
1439
 
 
1440
 
    QCOMPARE( calendar->isLeapYear( 2007 ), false );
1441
 
    QCOMPARE( calendar->isLeapYear( 2008 ), true );
1442
 
    QCOMPARE( calendar->isLeapYear( 1900 ), false );
1443
 
    QCOMPARE( calendar->isLeapYear( 2000 ), true );
1444
 
    QCOMPARE( calendar->isLeapYear( QDate( 2007, 1, 1 ) ), false );
1445
 
    QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), true );
1446
 
 
1447
 
    QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1448
 
 
1449
 
    QCOMPARE( calendar->monthsInYear( 2007 ),                12 );
1450
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1451
 
 
1452
 
    testYear(  calendar, QDate( 2007, 7, 9 ), 2007, QString("07"), QString("2007") );
1453
 
    testMonth( calendar, QDate( 2007, 7, 9 ),    7, QString("7"),  QString("07") );
1454
 
    testDay(   calendar, QDate( 2007, 7, 9 ),    9, QString("9"),  QString("09") );
1455
 
 
1456
 
    testEraDate( calendar, QDate( 2005, 1, 1 ), 2005, "2005", "2005", "AD", "Anno Domini" );
1457
 
    testEraDate( calendar, QDate(   -5, 1, 3 ),    5, "5",    "0005", "BC", "Before Christ" );
1458
 
 
1459
 
    testWeekDayName( calendar, 6, QDate( 2007, 7, 28 ), "Sat", "Saturday" );
1460
 
    testMonthName( calendar, 12, 2007, QDate( 2007, 12, 20 ), "Dec", "December", "of Dec", "of December" );
1461
 
 
1462
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1463
 
 
1464
 
    QCOMPARE( calendar->weekStartDay(), 1 );
1465
 
    QCOMPARE( calendar->weekDayOfPray(), 7 );
1466
 
 
1467
 
    QCOMPARE( calendar->isProleptic(), true );
1468
 
    QCOMPARE( calendar->isLunar(), false );
1469
 
    QCOMPARE( calendar->isLunisolar(), false );
1470
 
    QCOMPARE( calendar->isSolar(), true );
1471
 
 
1472
 
    testRoundTrip( calendar );
 
1450
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
 
1451
 
 
1452
    testCalendarSystemType(calendar, KLocale::GregorianCalendar, "gregorian-proleptic", "Gregorian (Proleptic)");
 
1453
 
 
1454
    QCOMPARE(calendar->epoch(), QDate::fromJulianDay(1721426));
 
1455
    QCOMPARE(calendar->earliestValidDate(), QDate::fromJulianDay(38));
 
1456
    QCOMPARE(calendar->latestValidDate(), QDate(9999, 12, 31));
 
1457
 
 
1458
    testValid(calendar, 0, 10000, 13, 32, QDate());
 
1459
 
 
1460
    QCOMPARE(calendar->isLeapYear(2007), false);
 
1461
    QCOMPARE(calendar->isLeapYear(2008), true);
 
1462
    QCOMPARE(calendar->isLeapYear(1900), false);
 
1463
    QCOMPARE(calendar->isLeapYear(2000), true);
 
1464
    QCOMPARE(calendar->isLeapYear(QDate(2007, 1, 1)), false);
 
1465
    QCOMPARE(calendar->isLeapYear(QDate(2008, 1, 1)), true);
 
1466
 
 
1467
    QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
 
1468
 
 
1469
    QCOMPARE(calendar->monthsInYear(2007),                12);
 
1470
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1471
 
 
1472
    testYear(calendar, QDate(2007, 7, 9), 2007, QString("07"), QString("2007"));
 
1473
    testMonth(calendar, QDate(2007, 7, 9),    7, QString("7"),  QString("07"));
 
1474
    testDay(calendar, QDate(2007, 7, 9),    9, QString("9"),  QString("09"));
 
1475
 
 
1476
    testEraDate(calendar, QDate(2005, 1, 1), 2005, "2005", "2005", "AD", "Anno Domini");
 
1477
    testEraDate(calendar, QDate(-5, 1, 3),    5, "5",    "0005", "BC", "Before Christ");
 
1478
 
 
1479
    testWeekDayName(calendar, 6, QDate(2007, 7, 28), "S", "Sat", "Saturday");
 
1480
    testMonthName(calendar, 12, 2007, QDate(2007, 12, 20), "D", "Dec", "December", "of Dec", "of December");
 
1481
 
 
1482
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1483
 
 
1484
    QCOMPARE(calendar->weekStartDay(), 1);
 
1485
    QCOMPARE(calendar->weekDayOfPray(), 7);
 
1486
 
 
1487
    QCOMPARE(calendar->isProleptic(), true);
 
1488
    QCOMPARE(calendar->isLunar(), false);
 
1489
    QCOMPARE(calendar->isLunisolar(), false);
 
1490
    QCOMPARE(calendar->isSolar(), true);
 
1491
 
 
1492
    testRoundTrip(calendar);
1473
1493
 
1474
1494
    delete calendar;
1475
1495
}
1479
1499
 
1480
1500
void KCalendarTest::testHebrewBasic()
1481
1501
{
1482
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
 
1502
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::HebrewCalendar);
1483
1503
    QDate testDate;
1484
1504
 
1485
 
    testCalendarSystemType( calendar, KLocale::HebrewCalendar, "hebrew", "Hebrew" );
1486
 
 
1487
 
    testEpoch( calendar,                1,  1,  1,  347998 );
1488
 
    testEarliestValidDate( calendar, 5344,  1,  1, 2299498 );
1489
 
    testLatestValidDate(   calendar, 8119, 13, 29, 3313431 );
1490
 
 
1491
 
    testDate = QDate::fromJulianDay( 2450340 ); //5756-12-29 Not Leap
1492
 
    QCOMPARE( calendar->isLeapYear( 5756 ), false );
1493
 
    QCOMPARE( calendar->isLeapYear( testDate ), false );
1494
 
    QCOMPARE( calendar->monthsInYear( testDate ), 12 );
1495
 
    QCOMPARE( calendar->month( testDate ), 12 );
1496
 
    QCOMPARE( calendar->monthName( testDate ), QString( "Elul" ) );
1497
 
 
1498
 
    testDate = QDate::fromJulianDay( 2450723 ); //5757-13-29 Leap
1499
 
    QCOMPARE( calendar->isLeapYear( 5757 ), true );
1500
 
    QCOMPARE( calendar->isLeapYear( testDate ), true );
1501
 
    QCOMPARE( calendar->monthsInYear( testDate ), 13 );
1502
 
    QCOMPARE( calendar->month( testDate ), 13 );
1503
 
    QCOMPARE( calendar->monthName( testDate ), QString( "Elul" ) );
 
1505
    testCalendarSystemType(calendar, KLocale::HebrewCalendar, "hebrew", "Hebrew");
 
1506
 
 
1507
    testEpoch(calendar,                1,  1,  1,  347998);
 
1508
    testEarliestValidDate(calendar, 5344,  1,  1, 2299498);
 
1509
    testLatestValidDate(calendar, 8119, 13, 29, 3313431);
 
1510
 
 
1511
    testDate = QDate::fromJulianDay(2450340);   //5756-12-29 Not Leap
 
1512
    QCOMPARE(calendar->isLeapYear(5756), false);
 
1513
    QCOMPARE(calendar->isLeapYear(testDate), false);
 
1514
    QCOMPARE(calendar->monthsInYear(testDate), 12);
 
1515
    QCOMPARE(calendar->month(testDate), 12);
 
1516
    QCOMPARE(calendar->monthName(testDate), QString("Elul"));
 
1517
 
 
1518
    testDate = QDate::fromJulianDay(2450723);   //5757-13-29 Leap
 
1519
    QCOMPARE(calendar->isLeapYear(5757), true);
 
1520
    QCOMPARE(calendar->isLeapYear(testDate), true);
 
1521
    QCOMPARE(calendar->monthsInYear(testDate), 13);
 
1522
    QCOMPARE(calendar->month(testDate), 13);
 
1523
    QCOMPARE(calendar->monthName(testDate), QString("Elul"));
1504
1524
 
1505
1525
    // 5707-01-01 Thursday
1506
 
    testDate = QDate::fromJulianDay( 2432090 );
1507
 
 
1508
 
    QCOMPARE( calendar->daysInWeek( testDate ), 7 );
1509
 
 
1510
 
    testYear(  calendar, testDate, 5707, "07", "5707" );
1511
 
    testMonth( calendar, testDate,    1,  "1",   "01" );
1512
 
    testDay(   calendar, testDate,    1,  "1",   "01" );
1513
 
 
1514
 
    testEraDate( calendar, testDate, 5707, "5707", "5707", "AM", "Anno Mundi" );
1515
 
 
1516
 
    testWeekDayName( calendar, 4, testDate, "Thu", "Thursday" );
1517
 
    testMonthName( calendar, 1, 5707, testDate, "Tishrey", "Tishrey", "of Tishrey", "of Tishrey" );
1518
 
 
1519
 
    QCOMPARE( calendar->weekStartDay(), 1 );
1520
 
    QCOMPARE( calendar->weekDayOfPray(), 6 );
1521
 
 
1522
 
    QCOMPARE( calendar->isProleptic(), false );
1523
 
    QCOMPARE( calendar->isLunar(), false );
1524
 
    QCOMPARE( calendar->isLunisolar(), true );
1525
 
    QCOMPARE( calendar->isSolar(), false );
1526
 
 
1527
 
    testRoundTrip( calendar );
 
1526
    testDate = QDate::fromJulianDay(2432090);
 
1527
 
 
1528
    QCOMPARE(calendar->daysInWeek(testDate), 7);
 
1529
 
 
1530
    testYear(calendar, testDate, 5707, "07", "5707");
 
1531
    testMonth(calendar, testDate,    1,  "1",   "01");
 
1532
    testDay(calendar, testDate,    1,  "1",   "01");
 
1533
 
 
1534
    testEraDate(calendar, testDate, 5707, "5707", "5707", "AM", "Anno Mundi");
 
1535
 
 
1536
    testWeekDayName(calendar, 4, testDate, "T", "Thu", "Thursday");
 
1537
    testMonthName(calendar, 1, 5707, testDate, "T", "Tis", "Tishrey", "of Tis", "of Tishrey");
 
1538
 
 
1539
    QCOMPARE(calendar->weekStartDay(), 1);
 
1540
    QCOMPARE(calendar->weekDayOfPray(), 6);
 
1541
 
 
1542
    QCOMPARE(calendar->isProleptic(), false);
 
1543
    QCOMPARE(calendar->isLunar(), false);
 
1544
    QCOMPARE(calendar->isLunisolar(), true);
 
1545
    QCOMPARE(calendar->isSolar(), false);
 
1546
 
 
1547
    testRoundTrip(calendar);
1528
1548
 
1529
1549
    delete calendar;
1530
1550
}
1538
1558
 
1539
1559
void KCalendarTest::testHebrewCompare()
1540
1560
{
1541
 
/*
1542
 
    const KCalendarSystemHebrew *calendar = new KCalendarSystemHebrew();
1543
 
    QDate setOldDate, setNewDate;
1544
 
 
1545
 
    for ( QDate testDate( 1900, 1, 1 ); testDate.year() == 2100; testDate.addDays(1) ) {
1546
 
        QCOMPARE( calendar->year(  testDate ), calendar->oldyear(  testDate ) );
1547
 
        QCOMPARE( calendar->month( testDate ), calendar->oldmonth( testDate ) );
1548
 
        QCOMPARE( calendar->day(   testDate ), calendar->oldday(   testDate ) );
1549
 
 
1550
 
        calendar->setYMD(setOldDate, calendar->oldyear( testDate ), calendar->oldmonth( testDate ), calendar->oldday( testDate ) );
1551
 
        calendar->setDate(setNewDate, calendar->oldyear( testDate ), calendar->oldmonth( testDate ), calendar->oldday( testDate ) );
1552
 
        QCOMPARE( setNewDate.toJulianDay(), setOldDate.toJulianDay() );
1553
 
    }
1554
 
 
1555
 
    delete calendar;
1556
 
*/
 
1561
    /*
 
1562
        const KCalendarSystemHebrew *calendar = new KCalendarSystemHebrew();
 
1563
        QDate setOldDate, setNewDate;
 
1564
 
 
1565
        for ( QDate testDate( 1900, 1, 1 ); testDate.year() == 2100; testDate.addDays(1) ) {
 
1566
            QCOMPARE( calendar->year(  testDate ), calendar->oldyear(  testDate ) );
 
1567
            QCOMPARE( calendar->month( testDate ), calendar->oldmonth( testDate ) );
 
1568
            QCOMPARE( calendar->day(   testDate ), calendar->oldday(   testDate ) );
 
1569
 
 
1570
            calendar->setDate(setOldDate, calendar->oldyear( testDate ), calendar->oldmonth( testDate ), calendar->oldday( testDate ) );
 
1571
            calendar->setDate(setNewDate, calendar->oldyear( testDate ), calendar->oldmonth( testDate ), calendar->oldday( testDate ) );
 
1572
            QCOMPARE( setNewDate.toJulianDay(), setOldDate.toJulianDay() );
 
1573
        }
 
1574
 
 
1575
        delete calendar;
 
1576
    */
1557
1577
}
1558
1578
 
1559
 
// Test Hijri Calendar System
 
1579
// Test Islamic Civil Calendar System
1560
1580
 
1561
 
void KCalendarTest::testHijriBasic()
 
1581
void KCalendarTest::testIslamicCivilBasic()
1562
1582
{
1563
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
 
1583
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::IslamicCivilCalendar);
1564
1584
    QDate testDate;
1565
1585
 
1566
 
    testCalendarSystemType( calendar, KLocale::IslamicCivilCalendar, "hijri", "Islamic / Hijri (Civil)" );
1567
 
 
1568
 
    QCOMPARE( calendar->epoch(), QDate( 622, 7, 16 ) );
1569
 
    QCOMPARE( calendar->earliestValidDate(), QDate( 622, 7, 16 ) );
1570
 
    QCOMPARE( calendar->latestValidDate(), QDate( 10323, 10, 21) );
1571
 
 
1572
 
    testValid( calendar, 0, 10000, 13, 31, QDate( 1, 1, 1 ) );
1573
 
 
1574
 
    QCOMPARE( calendar->isLeapYear( 1427 ), false );
1575
 
    QCOMPARE( calendar->isLeapYear( 1428 ), true );
1576
 
    QCOMPARE( calendar->isLeapYear( QDate( 2007, 1, 1 ) ), false );
1577
 
    QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), true );
 
1586
    testCalendarSystemType(calendar, KLocale::IslamicCivilCalendar, "hijri", "Islamic / Hijri (Civil)");
 
1587
 
 
1588
    QCOMPARE(calendar->epoch(), QDate(622, 7, 16));
 
1589
    QCOMPARE(calendar->earliestValidDate(), QDate(622, 7, 16));
 
1590
    QCOMPARE(calendar->latestValidDate(), QDate(10323, 10, 21));
 
1591
 
 
1592
    testValid(calendar, 0, 10000, 13, 31, QDate(1, 1, 1));
 
1593
 
 
1594
    QCOMPARE(calendar->isLeapYear(1427), false);
 
1595
    QCOMPARE(calendar->isLeapYear(1428), true);
 
1596
    QCOMPARE(calendar->isLeapYear(QDate(2007, 1, 1)), false);
 
1597
    QCOMPARE(calendar->isLeapYear(QDate(2008, 1, 1)), true);
1578
1598
 
1579
1599
    // 1426-08-06 Saturday
1580
 
    testDate = QDate( 2005, 9, 10 );
1581
 
 
1582
 
    QCOMPARE( calendar->daysInWeek( testDate ), 7 );
1583
 
 
1584
 
    QCOMPARE( calendar->monthsInYear( 1426 ),     12 );
1585
 
    QCOMPARE( calendar->monthsInYear( testDate ), 12 );
1586
 
 
1587
 
    testYear(  calendar, testDate, 1426, "26", "1426" );
1588
 
    testMonth( calendar, testDate,    8, "8",  "08" );
1589
 
    testDay(   calendar, testDate,    6, "6",  "06" );
1590
 
 
1591
 
    testEraDate( calendar, testDate, 1426, "1426", "1426", "AH", "Anno Hegirae" );
1592
 
 
1593
 
    testWeekDayName( calendar, 6, testDate, "Sab", "Yaum al-Sabt" );
1594
 
    testMonthName( calendar, 12, 1428, QDate( 2007, 12, 20 ), "Hijjah", "Thu al-Hijjah", "of Hijjah", "of Thu al-Hijjah" );
1595
 
 
1596
 
    QCOMPARE( calendar->monthsInYear( testDate ), 12 );
1597
 
 
1598
 
    QCOMPARE( calendar->weekStartDay(), 1 );
1599
 
    QCOMPARE( calendar->weekDayOfPray(), 5 );
1600
 
 
1601
 
    QCOMPARE( calendar->isProleptic(), false );
1602
 
    QCOMPARE( calendar->isLunar(), true );
1603
 
    QCOMPARE( calendar->isLunisolar(), false );
1604
 
    QCOMPARE( calendar->isSolar(), false );
1605
 
 
1606
 
    testRoundTrip( calendar );
 
1600
    testDate = QDate(2005, 9, 10);
 
1601
 
 
1602
    QCOMPARE(calendar->daysInWeek(testDate), 7);
 
1603
 
 
1604
    QCOMPARE(calendar->monthsInYear(1426),     12);
 
1605
    QCOMPARE(calendar->monthsInYear(testDate), 12);
 
1606
 
 
1607
    testYear(calendar, testDate, 1426, "26", "1426");
 
1608
    testMonth(calendar, testDate,    8, "8",  "08");
 
1609
    testDay(calendar, testDate,    6, "6",  "06");
 
1610
 
 
1611
    testEraDate(calendar, testDate, 1426, "1426", "1426", "AH", "Anno Hegirae");
 
1612
 
 
1613
    testWeekDayName(calendar, 6, testDate, "S", "Sab", "Yaum al-Sabt");
 
1614
    testMonthName(calendar, 12, 1428, QDate(2007, 12, 20), "H", "Hij", "Thu al-Hijjah", "of Hij", "of Thu al-Hijjah");
 
1615
 
 
1616
    QCOMPARE(calendar->monthsInYear(testDate), 12);
 
1617
 
 
1618
    QCOMPARE(calendar->weekStartDay(), 1);
 
1619
    QCOMPARE(calendar->weekDayOfPray(), 5);
 
1620
 
 
1621
    QCOMPARE(calendar->isProleptic(), false);
 
1622
    QCOMPARE(calendar->isLunar(), true);
 
1623
    QCOMPARE(calendar->isLunisolar(), false);
 
1624
    QCOMPARE(calendar->isSolar(), false);
 
1625
 
 
1626
    testRoundTrip(calendar);
1607
1627
 
1608
1628
    delete calendar;
1609
1629
}
1610
1630
 
1611
 
void KCalendarTest::testHijriYmd()
 
1631
void KCalendarTest::testIslamicCivilYmd()
1612
1632
{
1613
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
1614
 
    testYmd( calendar, 1426, 8, 6, QDate( 2005, 9, 10 ).toJulianDay() );
 
1633
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::IslamicCivilCalendar);
 
1634
    testYmd(calendar, 1426, 8, 6, QDate(2005, 9, 10).toJulianDay());
1615
1635
    delete calendar;
1616
1636
}
1617
1637
 
1620
1640
 
1621
1641
void KCalendarTest::testJalaliBasic()
1622
1642
{
1623
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JalaliCalendar );
 
1643
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JalaliCalendar);
1624
1644
    QDate testDate;
1625
1645
 
1626
 
    testCalendarSystemType( calendar, KLocale::JalaliCalendar, "jalali", "Jalali" );
 
1646
    testCalendarSystemType(calendar, KLocale::JalaliCalendar, "jalali", "Jalali");
1627
1647
 
1628
1648
    //Birashk argorithm only good between AP 1244-01-01 to 1530-12-29 (AD 1865 to 2152)
1629
 
    QCOMPARE( calendar->epoch(), QDate( 622, 3, 19 ) );
1630
 
    QCOMPARE( calendar->earliestValidDate(), QDate( 1865, 03, 21 ) );
1631
 
    QCOMPARE( calendar->latestValidDate(), QDate( 2152, 03, 19 ) );
1632
 
    QCOMPARE( calendar->isValid( 1243, 12, 29 ), false );
1633
 
    QCOMPARE( calendar->isValid( 1531, 1, 1 ), false );
1634
 
 
1635
 
    QCOMPARE( calendar->isLeapYear( 1386 ), false );
1636
 
    QCOMPARE( calendar->isLeapYear( 1387 ), true );
1637
 
    QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), false );
1638
 
    QCOMPARE( calendar->isLeapYear( QDate( 2009, 1, 1 ) ), true );
1639
 
 
1640
 
    testDate = QDate( 2005, 8, 31 ); // 1384-06-09 Wednesday
1641
 
 
1642
 
    QCOMPARE( calendar->daysInWeek( testDate ),    7 );
1643
 
    QCOMPARE( calendar->monthsInYear( 1384 ),     12 );
1644
 
    QCOMPARE( calendar->monthsInYear( testDate ), 12 );
1645
 
 
1646
 
    testYear(  calendar, testDate, 1384, "84", "1384" );
1647
 
    testMonth( calendar, testDate,    6, "6",  "06" );
1648
 
    testDay(   calendar, testDate,    9, "9",  "09" );
1649
 
 
1650
 
    testEraDate( calendar, testDate, 1384, "1384", "1384", "AP", "Anno Persico" );
1651
 
 
1652
 
    testWeekDayName( calendar, 3, testDate, "4sh", "Chahar shanbe" );
1653
 
    testMonthName( calendar, 6, 1384, testDate, "Sha", "Shahrivar", "of Sha", "of Shahrivar" );
1654
 
 
1655
 
    QCOMPARE( calendar->monthsInYear( testDate ), 12 );
1656
 
 
1657
 
    QCOMPARE( calendar->weekStartDay(), 1 );
1658
 
    QCOMPARE( calendar->weekDayOfPray(), 5 );
1659
 
 
1660
 
    QCOMPARE( calendar->isProleptic(), false );
1661
 
    QCOMPARE( calendar->isLunar(), false );
1662
 
    QCOMPARE( calendar->isLunisolar(), false );
1663
 
    QCOMPARE( calendar->isSolar(), true );
1664
 
 
1665
 
    testRoundTrip( calendar );
 
1649
    QCOMPARE(calendar->epoch(), QDate(622, 3, 19));
 
1650
    QCOMPARE(calendar->earliestValidDate(), QDate(1865, 03, 21));
 
1651
    QCOMPARE(calendar->latestValidDate(), QDate(2152, 03, 19));
 
1652
    QCOMPARE(calendar->isValid(1243, 12, 29), false);
 
1653
    QCOMPARE(calendar->isValid(1531, 1, 1), false);
 
1654
 
 
1655
    QCOMPARE(calendar->isLeapYear(1386), false);
 
1656
    QCOMPARE(calendar->isLeapYear(1387), true);
 
1657
    QCOMPARE(calendar->isLeapYear(QDate(2008, 1, 1)), false);
 
1658
    QCOMPARE(calendar->isLeapYear(QDate(2009, 1, 1)), true);
 
1659
 
 
1660
    testDate = QDate(2005, 8, 31);   // 1384-06-09 Wednesday
 
1661
 
 
1662
    QCOMPARE(calendar->daysInWeek(testDate),    7);
 
1663
    QCOMPARE(calendar->monthsInYear(1384),     12);
 
1664
    QCOMPARE(calendar->monthsInYear(testDate), 12);
 
1665
 
 
1666
    testYear(calendar, testDate, 1384, "84", "1384");
 
1667
    testMonth(calendar, testDate,    6, "6",  "06");
 
1668
    testDay(calendar, testDate,    9, "9",  "09");
 
1669
 
 
1670
    testEraDate(calendar, testDate, 1384, "1384", "1384", "AP", "Anno Persico");
 
1671
 
 
1672
    testWeekDayName(calendar, 3, testDate, "4", "4sh", "Chahar shanbe");
 
1673
    testMonthName(calendar, 6, 1384, testDate, "S", "Sha", "Shahrivar", "of Sha", "of Shahrivar");
 
1674
 
 
1675
    QCOMPARE(calendar->monthsInYear(testDate), 12);
 
1676
 
 
1677
    QCOMPARE(calendar->weekStartDay(), 1);
 
1678
    QCOMPARE(calendar->weekDayOfPray(), 5);
 
1679
 
 
1680
    QCOMPARE(calendar->isProleptic(), false);
 
1681
    QCOMPARE(calendar->isLunar(), false);
 
1682
    QCOMPARE(calendar->isLunisolar(), false);
 
1683
    QCOMPARE(calendar->isSolar(), true);
 
1684
 
 
1685
    testRoundTrip(calendar);
1666
1686
 
1667
1687
    //Special cases using Birashk argorithm
1668
 
    QCOMPARE( calendar->isLeapYear( 1403 ), true );
1669
 
    QCOMPARE( calendar->isLeapYear( 1404 ), false );
1670
 
    QCOMPARE( calendar->isLeapYear( 1436 ), true );
1671
 
    QCOMPARE( calendar->isLeapYear( 1437 ), false );
 
1688
    QCOMPARE(calendar->isLeapYear(1403), true);
 
1689
    QCOMPARE(calendar->isLeapYear(1404), false);
 
1690
    QCOMPARE(calendar->isLeapYear(1436), true);
 
1691
    QCOMPARE(calendar->isLeapYear(1437), false);
1672
1692
 
1673
1693
    delete calendar;
1674
1694
}
1675
1695
 
1676
1696
void KCalendarTest::testJalaliYmd()
1677
1697
{
1678
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JalaliCalendar );
1679
 
    testYmd( calendar, 1384, 6, 9, QDate( 2005, 8, 31 ).toJulianDay() );
 
1698
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JalaliCalendar);
 
1699
    testYmd(calendar, 1384, 6, 9, QDate(2005, 8, 31).toJulianDay());
1680
1700
    delete calendar;
1681
1701
}
1682
1702
 
1683
1703
void KCalendarTest::testJapanese()
1684
1704
{
1685
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1686
 
    QDate testDate( 2005, 9, 10 );
1687
 
 
1688
 
    QCOMPARE( calendar->dayOfYear( testDate ), 253 );
1689
 
 
1690
 
    QVERIFY( calendar->setYMD( testDate, 2000, 3, 1 ) );
1691
 
    QCOMPARE( calendar->year( testDate ), 2000 );
1692
 
    QCOMPARE( calendar->month( testDate ), 3 );
1693
 
    QCOMPARE( calendar->day( testDate ), 1 );
1694
 
    QCOMPARE( calendar->daysInYear( testDate ), 366 );
1695
 
 
1696
 
    QDate newDate = calendar->addYears( testDate, 4);
1697
 
    QCOMPARE( newDate.year(), 2004 );
1698
 
    QCOMPARE( calendar->daysInYear( newDate ), 366 );
1699
 
 
1700
 
    newDate = calendar->addMonths( testDate, -4 );
1701
 
    QCOMPARE( newDate.year(), 1999 );
1702
 
    QCOMPARE( newDate.month(), 11 );
1703
 
    QCOMPARE( newDate.day(), 1 );
1704
 
 
1705
 
    newDate = calendar->addDays( newDate, 20 );
1706
 
    QCOMPARE( newDate.year(), 1999 );
1707
 
    QCOMPARE( newDate.month(), 11 );
1708
 
    QCOMPARE( newDate.day(), 21 );
 
1705
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JapaneseCalendar);
 
1706
    QDate testDate(2005, 9, 10);
 
1707
 
 
1708
    QCOMPARE(calendar->dayOfYear(testDate), 253);
 
1709
 
 
1710
    QVERIFY(calendar->setDate(testDate, 2000, 3, 1));
 
1711
    QCOMPARE(calendar->year(testDate), 2000);
 
1712
    QCOMPARE(calendar->month(testDate), 3);
 
1713
    QCOMPARE(calendar->day(testDate), 1);
 
1714
    QCOMPARE(calendar->daysInYear(testDate), 366);
 
1715
 
 
1716
    QDate newDate = calendar->addYears(testDate, 4);
 
1717
    QCOMPARE(newDate.year(), 2004);
 
1718
    QCOMPARE(calendar->daysInYear(newDate), 366);
 
1719
 
 
1720
    newDate = calendar->addMonths(testDate, -4);
 
1721
    QCOMPARE(newDate.year(), 1999);
 
1722
    QCOMPARE(newDate.month(), 11);
 
1723
    QCOMPARE(newDate.day(), 1);
 
1724
 
 
1725
    newDate = calendar->addDays(newDate, 20);
 
1726
    QCOMPARE(newDate.year(), 1999);
 
1727
    QCOMPARE(newDate.month(), 11);
 
1728
    QCOMPARE(newDate.day(), 21);
1709
1729
 
1710
1730
    delete calendar;
1711
1731
}
1712
1732
 
1713
1733
void KCalendarTest::testJapaneseBasic()
1714
1734
{
1715
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
 
1735
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JapaneseCalendar);
1716
1736
    QDate testDate;
1717
1737
 
1718
 
    testCalendarSystemType( calendar, KLocale::JapaneseCalendar, "japanese", "Japanese" );
1719
 
 
1720
 
    QCOMPARE( calendar->epoch(), QDate::fromJulianDay( 1721426 ) );
1721
 
    QCOMPARE( calendar->earliestValidDate(), QDate::fromJulianDay( 1721426 ) );
1722
 
    QCOMPARE( calendar->latestValidDate(), QDate( 9999, 12, 31 ) );
1723
 
 
1724
 
    testValid( calendar, 0, 10000, 13, 32, QDate( -5000, 1, 1 ) );
1725
 
 
1726
 
    QCOMPARE( calendar->isLeapYear( 2007 ), false );
1727
 
    QCOMPARE( calendar->isLeapYear( 2008 ), true );
1728
 
    QCOMPARE( calendar->isLeapYear( 1900 ), false );
1729
 
    QCOMPARE( calendar->isLeapYear( 2000 ), true );
1730
 
    QCOMPARE( calendar->isLeapYear( QDate( 2007, 1, 1 ) ), false );
1731
 
    QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), true );
1732
 
 
1733
 
    QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1734
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1735
 
 
1736
 
    testDate = QDate( 2007, 7, 9 ); // 2007-07-09
1737
 
    testYear(  calendar, testDate, 2007, "07", "2007" );
1738
 
    testMonth( calendar, testDate,    7, "7",  "07" );
1739
 
    testDay(   calendar, testDate,    9, "9",  "09" );
1740
 
 
1741
 
    testEraDate( calendar, testDate,   19, "19", "0019", "Heisei", "Heisei" );
1742
 
 
1743
 
    testWeekDayName( calendar, 6, QDate( 2007, 7, 28 ), "Sat", "Saturday" );
1744
 
    testMonthName( calendar, 12, 2007, QDate( 2007, 12, 20 ), "Dec", "December", "of Dec", "of December" );
1745
 
 
1746
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1747
 
 
1748
 
    QCOMPARE( calendar->weekStartDay(), 1 );
1749
 
    QCOMPARE( calendar->weekDayOfPray(), 7 );
1750
 
 
1751
 
    QCOMPARE( calendar->isProleptic(), false );
1752
 
    QCOMPARE( calendar->isLunar(), false );
1753
 
    QCOMPARE( calendar->isLunisolar(), false );
1754
 
    QCOMPARE( calendar->isSolar(), true );
1755
 
 
1756
 
    testRoundTrip( calendar );
 
1738
    testCalendarSystemType(calendar, KLocale::JapaneseCalendar, "japanese", "Japanese");
 
1739
 
 
1740
    QCOMPARE(calendar->epoch(), QDate::fromJulianDay(1721426));
 
1741
    QCOMPARE(calendar->earliestValidDate(), QDate::fromJulianDay(1721426));
 
1742
    QCOMPARE(calendar->latestValidDate(), QDate(9999, 12, 31));
 
1743
 
 
1744
    testValid(calendar, 0, 10000, 13, 32, QDate(-5000, 1, 1));
 
1745
 
 
1746
    QCOMPARE(calendar->isLeapYear(2007), false);
 
1747
    QCOMPARE(calendar->isLeapYear(2008), true);
 
1748
    QCOMPARE(calendar->isLeapYear(1900), false);
 
1749
    QCOMPARE(calendar->isLeapYear(2000), true);
 
1750
    QCOMPARE(calendar->isLeapYear(QDate(2007, 1, 1)), false);
 
1751
    QCOMPARE(calendar->isLeapYear(QDate(2008, 1, 1)), true);
 
1752
 
 
1753
    QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
 
1754
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1755
 
 
1756
    testDate = QDate(2007, 7, 9);   // 2007-07-09
 
1757
    testYear(calendar, testDate, 2007, "07", "2007");
 
1758
    testMonth(calendar, testDate,    7, "7",  "07");
 
1759
    testDay(calendar, testDate,    9, "9",  "09");
 
1760
 
 
1761
    testEraDate(calendar, testDate,   19, "19", "0019", "Heisei", "Heisei");
 
1762
 
 
1763
    testWeekDayName(calendar, 6, QDate(2007, 7, 28), "S", "Sat", "Saturday");
 
1764
    testMonthName(calendar, 12, 2007, QDate(2007, 12, 20), "D", "Dec", "December", "of Dec", "of December");
 
1765
 
 
1766
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1767
 
 
1768
    QCOMPARE(calendar->weekStartDay(), 1);
 
1769
    QCOMPARE(calendar->weekDayOfPray(), 7);
 
1770
 
 
1771
    QCOMPARE(calendar->isProleptic(), false);
 
1772
    QCOMPARE(calendar->isLunar(), false);
 
1773
    QCOMPARE(calendar->isLunisolar(), false);
 
1774
    QCOMPARE(calendar->isSolar(), true);
 
1775
 
 
1776
    testRoundTrip(calendar);
1757
1777
 
1758
1778
    delete calendar;
1759
1779
}
1760
1780
 
1761
1781
void KCalendarTest::testJapaneseYmd()
1762
1782
{
1763
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1764
 
    testYmd( calendar, 2007, 1, 1, QDate( 2007, 1, 1 ).toJulianDay() );
 
1783
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JapaneseCalendar);
 
1784
    testYmd(calendar, 2007, 1, 1, QDate(2007, 1, 1).toJulianDay());
1765
1785
    delete calendar;
1766
1786
}
1767
1787
 
1768
1788
void KCalendarTest::testJapaneseSpecialCases()
1769
1789
{
1770
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
 
1790
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JapaneseCalendar);
1771
1791
 
1772
1792
    // Test Japanese Eras
1773
1793
    // Heisei > 1        1990-01-01 onwards
1780
1800
    // Meiji 1 (Gannen)  1868-09-08 to 1868-12-31
1781
1801
    // Gregorian         0001-01-01 to 1868-09-07
1782
1802
 
1783
 
    testEraDate( calendar, QDate( 1990,  1,  1 ),    2,    "2", "0002", "Heisei", "Heisei" );
1784
 
    testEraDate( calendar, QDate( 1989,  1,  8 ),    1,    "1", "0001", "Heisei", "Heisei" );
 
1803
    testEraDate(calendar, QDate(1990,  1,  1),    2,    "2", "0002", "Heisei", "Heisei");
 
1804
    testEraDate(calendar, QDate(1989,  1,  8),    1,    "1", "0001", "Heisei", "Heisei");
1785
1805
    //testEraDate( calendar, QDate( 1989,  1,  7 ),   64,   "64", "0064", "Sh��wa",  "Sh��wa" );
1786
1806
    //testEraDate( calendar, QDate( 1927,  1,  1 ),    2,    "2", "0002", "Sh��wa",  "Sh��wa" );
1787
1807
    //testEraDate( calendar, QDate( 1926, 12, 25 ),    1,    "1", "0001", "Sh��wa",  "Sh��wa" );
1788
1808
    //testEraDate( calendar, QDate( 1926, 12, 24 ),   15,   "15", "0015", "Taish��", "Taish��" );
1789
1809
    //testEraDate( calendar, QDate( 1913,  1,  1 ),    2,    "2", "0002", "Taish��", "Taish��" );
1790
1810
    //testEraDate( calendar, QDate( 1912,  7, 30 ),    1,    "1", "0001", "Taish��", "Taish��" );
1791
 
    testEraDate( calendar, QDate( 1912,  7, 29 ),   45,   "45", "0045", "Meiji",  "Meiji" );
1792
 
    testEraDate( calendar, QDate( 1869,  1,  1 ),    2,    "2", "0002", "Meiji",  "Meiji" );
1793
 
    testEraDate( calendar, QDate( 1868,  9,  8 ),    1,    "1", "0001", "Meiji",  "Meiji" );
1794
 
    testEraDate( calendar, QDate( 1868,  9,  7 ), 1868, "1868", "1868", "AD",     "Anno Domini" );
 
1811
    testEraDate(calendar, QDate(1912,  7, 29),   45,   "45", "0045", "Meiji",  "Meiji");
 
1812
    testEraDate(calendar, QDate(1869,  1,  1),    2,    "2", "0002", "Meiji",  "Meiji");
 
1813
    testEraDate(calendar, QDate(1868,  9,  8),    1,    "1", "0001", "Meiji",  "Meiji");
 
1814
    testEraDate(calendar, QDate(1868,  9,  7), 1868, "1868", "1868", "AD",     "Anno Domini");
1795
1815
 
1796
1816
    // Should always be able to read Gannen as year 1
1797
 
    QCOMPARE( calendar->readDate( "1 2 Heisei 1", "%e %n %EC %Ey" ), QDate( 1989, 2, 1 ) );
1798
 
    QCOMPARE( calendar->readDate( "1 2 Heisei 1", "%e %n %EY" ), QDate( 1989, 2, 1 ) );
1799
 
    QCOMPARE( calendar->readDate( "1 2 Heisei Gannen", "%e %n %EC %Ey" ), QDate( 1989, 2, 1 ) );
1800
 
    QCOMPARE( calendar->readDate( "1 2 Heisei Gannen", "%e %n %EY" ), QDate( 1989, 2, 1 ) );
 
1817
    QCOMPARE(calendar->readDate("1 2 Heisei 1", "%e %n %EC %Ey"), QDate(1989, 2, 1));
 
1818
    QCOMPARE(calendar->readDate("1 2 Heisei 1", "%e %n %EY"), QDate(1989, 2, 1));
 
1819
    QCOMPARE(calendar->readDate("1 2 Heisei Gannen", "%e %n %EC %Ey"), QDate(1989, 2, 1));
 
1820
    QCOMPARE(calendar->readDate("1 2 Heisei Gannen", "%e %n %EY"), QDate(1989, 2, 1));
1801
1821
 
1802
1822
    // Should only format Gannen if defined in %EY format, never for %Ey
1803
 
    QCOMPARE( calendar->formatDate( QDate( 1989, 2, 1 ), "%e %n %EC %Ey"), QString( "1 2 Heisei 1" ) );
1804
 
    QCOMPARE( calendar->formatDate( QDate( 1989, 2, 1 ), "%e %n %EY"),     QString( "1 2 Heisei Gannen" ) );
1805
 
    QCOMPARE( calendar->formatDate( QDate( 1990, 2, 1 ), "%e %n %EC %Ey"), QString( "1 2 Heisei 2" ) );
1806
 
    QCOMPARE( calendar->formatDate( QDate( 1990, 2, 1 ), "%e %n %EY"),     QString( "1 2 Heisei 2" ) );
 
1823
    QCOMPARE(calendar->formatDate(QDate(1989, 2, 1), "%e %n %EC %Ey"), QString("1 2 Heisei 1"));
 
1824
    QCOMPARE(calendar->formatDate(QDate(1989, 2, 1), "%e %n %EY"),     QString("1 2 Heisei Gannen"));
 
1825
    QCOMPARE(calendar->formatDate(QDate(1990, 2, 1), "%e %n %EC %Ey"), QString("1 2 Heisei 2"));
 
1826
    QCOMPARE(calendar->formatDate(QDate(1990, 2, 1), "%e %n %EY"),     QString("1 2 Heisei 2"));
1807
1827
 
1808
1828
    delete calendar;
1809
1829
}
1810
1830
 
1811
1831
void KCalendarTest::testMinguoBasic()
1812
1832
{
1813
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::MinguoCalendar );
1814
 
 
1815
 
    testCalendarSystemType( calendar, KLocale::MinguoCalendar, "minguo", "Taiwanese" );
1816
 
 
1817
 
    QCOMPARE( calendar->epoch(), QDate( 1912, 1, 1 ) );
1818
 
    QCOMPARE( calendar->earliestValidDate(), QDate( 1912, 1, 1 ) );
1819
 
    QCOMPARE( calendar->latestValidDate(), QDate( 11910, 12, 31 ) );
1820
 
 
1821
 
    testValid( calendar, -1, 10000, 13, 32, QDate() );
1822
 
 
1823
 
    QCOMPARE( calendar->isLeapYear( 2007 - 1911 ), false );
1824
 
    QCOMPARE( calendar->isLeapYear( 2008 - 1911 ), true );
1825
 
    QCOMPARE( calendar->isLeapYear( 1900 - 1911 ), false );
1826
 
    QCOMPARE( calendar->isLeapYear( 2000 - 1911 ), true );
1827
 
    QCOMPARE( calendar->isLeapYear( QDate( 2007, 1, 1 ) ), false );
1828
 
    QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), true );
1829
 
 
1830
 
    QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1831
 
 
1832
 
    QCOMPARE( calendar->monthsInYear( 2007 - 1911 ),         12 );
1833
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1834
 
 
1835
 
    testYear(  calendar, QDate( 2007, 7, 9 ), 2007 - 1911, QString("96"), QString("0096") );
1836
 
    testMonth( calendar, QDate( 2007, 7, 9 ),    7, QString("7"),  QString("07") );
1837
 
    testDay(   calendar, QDate( 2007, 7, 9 ),    9, QString("9"),  QString("09") );
1838
 
 
1839
 
    testEraDate( calendar, QDate( 2007, 1, 1 ), 2007 - 1911, "96", "0096", "ROC", "Republic of China Era" );
1840
 
 
1841
 
    testWeekDayName( calendar, 6, QDate( 2007, 7, 28 ), "Sat", "Saturday" );
1842
 
    testMonthName( calendar, 12, 2007 - 1911, QDate( 2007, 12, 20 ), "Dec", "December", "of Dec", "of December" );
1843
 
 
1844
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1845
 
 
1846
 
    QCOMPARE( calendar->weekStartDay(), 1 );
1847
 
    QCOMPARE( calendar->weekDayOfPray(), 7 );
1848
 
 
1849
 
    QCOMPARE( calendar->isProleptic(), false );
1850
 
    QCOMPARE( calendar->isLunar(), false );
1851
 
    QCOMPARE( calendar->isLunisolar(), false );
1852
 
    QCOMPARE( calendar->isSolar(), true );
1853
 
 
1854
 
    testRoundTrip( calendar );
 
1833
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::MinguoCalendar);
 
1834
 
 
1835
    testCalendarSystemType(calendar, KLocale::MinguoCalendar, "minguo", "Taiwanese");
 
1836
 
 
1837
    QCOMPARE(calendar->epoch(), QDate(1912, 1, 1));
 
1838
    QCOMPARE(calendar->earliestValidDate(), QDate(1912, 1, 1));
 
1839
    QCOMPARE(calendar->latestValidDate(), QDate(11910, 12, 31));
 
1840
 
 
1841
    testValid(calendar, -1, 10000, 13, 32, QDate());
 
1842
 
 
1843
    QCOMPARE(calendar->isLeapYear(2007 - 1911), false);
 
1844
    QCOMPARE(calendar->isLeapYear(2008 - 1911), true);
 
1845
    QCOMPARE(calendar->isLeapYear(1900 - 1911), false);
 
1846
    QCOMPARE(calendar->isLeapYear(2000 - 1911), true);
 
1847
    QCOMPARE(calendar->isLeapYear(QDate(2007, 1, 1)), false);
 
1848
    QCOMPARE(calendar->isLeapYear(QDate(2008, 1, 1)), true);
 
1849
 
 
1850
    QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
 
1851
 
 
1852
    QCOMPARE(calendar->monthsInYear(2007 - 1911),         12);
 
1853
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1854
 
 
1855
    testYear(calendar, QDate(2007, 7, 9), 2007 - 1911, QString("96"), QString("0096"));
 
1856
    testMonth(calendar, QDate(2007, 7, 9),    7, QString("7"),  QString("07"));
 
1857
    testDay(calendar, QDate(2007, 7, 9),    9, QString("9"),  QString("09"));
 
1858
 
 
1859
    testEraDate(calendar, QDate(2007, 1, 1), 2007 - 1911, "96", "0096", "ROC", "Republic of China Era");
 
1860
 
 
1861
    testWeekDayName(calendar, 6, QDate(2007, 7, 28), "S", "Sat", "Saturday");
 
1862
    testMonthName(calendar, 12, 2007 - 1911, QDate(2007, 12, 20), "D", "Dec", "December", "of Dec", "of December");
 
1863
 
 
1864
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1865
 
 
1866
    QCOMPARE(calendar->weekStartDay(), 1);
 
1867
    QCOMPARE(calendar->weekDayOfPray(), 7);
 
1868
 
 
1869
    QCOMPARE(calendar->isProleptic(), false);
 
1870
    QCOMPARE(calendar->isLunar(), false);
 
1871
    QCOMPARE(calendar->isLunisolar(), false);
 
1872
    QCOMPARE(calendar->isSolar(), true);
 
1873
 
 
1874
    testRoundTrip(calendar);
1855
1875
 
1856
1876
    delete calendar;
1857
1877
}
1859
1879
 
1860
1880
void KCalendarTest::testThaiBasic()
1861
1881
{
1862
 
    const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::ThaiCalendar );
1863
 
 
1864
 
    testCalendarSystemType( calendar, KLocale::ThaiCalendar, "thai", "Thai" );
1865
 
 
1866
 
    QCOMPARE( calendar->epoch(), QDate( -544, 1, 7 ) );
1867
 
    QCOMPARE( calendar->earliestValidDate(), QDate( -544, 1, 7 ) );
1868
 
    QCOMPARE( calendar->latestValidDate(), QDate( 9456, 12, 31 ) );
1869
 
 
1870
 
    testValid( calendar, -1, 10000, 13, 32, QDate() );
1871
 
 
1872
 
    QCOMPARE( calendar->isLeapYear( 2007 + 543 ), false );
1873
 
    QCOMPARE( calendar->isLeapYear( 2008 + 543 ), true );
1874
 
    QCOMPARE( calendar->isLeapYear( 1900 + 543 ), false );
1875
 
    QCOMPARE( calendar->isLeapYear( 2000 + 543 ), true );
1876
 
    QCOMPARE( calendar->isLeapYear( QDate( 2007, 1, 1 ) ), false );
1877
 
    QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), true );
1878
 
 
1879
 
    QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1880
 
 
1881
 
    QCOMPARE( calendar->monthsInYear( 2007 + 543 ),          12 );
1882
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1883
 
 
1884
 
    testYear(  calendar, QDate( 2007, 7, 9 ), 2007 + 543, QString("50"), QString("2550") );
1885
 
    testMonth( calendar, QDate( 2007, 7, 9 ),    7, QString("7"),  QString("07") );
1886
 
    testDay(   calendar, QDate( 2007, 7, 9 ),    9, QString("9"),  QString("09") );
1887
 
 
1888
 
    testEraDate( calendar, QDate( 2007, 1, 1 ), 2007 + 543, "2550", "2550", "BE", "Buddhist Era" );
1889
 
 
1890
 
    testWeekDayName( calendar, 6, QDate( 2007, 7, 28 ), "Sat", "Saturday" );
1891
 
    testMonthName( calendar, 12, 2007 + 543, QDate( 2007, 12, 20 ), "Dec", "December", "of Dec", "of December" );
1892
 
 
1893
 
    QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1894
 
 
1895
 
    QCOMPARE( calendar->weekStartDay(), 1 );
1896
 
    QCOMPARE( calendar->weekDayOfPray(), 7 );
1897
 
 
1898
 
    QCOMPARE( calendar->isProleptic(), false );
1899
 
    QCOMPARE( calendar->isLunar(), false );
1900
 
    QCOMPARE( calendar->isLunisolar(), false );
1901
 
    QCOMPARE( calendar->isSolar(), true );
1902
 
 
1903
 
    testRoundTrip( calendar );
 
1882
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::ThaiCalendar);
 
1883
 
 
1884
    testCalendarSystemType(calendar, KLocale::ThaiCalendar, "thai", "Thai");
 
1885
 
 
1886
    QCOMPARE(calendar->epoch(), QDate(-544, 1, 7));
 
1887
    QCOMPARE(calendar->earliestValidDate(), QDate(-544, 1, 7));
 
1888
    QCOMPARE(calendar->latestValidDate(), QDate(9456, 12, 31));
 
1889
 
 
1890
    testValid(calendar, -1, 10000, 13, 32, QDate());
 
1891
 
 
1892
    QCOMPARE(calendar->isLeapYear(2007 + 543), false);
 
1893
    QCOMPARE(calendar->isLeapYear(2008 + 543), true);
 
1894
    QCOMPARE(calendar->isLeapYear(1900 + 543), false);
 
1895
    QCOMPARE(calendar->isLeapYear(2000 + 543), true);
 
1896
    QCOMPARE(calendar->isLeapYear(QDate(2007, 1, 1)), false);
 
1897
    QCOMPARE(calendar->isLeapYear(QDate(2008, 1, 1)), true);
 
1898
 
 
1899
    QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
 
1900
 
 
1901
    QCOMPARE(calendar->monthsInYear(2007 + 543),          12);
 
1902
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1903
 
 
1904
    testYear(calendar, QDate(2007, 7, 9), 2007 + 543, QString("50"), QString("2550"));
 
1905
    testMonth(calendar, QDate(2007, 7, 9),    7, QString("7"),  QString("07"));
 
1906
    testDay(calendar, QDate(2007, 7, 9),    9, QString("9"),  QString("09"));
 
1907
 
 
1908
    testEraDate(calendar, QDate(2007, 1, 1), 2007 + 543, "2550", "2550", "BE", "Buddhist Era");
 
1909
 
 
1910
    testWeekDayName(calendar, 6, QDate(2007, 7, 28), "S", "Sat", "Saturday");
 
1911
    testMonthName(calendar, 12, 2007 + 543, QDate(2007, 12, 20), "D", "Dec", "December", "of Dec", "of December");
 
1912
 
 
1913
    QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
 
1914
 
 
1915
    QCOMPARE(calendar->weekStartDay(), 1);
 
1916
    QCOMPARE(calendar->weekDayOfPray(), 7);
 
1917
 
 
1918
    QCOMPARE(calendar->isProleptic(), false);
 
1919
    QCOMPARE(calendar->isLunar(), false);
 
1920
    QCOMPARE(calendar->isLunisolar(), false);
 
1921
    QCOMPARE(calendar->isSolar(), true);
 
1922
 
 
1923
    testRoundTrip(calendar);
1904
1924
 
1905
1925
    delete calendar;
1906
1926
}
1907
1927
 
1908
1928
 
1909
1929
// generic test functions, call from calendar system specific ones
1910
 
void KCalendarTest::testCalendarSystemType( const KCalendarSystem *calendar,
1911
 
                                            KLocale::CalendarSystem system,
1912
 
                                            const QString &type, const QString &label )
 
1930
void KCalendarTest::testCalendarSystemType(const KCalendarSystem *calendar,
 
1931
                                           KLocale::CalendarSystem system,
 
1932
                                           const QString &type, const QString &label)
1913
1933
{
1914
 
    QCOMPARE( calendar->calendarType(),                 type );
1915
 
    QCOMPARE( calendar->calendarSystem(),               system );
1916
 
    QCOMPARE( calendar->calendarLabel(),                label );
1917
 
    QCOMPARE( KCalendarSystem::calendarLabel( type ),   label );
1918
 
    QCOMPARE( KCalendarSystem::calendarLabel( system ), label );
 
1934
    QCOMPARE(calendar->calendarType(system),         type);
 
1935
    QCOMPARE(calendar->calendarSystem(type),         system);
 
1936
    QCOMPARE(calendar->calendarType(),               type);
 
1937
    QCOMPARE(calendar->calendarSystem(),             system);
 
1938
    QCOMPARE(calendar->calendarLabel(),              label);
 
1939
    QCOMPARE(KCalendarSystem::calendarLabel(type),   label);
 
1940
    QCOMPARE(KCalendarSystem::calendarLabel(system), label);
1919
1941
}
1920
1942
 
1921
1943
// Simply tests valid ranges of ymd values, testYmd covers all other dates
1922
 
void KCalendarTest::testValid( const KCalendarSystem *calendar, int lowInvalidYear, int highInvalidYear,
1923
 
                               int highInvalidMonth, int highInvalidDay, const QDate &invalidDate )
 
1944
void KCalendarTest::testValid(const KCalendarSystem *calendar, int lowInvalidYear, int highInvalidYear,
 
1945
                              int highInvalidMonth, int highInvalidDay, const QDate &invalidDate)
1924
1946
{
1925
1947
    // min/max year
1926
 
    QCOMPARE( calendar->isValid( lowInvalidYear, 1, 1 ), false );
1927
 
    QCOMPARE( calendar->isValid( highInvalidYear, 1, 1 ), false );
 
1948
    QCOMPARE(calendar->isValid(lowInvalidYear, 1, 1), false);
 
1949
    QCOMPARE(calendar->isValid(highInvalidYear, 1, 1), false);
1928
1950
 
1929
1951
    // min/max month
1930
 
    QCOMPARE( calendar->isValid( 1, 0, 1 ), false );
1931
 
    QCOMPARE( calendar->isValid( 1, highInvalidMonth, 1 ), false );
 
1952
    QCOMPARE(calendar->isValid(1, 0, 1), false);
 
1953
    QCOMPARE(calendar->isValid(1, highInvalidMonth, 1), false);
1932
1954
 
1933
1955
    // min/max day
1934
 
    QCOMPARE( calendar->isValid( 1, 1, 0 ), false );
1935
 
    QCOMPARE( calendar->isValid( 1, 1, highInvalidDay ), false );
1936
 
 
1937
 
    QCOMPARE( calendar->isValid( 1, 1,  1 ), true );
1938
 
 
1939
 
    QCOMPARE( calendar->isValid( invalidDate ), false );
1940
 
    QCOMPARE( calendar->isValid( QDate( 2000, 1, 1 ) ), true );
 
1956
    QCOMPARE(calendar->isValid(1, 1, 0), false);
 
1957
    QCOMPARE(calendar->isValid(1, 1, highInvalidDay), false);
 
1958
 
 
1959
    QCOMPARE(calendar->isValid(1, 1,  1), true);
 
1960
 
 
1961
    QCOMPARE(calendar->isValid(invalidDate), false);
 
1962
    QCOMPARE(calendar->isValid(QDate(2000, 1, 1)), true);
1941
1963
}
1942
1964
 
1943
 
void KCalendarTest::testEpoch( const KCalendarSystem *calendar, int y, int m, int d, int jd )
 
1965
void KCalendarTest::testEpoch(const KCalendarSystem *calendar, int y, int m, int d, int jd)
1944
1966
{
1945
 
    QCOMPARE( calendar->epoch(), QDate::fromJulianDay( jd ) );
1946
 
    if ( calendar->epoch() >= calendar->earliestValidDate() ) {
1947
 
        testYmd( calendar, y, m, d, jd );
 
1967
    QCOMPARE(calendar->epoch(), QDate::fromJulianDay(jd));
 
1968
    if (calendar->epoch() >= calendar->earliestValidDate()) {
 
1969
        testYmd(calendar, y, m, d, jd);
1948
1970
    }
1949
1971
}
1950
1972
 
1951
 
void KCalendarTest::testEarliestValidDate( const KCalendarSystem *calendar, int y, int m, int d, int jd )
1952
 
{
1953
 
    QCOMPARE( calendar->earliestValidDate(), QDate::fromJulianDay( jd ) );
1954
 
    testYmd( calendar, y, m, d, jd );
1955
 
}
1956
 
 
1957
 
void KCalendarTest::testLatestValidDate( const KCalendarSystem *calendar, int y, int m, int d, int jd )
1958
 
{
1959
 
    QCOMPARE( calendar->latestValidDate(), QDate::fromJulianDay( jd ) );
1960
 
    testYmd( calendar, y, m, d, jd );
1961
 
}
1962
 
 
1963
 
void KCalendarTest::testYmd( const KCalendarSystem *calendar, int y, int m, int d, int jd )
1964
 
{
1965
 
    QDate testDate1 = QDate::fromJulianDay( jd );
1966
 
    QCOMPARE( calendar->year(  testDate1 ), y );
1967
 
    QCOMPARE( calendar->month( testDate1 ), m );
1968
 
    QCOMPARE( calendar->day(   testDate1 ), d );
 
1973
void KCalendarTest::testEarliestValidDate(const KCalendarSystem *calendar, int y, int m, int d, int jd)
 
1974
{
 
1975
    QCOMPARE(calendar->earliestValidDate(), QDate::fromJulianDay(jd));
 
1976
    testYmd(calendar, y, m, d, jd);
 
1977
}
 
1978
 
 
1979
void KCalendarTest::testLatestValidDate(const KCalendarSystem *calendar, int y, int m, int d, int jd)
 
1980
{
 
1981
    QCOMPARE(calendar->latestValidDate(), QDate::fromJulianDay(jd));
 
1982
    testYmd(calendar, y, m, d, jd);
 
1983
}
 
1984
 
 
1985
void KCalendarTest::testYmd(const KCalendarSystem *calendar, int y, int m, int d, int jd)
 
1986
{
 
1987
    QDate testDate1 = QDate::fromJulianDay(jd);
 
1988
    QCOMPARE(calendar->year(testDate1), y);
 
1989
    QCOMPARE(calendar->month(testDate1), m);
 
1990
    QCOMPARE(calendar->day(testDate1), d);
1969
1991
 
1970
1992
    QDate testDate2;
1971
 
    QVERIFY( calendar->setYMD( testDate2, y, m, d ) );
1972
 
    QCOMPARE( testDate1, testDate2 );
1973
 
}
1974
 
 
1975
 
void KCalendarTest::testYear( const KCalendarSystem *calendar, const QDate &date,
1976
 
                              int year, const QString &shortString, const QString &longString )
1977
 
{
1978
 
    QCOMPARE( calendar->year( date ), year );
1979
 
    QCOMPARE( calendar->yearString( date, KCalendarSystem::ShortFormat ), shortString );
1980
 
    QCOMPARE( calendar->yearString( date, KCalendarSystem::LongFormat ), longString );
1981
 
    int i;
1982
 
    QCOMPARE( calendar->yearStringToInteger( longString, i ), year );
1983
 
    QCOMPARE( i, longString.length() );
1984
 
}
1985
 
 
1986
 
void KCalendarTest::testMonth( const KCalendarSystem *calendar, const QDate &date,
1987
 
                               int month, const QString &shortString, const QString &longString )
1988
 
{
1989
 
    QCOMPARE( calendar->month( date ), month );
1990
 
    QCOMPARE( calendar->monthString( date, KCalendarSystem::ShortFormat ), shortString );
1991
 
    QCOMPARE( calendar->monthString( date, KCalendarSystem::LongFormat ), longString );
1992
 
    int i;
1993
 
    QCOMPARE( calendar->monthStringToInteger( longString, i ), month );
1994
 
    QCOMPARE( i, longString.length() );
1995
 
}
1996
 
 
1997
 
void KCalendarTest::testDay( const KCalendarSystem *calendar, const QDate &date,
1998
 
                             int day, const QString &shortString, const QString &longString )
1999
 
{
2000
 
    QCOMPARE( calendar->day( date ), day );
2001
 
    QCOMPARE( calendar->dayString( date, KCalendarSystem::ShortFormat ), shortString );
2002
 
    QCOMPARE( calendar->dayString( date, KCalendarSystem::LongFormat ), longString );
2003
 
    int i;
2004
 
    QCOMPARE( calendar->dayStringToInteger( longString, i ), day );
2005
 
    QCOMPARE( i, longString.length() );
2006
 
}
2007
 
 
2008
 
void KCalendarTest::testEraDate( const KCalendarSystem *calendar, const QDate &date,
2009
 
                                 int yearInEra, const QString &shortYearInEraString, const QString &longYearInEraString,
2010
 
                                 const QString &shortEraName, const QString &longEraName )
2011
 
{
2012
 
    QCOMPARE( calendar->yearInEra( date ),                                     yearInEra );
2013
 
    QCOMPARE( calendar->yearInEraString( date ),                               shortYearInEraString );
2014
 
    QCOMPARE( calendar->yearInEraString( date, KCalendarSystem::ShortFormat ), shortYearInEraString );
2015
 
    QCOMPARE( calendar->yearInEraString( date, KCalendarSystem::LongFormat ),  longYearInEraString );
2016
 
    QCOMPARE( calendar->eraName( date ),                                       shortEraName );
2017
 
    QCOMPARE( calendar->eraName( date, KCalendarSystem::ShortFormat ),         shortEraName );
2018
 
    QCOMPARE( calendar->eraName( date, KCalendarSystem::LongFormat ),          longEraName );
 
1993
    QVERIFY(calendar->setDate(testDate2, y, m, d));
 
1994
    QCOMPARE(testDate1, testDate2);
 
1995
}
 
1996
 
 
1997
void KCalendarTest::testYear(const KCalendarSystem *calendar, const QDate &date,
 
1998
                             int year, const QString &shortString, const QString &longString)
 
1999
{
 
2000
    QCOMPARE(calendar->year(date), year);
 
2001
    QCOMPARE(calendar->yearString(date, KCalendarSystem::ShortFormat), shortString);
 
2002
    QCOMPARE(calendar->yearString(date, KCalendarSystem::LongFormat), longString);
 
2003
    int i;
 
2004
    QCOMPARE(calendar->yearStringToInteger(longString, i), year);
 
2005
    QCOMPARE(i, longString.length());
 
2006
}
 
2007
 
 
2008
void KCalendarTest::testMonth(const KCalendarSystem *calendar, const QDate &date,
 
2009
                              int month, const QString &shortString, const QString &longString)
 
2010
{
 
2011
    QCOMPARE(calendar->month(date), month);
 
2012
    QCOMPARE(calendar->monthString(date, KCalendarSystem::ShortFormat), shortString);
 
2013
    QCOMPARE(calendar->monthString(date, KCalendarSystem::LongFormat), longString);
 
2014
    int i;
 
2015
    QCOMPARE(calendar->monthStringToInteger(longString, i), month);
 
2016
    QCOMPARE(i, longString.length());
 
2017
}
 
2018
 
 
2019
void KCalendarTest::testDay(const KCalendarSystem *calendar, const QDate &date,
 
2020
                            int day, const QString &shortString, const QString &longString)
 
2021
{
 
2022
    QCOMPARE(calendar->day(date), day);
 
2023
    QCOMPARE(calendar->dayString(date, KCalendarSystem::ShortFormat), shortString);
 
2024
    QCOMPARE(calendar->dayString(date, KCalendarSystem::LongFormat), longString);
 
2025
    int i;
 
2026
    QCOMPARE(calendar->dayStringToInteger(longString, i), day);
 
2027
    QCOMPARE(i, longString.length());
 
2028
}
 
2029
 
 
2030
void KCalendarTest::testEraDate(const KCalendarSystem *calendar, const QDate &date,
 
2031
                                int yearInEra, const QString &shortYearInEraString, const QString &longYearInEraString,
 
2032
                                const QString &shortEraName, const QString &longEraName)
 
2033
{
 
2034
    QCOMPARE(calendar->yearInEra(date),                                     yearInEra);
 
2035
    QCOMPARE(calendar->yearInEraString(date),                               shortYearInEraString);
 
2036
    QCOMPARE(calendar->yearInEraString(date, KCalendarSystem::ShortFormat), shortYearInEraString);
 
2037
    QCOMPARE(calendar->yearInEraString(date, KCalendarSystem::LongFormat),  longYearInEraString);
 
2038
    QCOMPARE(calendar->eraName(date),                                       shortEraName);
 
2039
    QCOMPARE(calendar->eraName(date, KCalendarSystem::ShortFormat),         shortEraName);
 
2040
    QCOMPARE(calendar->eraName(date, KCalendarSystem::LongFormat),          longEraName);
2019
2041
}
2020
2042
 
2021
2043
// Pass in the week day number, the equivalent QDate, and the short and long day names
2022
2044
//  e.g. testWeekDayName( cal, 6, QDate(y,m,d), QString("Monday"), QString("Mon") )
2023
2045
 
2024
 
void KCalendarTest::testWeekDayName( const KCalendarSystem *calendar, int weekDay, const QDate &date,
2025
 
                                     const QString & shortName, const QString & longName )
 
2046
void KCalendarTest::testWeekDayName(const KCalendarSystem *calendar, int weekDay, const QDate &date,
 
2047
                                    const QString &narrowName, const QString & shortName, const QString & longName)
2026
2048
{
2027
 
    QCOMPARE( calendar->weekDayName( weekDay, KCalendarSystem::ShortDayName ), shortName );
2028
 
    QCOMPARE( calendar->weekDayName( weekDay, KCalendarSystem::LongDayName ), longName );
2029
 
    QCOMPARE( calendar->weekDayName( weekDay ), longName );
 
2049
    QCOMPARE(calendar->weekDayName(weekDay, KCalendarSystem::ShortDayName), shortName);
 
2050
    QCOMPARE(calendar->weekDayName(weekDay, KCalendarSystem::LongDayName), longName);
 
2051
    QCOMPARE(calendar->weekDayName(weekDay), longName);
2030
2052
 
2031
2053
    // Test week day < min
2032
 
    QCOMPARE( calendar->weekDayName( 0, KCalendarSystem::ShortDayName ), QString() );
2033
 
    QCOMPARE( calendar->weekDayName( 0, KCalendarSystem::LongDayName ), QString() );
 
2054
    QCOMPARE(calendar->weekDayName(0, KCalendarSystem::ShortDayName), QString());
 
2055
    QCOMPARE(calendar->weekDayName(0, KCalendarSystem::LongDayName), QString());
2034
2056
 
2035
2057
    // Test week day > max
2036
 
    QCOMPARE( calendar->weekDayName( calendar->daysInWeek( date ) + 1, KCalendarSystem::ShortDayName ), QString() );
2037
 
    QCOMPARE( calendar->weekDayName( calendar->daysInWeek( date ) + 1, KCalendarSystem::LongDayName ), QString() );
 
2058
    QCOMPARE(calendar->weekDayName(calendar->daysInWeek(date) + 1, KCalendarSystem::ShortDayName), QString());
 
2059
    QCOMPARE(calendar->weekDayName(calendar->daysInWeek(date) + 1, KCalendarSystem::LongDayName), QString());
2038
2060
 
2039
2061
    // QDate parameter tests, so always in valid range
2040
 
    QCOMPARE( calendar->weekDayName( date, KCalendarSystem::ShortDayName ), shortName );
2041
 
    QCOMPARE( calendar->weekDayName( date, KCalendarSystem::LongDayName ), longName );
2042
 
    QCOMPARE( calendar->weekDayName( date ), longName );
 
2062
    QCOMPARE(calendar->weekDayName(date, KCalendarSystem::ShortDayName), shortName);
 
2063
    QCOMPARE(calendar->weekDayName(date, KCalendarSystem::LongDayName), longName);
 
2064
    QCOMPARE(calendar->weekDayName(date), longName);
 
2065
 
 
2066
    // Test format date componant
 
2067
    QCOMPARE(calendar->formatDate(date, KLocale::DayOfWeekName, KLocale::NarrowName), narrowName);
 
2068
    QCOMPARE(calendar->formatDate(date, KLocale::DayOfWeekName, KLocale::ShortName), shortName);
 
2069
    QCOMPARE(calendar->formatDate(date, KLocale::DayOfWeekName, KLocale::LongName), longName);
2043
2070
}
2044
2071
 
2045
 
void KCalendarTest::testMonthName( const KCalendarSystem *calendar, int month, int year, const QDate &date,
2046
 
                                   const QString &shortName, const QString &longName,
2047
 
                                   const QString &shortNamePossessive, const QString &longNamePossessive )
 
2072
void KCalendarTest::testMonthName(const KCalendarSystem *calendar, int month, int year, const QDate &date,
 
2073
                                  const QString &narrowName, const QString &shortName, const QString &longName,
 
2074
                                  const QString &shortNamePossessive, const QString &longNamePossessive)
2048
2075
{
2049
 
    QCOMPARE( calendar->monthName( month, year, KCalendarSystem::ShortName ), shortName );
2050
 
    QCOMPARE( calendar->monthName( month, year, KCalendarSystem::LongName ), longName );
2051
 
    QCOMPARE( calendar->monthName( month, year, KCalendarSystem::ShortNamePossessive ),
2052
 
              shortNamePossessive );
2053
 
    QCOMPARE( calendar->monthName( month, year, KCalendarSystem::LongNamePossessive ),
2054
 
              longNamePossessive );
2055
 
    QCOMPARE( calendar->monthName( month, year ), longName );
 
2076
    QCOMPARE(calendar->monthName(month, year, KCalendarSystem::ShortName), shortName);
 
2077
    QCOMPARE(calendar->monthName(month, year, KCalendarSystem::LongName), longName);
 
2078
    QCOMPARE(calendar->monthName(month, year, KCalendarSystem::ShortNamePossessive),
 
2079
             shortNamePossessive);
 
2080
    QCOMPARE(calendar->monthName(month, year, KCalendarSystem::LongNamePossessive),
 
2081
             longNamePossessive);
 
2082
    QCOMPARE(calendar->monthName(month, year), longName);
2056
2083
 
2057
2084
    // Test month < min
2058
 
    QCOMPARE( calendar->monthName( 0, year, KCalendarSystem::ShortName ), QString() );
2059
 
    QCOMPARE( calendar->monthName( 0, year, KCalendarSystem::LongName ),  QString() );
2060
 
    QCOMPARE( calendar->monthName( 0, year, KCalendarSystem::ShortName ), QString() );
2061
 
    QCOMPARE( calendar->monthName( 0, year, KCalendarSystem::LongName ),  QString() );
 
2085
    QCOMPARE(calendar->monthName(0, year, KCalendarSystem::ShortName), QString());
 
2086
    QCOMPARE(calendar->monthName(0, year, KCalendarSystem::LongName),  QString());
 
2087
    QCOMPARE(calendar->monthName(0, year, KCalendarSystem::ShortName), QString());
 
2088
    QCOMPARE(calendar->monthName(0, year, KCalendarSystem::LongName),  QString());
2062
2089
 
2063
2090
    // Test month > max
2064
 
    QCOMPARE( calendar->monthName( calendar->monthsInYear( date ) + 1, year,
2065
 
                                   KCalendarSystem::ShortName ), QString() );
2066
 
    QCOMPARE( calendar->monthName( calendar->monthsInYear( date ) + 1, year,
2067
 
                                   KCalendarSystem::LongName ), QString() );
2068
 
    QCOMPARE( calendar->monthName( calendar->monthsInYear( date ) + 1, year,
2069
 
                                   KCalendarSystem::ShortName ), QString() );
2070
 
    QCOMPARE( calendar->monthName( calendar->monthsInYear( date ) + 1, year,
2071
 
                                   KCalendarSystem::LongName ), QString() );
 
2091
    QCOMPARE(calendar->monthName(calendar->monthsInYear(date) + 1, year,
 
2092
                                 KCalendarSystem::ShortName), QString());
 
2093
    QCOMPARE(calendar->monthName(calendar->monthsInYear(date) + 1, year,
 
2094
                                 KCalendarSystem::LongName), QString());
 
2095
    QCOMPARE(calendar->monthName(calendar->monthsInYear(date) + 1, year,
 
2096
                                 KCalendarSystem::ShortName), QString());
 
2097
    QCOMPARE(calendar->monthName(calendar->monthsInYear(date) + 1, year,
 
2098
                                 KCalendarSystem::LongName), QString());
2072
2099
 
2073
2100
    // QDate parameter tests, so always in valid range
2074
 
    QCOMPARE( calendar->monthName( date, KCalendarSystem::ShortName ), shortName );
2075
 
    QCOMPARE( calendar->monthName( date, KCalendarSystem::LongName ), longName );
2076
 
    QCOMPARE( calendar->monthName( date, KCalendarSystem::ShortNamePossessive ),
2077
 
              shortNamePossessive );
2078
 
    QCOMPARE( calendar->monthName( date, KCalendarSystem::LongNamePossessive ),
2079
 
              longNamePossessive );
2080
 
    QCOMPARE( calendar->monthName( date ), longName );
 
2101
    QCOMPARE(calendar->monthName(date, KCalendarSystem::ShortName), shortName);
 
2102
    QCOMPARE(calendar->monthName(date, KCalendarSystem::LongName), longName);
 
2103
    QCOMPARE(calendar->monthName(date, KCalendarSystem::ShortNamePossessive),
 
2104
             shortNamePossessive);
 
2105
    QCOMPARE(calendar->monthName(date, KCalendarSystem::LongNamePossessive),
 
2106
             longNamePossessive);
 
2107
    QCOMPARE(calendar->monthName(date), longName);
 
2108
 
 
2109
    // Test format date componant
 
2110
    QCOMPARE(calendar->formatDate(date, KLocale::MonthName, KLocale::NarrowName), narrowName);
 
2111
    QCOMPARE(calendar->formatDate(date, KLocale::MonthName, KLocale::ShortName), shortName);
 
2112
    QCOMPARE(calendar->formatDate(date, KLocale::MonthName, KLocale::LongName), longName);
2081
2113
}
2082
2114
 
2083
 
void KCalendarTest::testRoundTrip( const KCalendarSystem *calendar, bool testFullRange )
 
2115
void KCalendarTest::testRoundTrip(const KCalendarSystem *calendar, bool testFullRange)
2084
2116
{
2085
 
    kDebug() << "Testing round trip of dates for Calendar System " << calendar->calendarType();
 
2117
    kDebug() << "Testing round trip of dates for Calendar System " << calendar->calendarLabel();
2086
2118
    kDebug() << "This may take some time, or you may have created an infinite loop.";
2087
2119
    kDebug() << "Uncomment the loop debug message to see each date comparison.";
2088
2120
 
2091
2123
    // Limit to a short interesting date range for regular testing
2092
2124
    // Later add an Env var to choose full test whenever the formulas are changed.
2093
2125
    QDate loopDate, terminateDate;
2094
 
    if ( testFullRange ) {
 
2126
    if (testFullRange) {
2095
2127
        loopDate = calendar->earliestValidDate();
2096
2128
        terminateDate = calendar->latestValidDate();
2097
2129
    } else {
2099
2131
        terminateDate = qMin(QDate(2020, 1, 1), calendar->latestValidDate());
2100
2132
    }
2101
2133
    QByteArray msg;
2102
 
    while ( loopDate <= terminateDate ) {
2103
 
        testYear = calendar->year( loopDate );
2104
 
        testMonth = calendar->month( loopDate );
2105
 
        testDay = calendar->day( loopDate );
2106
 
        calendar->setDate( testDate, testYear, testMonth, testDay );
 
2134
    while (loopDate <= terminateDate) {
 
2135
        testYear = calendar->year(loopDate);
 
2136
        testMonth = calendar->month(loopDate);
 
2137
        testDay = calendar->day(loopDate);
 
2138
        calendar->setDate(testDate, testYear, testMonth, testDay);
2107
2139
        // Uncomment this to see each comparison printed
2108
2140
        // or
2109
2141
        // Uncomment the QEXPECT_FAIL statements to check all dates regardless of occasional failures
2110
 
        QByteArray msg = QByteArray::number( loopDate.toJulianDay() ) + " = " +
2111
 
                         QByteArray::number( testYear ) + '-' +
2112
 
                         QByteArray::number( testMonth ) + '-' +
2113
 
                         QByteArray::number( testDay ) + " = " +
2114
 
                         QByteArray::number( testDate.toJulianDay() );
 
2142
        QByteArray msg = QByteArray::number(loopDate.toJulianDay()) + " = " +
 
2143
                         QByteArray::number(testYear) + '-' +
 
2144
                         QByteArray::number(testMonth) + '-' +
 
2145
                         QByteArray::number(testDay) + " = " +
 
2146
                         QByteArray::number(testDate.toJulianDay());
2115
2147
        /*
2116
2148
        kDebug() << msg;
2117
2149
        */
2118
 
        if ( testMonth <= 0 || testDay <= 0 ) { // year <= 0 is OK
2119
 
            msg.prepend( "Round Trip : JD to Date failed : " );
2120
 
            QEXPECT_FAIL( "", msg.data(), Continue );
2121
 
        } else if ( testDate.toJulianDay() == 0 ) {
2122
 
            msg.prepend( "Round Trip : Date to JD failed : " );
2123
 
            QEXPECT_FAIL( "", msg.data(), Continue );
2124
 
        } else if ( loopDate != testDate ) {
2125
 
            msg.prepend( "Round Trip : JD's differ       : " );
2126
 
            QEXPECT_FAIL( "", msg.data(), Continue );
 
2150
        if (testMonth <= 0 || testDay <= 0) {   // year <= 0 is OK
 
2151
            msg.prepend("Round Trip : JD to Date failed : ");
 
2152
            QEXPECT_FAIL("", msg.data(), Continue);
 
2153
        } else if (testDate.toJulianDay() == 0) {
 
2154
            msg.prepend("Round Trip : Date to JD failed : ");
 
2155
            QEXPECT_FAIL("", msg.data(), Continue);
 
2156
        } else if (loopDate != testDate) {
 
2157
            msg.prepend("Round Trip : JD's differ       : ");
 
2158
            QEXPECT_FAIL("", msg.data(), Continue);
2127
2159
        }
2128
 
        QCOMPARE( loopDate.toJulianDay(), testDate.toJulianDay() );
 
2160
        QCOMPARE(loopDate.toJulianDay(), testDate.toJulianDay());
2129
2161
        loopDate = loopDate.addDays(1);
2130
2162
    }
2131
2163
}
2135
2167
 
2136
2168
void KCalendarTest::testQDateYearMonthDay()
2137
2169
{
2138
 
    const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
2139
 
 
2140
 
    testQDateYMD( calendar, 2000,  1,  1 );
2141
 
    testQDateYMD( calendar, 2000,  2, 28 );
2142
 
    testQDateYMD( calendar, 2000,  2, 29 );
2143
 
    testQDateYMD( calendar, 2000, 6, 15 );
2144
 
    testQDateYMD( calendar, 2000, 12, 31 );
2145
 
 
2146
 
    testQDateYMD( calendar, 9999,  1,  1 );
2147
 
    testQDateYMD( calendar, 9999,  6, 15 );
2148
 
    testQDateYMD( calendar, 9999, 12, 31 );
2149
 
 
2150
 
    testQDateYMD( calendar,    1,  1,  1 );
2151
 
    testQDateYMD( calendar,    1,  6, 15 );
2152
 
    testQDateYMD( calendar,    1, 12, 31 );
2153
 
 
2154
 
    testQDateYMD( calendar, -4712,  1,  2 );
2155
 
    testQDateYMD( calendar, -4712,  6, 15 );
2156
 
    testQDateYMD( calendar, -4712, 12, 31 );
 
2170
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
 
2171
 
 
2172
    testQDateYMD(calendar, 2000,  1,  1);
 
2173
    testQDateYMD(calendar, 2000,  2, 28);
 
2174
    testQDateYMD(calendar, 2000,  2, 29);
 
2175
    testQDateYMD(calendar, 2000, 6, 15);
 
2176
    testQDateYMD(calendar, 2000, 12, 31);
 
2177
 
 
2178
    testQDateYMD(calendar, 9999,  1,  1);
 
2179
    testQDateYMD(calendar, 9999,  6, 15);
 
2180
    testQDateYMD(calendar, 9999, 12, 31);
 
2181
 
 
2182
    testQDateYMD(calendar,    1,  1,  1);
 
2183
    testQDateYMD(calendar,    1,  6, 15);
 
2184
    testQDateYMD(calendar,    1, 12, 31);
 
2185
 
 
2186
    testQDateYMD(calendar, -4712,  1,  2);
 
2187
    testQDateYMD(calendar, -4712,  6, 15);
 
2188
    testQDateYMD(calendar, -4712, 12, 31);
2157
2189
 
2158
2190
    delete calendar;
2159
2191
}
2160
2192
 
2161
 
void KCalendarTest::testQDateYMD( const KCalendarSystem *calendar, int y, int m, int d )
 
2193
void KCalendarTest::testQDateYMD(const KCalendarSystem *calendar, int y, int m, int d)
2162
2194
{
2163
2195
    QDate testDate;
2164
2196
 
2165
 
    calendar->setDate( testDate, y, m, d );
2166
 
    QCOMPARE( calendar->year( testDate ),  testDate.year() );
2167
 
    QCOMPARE( calendar->month( testDate ), testDate.month() );
2168
 
    QCOMPARE( calendar->day( testDate ),   testDate.day() );
 
2197
    calendar->setDate(testDate, y, m, d);
 
2198
    QCOMPARE(calendar->year(testDate),  testDate.year());
 
2199
    QCOMPARE(calendar->month(testDate), testDate.month());
 
2200
    QCOMPARE(calendar->day(testDate),   testDate.day());
2169
2201
}
2170
2202
 
2171
2203
void KCalendarTest::testQDateAddYears()
2172
2204
{
2173
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
2205
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2174
2206
 
2175
2207
    QDate testDate;
2176
2208
 
2177
 
    calendar->setDate( testDate, 2000,  1,  1 );
2178
 
    QCOMPARE( calendar->addYears( testDate, -1 ),  testDate.addYears( -1 ) );
2179
 
    QCOMPARE( calendar->addYears( testDate,  1 ),  testDate.addYears(  1 ) );
2180
 
 
2181
 
    calendar->setDate( testDate, 2000,  2, 29 );
2182
 
    QCOMPARE( calendar->addYears( testDate,  1 ),  testDate.addYears(  1 ) );
2183
 
 
2184
 
    calendar->setDate( testDate, -2000,  1,  1 );
2185
 
    QCOMPARE( calendar->addYears( testDate, -1 ),  testDate.addYears( -1 ) );
2186
 
    QCOMPARE( calendar->addYears( testDate,  1 ),  testDate.addYears(  1 ) );
 
2209
    calendar->setDate(testDate, 2000,  1,  1);
 
2210
    QCOMPARE(calendar->addYears(testDate, -1),  testDate.addYears(-1));
 
2211
    QCOMPARE(calendar->addYears(testDate,  1),  testDate.addYears(1));
 
2212
 
 
2213
    calendar->setDate(testDate, 2000,  2, 29);
 
2214
    QCOMPARE(calendar->addYears(testDate,  1),  testDate.addYears(1));
 
2215
 
 
2216
    calendar->setDate(testDate, -2000,  1,  1);
 
2217
    QCOMPARE(calendar->addYears(testDate, -1),  testDate.addYears(-1));
 
2218
    QCOMPARE(calendar->addYears(testDate,  1),  testDate.addYears(1));
2187
2219
 
2188
2220
    delete calendar;
2189
2221
}
2190
2222
 
2191
2223
void KCalendarTest::testQDateAddMonths()
2192
2224
{
2193
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
2225
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2194
2226
 
2195
2227
    QDate testDate;
2196
2228
 
2197
 
    calendar->setDate( testDate, 2000,  1,  1 );
2198
 
    QCOMPARE( calendar->addMonths( testDate, -1 ),  testDate.addMonths( -1 ) );
2199
 
    QCOMPARE( calendar->addMonths( testDate,  1 ),  testDate.addMonths(  1 ) );
2200
 
 
2201
 
    calendar->setDate( testDate, 2000,  3,  1 );
2202
 
    QCOMPARE( calendar->addMonths( testDate, -1 ),  testDate.addMonths( -1 ) );
2203
 
    QCOMPARE( calendar->addMonths( testDate,  1 ),  testDate.addMonths(  1 ) );
2204
 
 
2205
 
    calendar->setDate( testDate, 2000, 12,  1 );
2206
 
    QCOMPARE( calendar->addMonths( testDate, -1 ),  testDate.addMonths( -1 ) );
2207
 
    QCOMPARE( calendar->addMonths( testDate,  1 ),  testDate.addMonths(  1 ) );
2208
 
 
2209
 
    calendar->setDate( testDate, 2000,  1,  1 );
2210
 
    QCOMPARE( calendar->addMonths( testDate, -30 ),  testDate.addMonths( -30 ) );
2211
 
    QCOMPARE( calendar->addMonths( testDate,  30 ),  testDate.addMonths(  30 ) );
2212
 
 
2213
 
    calendar->setDate( testDate, -2000,  1,  1 );
2214
 
    QCOMPARE( calendar->addMonths( testDate, -1 ),  testDate.addMonths( -1 ) );
2215
 
    QCOMPARE( calendar->addMonths( testDate,  1 ),  testDate.addMonths(  1 ) );
2216
 
 
2217
 
    calendar->setDate( testDate, -2000,  3,  1 );
2218
 
    QCOMPARE( calendar->addMonths( testDate, -1 ),  testDate.addMonths( -1 ) );
2219
 
    QCOMPARE( calendar->addMonths( testDate,  1 ),  testDate.addMonths(  1 ) );
2220
 
 
2221
 
    calendar->setDate( testDate, -2000, 12,  1 );
2222
 
    QCOMPARE( calendar->addMonths( testDate, -1 ),  testDate.addMonths( -1 ) );
2223
 
    QCOMPARE( calendar->addMonths( testDate,  1 ),  testDate.addMonths(  1 ) );
2224
 
 
2225
 
    calendar->setDate( testDate, -2000,  1,  1 );
2226
 
    QCOMPARE( calendar->addMonths( testDate, -30 ),  testDate.addMonths( -30 ) );
2227
 
    QCOMPARE( calendar->addMonths( testDate,  30 ),  testDate.addMonths(  30 ) );
 
2229
    calendar->setDate(testDate, 2000,  1,  1);
 
2230
    QCOMPARE(calendar->addMonths(testDate, -1),  testDate.addMonths(-1));
 
2231
    QCOMPARE(calendar->addMonths(testDate,  1),  testDate.addMonths(1));
 
2232
 
 
2233
    calendar->setDate(testDate, 2000,  3,  1);
 
2234
    QCOMPARE(calendar->addMonths(testDate, -1),  testDate.addMonths(-1));
 
2235
    QCOMPARE(calendar->addMonths(testDate,  1),  testDate.addMonths(1));
 
2236
 
 
2237
    calendar->setDate(testDate, 2000, 12,  1);
 
2238
    QCOMPARE(calendar->addMonths(testDate, -1),  testDate.addMonths(-1));
 
2239
    QCOMPARE(calendar->addMonths(testDate,  1),  testDate.addMonths(1));
 
2240
 
 
2241
    calendar->setDate(testDate, 2000,  1,  1);
 
2242
    QCOMPARE(calendar->addMonths(testDate, -30),  testDate.addMonths(-30));
 
2243
    QCOMPARE(calendar->addMonths(testDate,  30),  testDate.addMonths(30));
 
2244
 
 
2245
    calendar->setDate(testDate, -2000,  1,  1);
 
2246
    QCOMPARE(calendar->addMonths(testDate, -1),  testDate.addMonths(-1));
 
2247
    QCOMPARE(calendar->addMonths(testDate,  1),  testDate.addMonths(1));
 
2248
 
 
2249
    calendar->setDate(testDate, -2000,  3,  1);
 
2250
    QCOMPARE(calendar->addMonths(testDate, -1),  testDate.addMonths(-1));
 
2251
    QCOMPARE(calendar->addMonths(testDate,  1),  testDate.addMonths(1));
 
2252
 
 
2253
    calendar->setDate(testDate, -2000, 12,  1);
 
2254
    QCOMPARE(calendar->addMonths(testDate, -1),  testDate.addMonths(-1));
 
2255
    QCOMPARE(calendar->addMonths(testDate,  1),  testDate.addMonths(1));
 
2256
 
 
2257
    calendar->setDate(testDate, -2000,  1,  1);
 
2258
    QCOMPARE(calendar->addMonths(testDate, -30),  testDate.addMonths(-30));
 
2259
    QCOMPARE(calendar->addMonths(testDate,  30),  testDate.addMonths(30));
2228
2260
 
2229
2261
    delete calendar;
2230
2262
}
2231
2263
 
2232
2264
void KCalendarTest::testQDateAddDays()
2233
2265
{
2234
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
2266
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2235
2267
 
2236
2268
    QDate testDate;
2237
2269
 
2238
 
    calendar->setDate( testDate, 2000,  1,  1 );
2239
 
    QCOMPARE( calendar->addDays( testDate, -1 ),  testDate.addDays( -1 ) );
2240
 
    QCOMPARE( calendar->addDays( testDate,  1 ),  testDate.addDays(  1 ) );
 
2270
    calendar->setDate(testDate, 2000,  1,  1);
 
2271
    QCOMPARE(calendar->addDays(testDate, -1),  testDate.addDays(-1));
 
2272
    QCOMPARE(calendar->addDays(testDate,  1),  testDate.addDays(1));
2241
2273
 
2242
 
    calendar->setDate( testDate, -2000,  1,  1 );
2243
 
    QCOMPARE( calendar->addDays( testDate, -1 ),  testDate.addDays( -1 ) );
2244
 
    QCOMPARE( calendar->addDays( testDate,  1 ),  testDate.addDays(  1 ) );
 
2274
    calendar->setDate(testDate, -2000,  1,  1);
 
2275
    QCOMPARE(calendar->addDays(testDate, -1),  testDate.addDays(-1));
 
2276
    QCOMPARE(calendar->addDays(testDate,  1),  testDate.addDays(1));
2245
2277
 
2246
2278
    delete calendar;
2247
2279
}
2248
2280
 
2249
2281
void KCalendarTest::testQDateDaysInYear()
2250
2282
{
2251
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
2283
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2252
2284
 
2253
2285
    QDate testDate;
2254
2286
 
2255
 
    calendar->setDate( testDate, 1900, 1, 1 );
2256
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2257
 
    calendar->setDate( testDate, 1999, 1, 1 );
2258
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2259
 
    calendar->setDate( testDate, 2000, 1, 1 );
2260
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2261
 
    calendar->setDate( testDate, 2001, 1, 1 );
2262
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2263
 
    calendar->setDate( testDate, 2002, 1, 1 );
2264
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2265
 
    calendar->setDate( testDate, 2003, 1, 1 );
2266
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2267
 
    calendar->setDate( testDate, 2004, 1, 1 );
2268
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2269
 
    calendar->setDate( testDate, 2005, 1, 1 );
2270
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2271
 
 
2272
 
    calendar->setDate( testDate, -4700, 1, 1 );
2273
 
    #if QT_VERSION < 0x040601
2274
 
    QEXPECT_FAIL("", "Returns 365 instead of 366", Continue); // Fix submitted to Qt
2275
 
    #endif
2276
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2277
 
    calendar->setDate( testDate, -4000, 1, 1 );
2278
 
    #if QT_VERSION < 0x040601
2279
 
    QEXPECT_FAIL("", "Returns 365 instead of 366", Continue); // Fix submitted to Qt
2280
 
    #endif
2281
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2282
 
 
2283
 
    calendar->setDate( testDate, 1, 1, 1 );
2284
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2285
 
 
2286
 
    calendar->setDate( testDate, 9996, 1, 1 );
2287
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
2288
 
    calendar->setDate( testDate, 9999, 1, 1 );
2289
 
    QCOMPARE( calendar->daysInYear( testDate ),  testDate.daysInYear() );
 
2287
    calendar->setDate(testDate, 1900, 1, 1);
 
2288
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2289
    calendar->setDate(testDate, 1999, 1, 1);
 
2290
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2291
    calendar->setDate(testDate, 2000, 1, 1);
 
2292
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2293
    calendar->setDate(testDate, 2001, 1, 1);
 
2294
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2295
    calendar->setDate(testDate, 2002, 1, 1);
 
2296
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2297
    calendar->setDate(testDate, 2003, 1, 1);
 
2298
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2299
    calendar->setDate(testDate, 2004, 1, 1);
 
2300
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2301
    calendar->setDate(testDate, 2005, 1, 1);
 
2302
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2303
 
 
2304
    calendar->setDate(testDate, -4700, 1, 1);
 
2305
#if QT_VERSION < 0x040601
 
2306
    QEXPECT_FAIL("", "Returns 365 instead of 366", Continue); // Fix submitted to Qt
 
2307
#endif
 
2308
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2309
    calendar->setDate(testDate, -4000, 1, 1);
 
2310
#if QT_VERSION < 0x040601
 
2311
    QEXPECT_FAIL("", "Returns 365 instead of 366", Continue); // Fix submitted to Qt
 
2312
#endif
 
2313
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2314
 
 
2315
    calendar->setDate(testDate, 1, 1, 1);
 
2316
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2317
 
 
2318
    calendar->setDate(testDate, 9996, 1, 1);
 
2319
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
 
2320
    calendar->setDate(testDate, 9999, 1, 1);
 
2321
    QCOMPARE(calendar->daysInYear(testDate),  testDate.daysInYear());
2290
2322
 
2291
2323
    delete calendar;
2292
2324
}
2294
2326
 
2295
2327
void KCalendarTest::testQDateDaysInMonth()
2296
2328
{
2297
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
2329
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2298
2330
 
2299
2331
    QDate testDate;
2300
2332
 
2301
2333
    // Test all months
2302
 
    calendar->setDate( testDate, 2000,  1, 1 );
2303
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2304
 
    calendar->setDate( testDate, 2000,  2, 1 );
2305
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2306
 
    calendar->setDate( testDate, 2000,  3, 1 );
2307
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2308
 
    calendar->setDate( testDate, 2000,  4, 1 );
2309
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2310
 
    calendar->setDate( testDate, 2000,  5, 1 );
2311
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2312
 
    calendar->setDate( testDate, 2000,  6, 1 );
2313
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2314
 
    calendar->setDate( testDate, 2000,  7, 1 );
2315
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2316
 
    calendar->setDate( testDate, 2000,  8, 1 );
2317
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2318
 
    calendar->setDate( testDate, 2000,  9, 1 );
2319
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2320
 
    calendar->setDate( testDate, 2000, 10, 1 );
2321
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2322
 
    calendar->setDate( testDate, 2000, 11, 1 );
2323
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2324
 
    calendar->setDate( testDate, 2000, 12, 1 );
2325
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
 
2334
    calendar->setDate(testDate, 2000,  1, 1);
 
2335
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2336
    calendar->setDate(testDate, 2000,  2, 1);
 
2337
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2338
    calendar->setDate(testDate, 2000,  3, 1);
 
2339
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2340
    calendar->setDate(testDate, 2000,  4, 1);
 
2341
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2342
    calendar->setDate(testDate, 2000,  5, 1);
 
2343
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2344
    calendar->setDate(testDate, 2000,  6, 1);
 
2345
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2346
    calendar->setDate(testDate, 2000,  7, 1);
 
2347
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2348
    calendar->setDate(testDate, 2000,  8, 1);
 
2349
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2350
    calendar->setDate(testDate, 2000,  9, 1);
 
2351
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2352
    calendar->setDate(testDate, 2000, 10, 1);
 
2353
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2354
    calendar->setDate(testDate, 2000, 11, 1);
 
2355
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2356
    calendar->setDate(testDate, 2000, 12, 1);
 
2357
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
2326
2358
 
2327
2359
    // Test Feb in leap and normal years
2328
 
    calendar->setDate( testDate, 2000, 2, 1 );
2329
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
2330
 
    calendar->setDate( testDate, 2001, 2, 1 );
2331
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
 
2360
    calendar->setDate(testDate, 2000, 2, 1);
 
2361
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
 
2362
    calendar->setDate(testDate, 2001, 2, 1);
 
2363
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
2332
2364
 
2333
2365
    // Test max date
2334
 
    calendar->setDate( testDate, 9999, 12, 1 );
2335
 
    QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
 
2366
    calendar->setDate(testDate, 9999, 12, 1);
 
2367
    QCOMPARE(calendar->daysInMonth(testDate), testDate.daysInMonth());
2336
2368
 
2337
2369
    delete calendar;
2338
2370
}
2339
2371
 
2340
2372
void KCalendarTest::testQDateDayOfYear()
2341
2373
{
2342
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
2374
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2343
2375
 
2344
2376
    QDate testDate;
2345
2377
 
2346
 
    calendar->setDate( testDate, 2000,  1,  1 );
2347
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2348
 
    calendar->setDate( testDate, 2000,  2, 29 );
2349
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2350
 
    calendar->setDate( testDate, 2000,  6,  1 );
2351
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2352
 
    calendar->setDate( testDate, 2000, 12,  1 );
2353
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2354
 
    calendar->setDate( testDate, 2000, 12, 31 );
2355
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2356
 
 
2357
 
    calendar->setDate( testDate, -2000,  1,  1 );
2358
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2359
 
    calendar->setDate( testDate, -2000,  2, 28 );
2360
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2361
 
    calendar->setDate( testDate, -2000,  6,  1 );
2362
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2363
 
    calendar->setDate( testDate, -2000, 12,  1 );
2364
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2365
 
    calendar->setDate( testDate, -2000, 12, 31 );
2366
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2367
 
 
2368
 
    calendar->setDate( testDate, -4712,  1,  2 );
2369
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2370
 
    calendar->setDate( testDate, -4712,  2, 28 );
2371
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2372
 
    calendar->setDate( testDate, -4712,  6,  1 );
2373
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2374
 
    calendar->setDate( testDate, -4712, 12,  1 );
2375
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2376
 
    calendar->setDate( testDate, -4712, 12, 31 );
2377
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2378
 
 
2379
 
    calendar->setDate( testDate, 9999,  1,  1 );
2380
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
 
2378
    calendar->setDate(testDate, 2000,  1,  1);
 
2379
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2380
    calendar->setDate(testDate, 2000,  2, 29);
 
2381
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2382
    calendar->setDate(testDate, 2000,  6,  1);
 
2383
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2384
    calendar->setDate(testDate, 2000, 12,  1);
 
2385
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2386
    calendar->setDate(testDate, 2000, 12, 31);
 
2387
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2388
 
 
2389
    calendar->setDate(testDate, -2000,  1,  1);
 
2390
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2391
    calendar->setDate(testDate, -2000,  2, 28);
 
2392
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2393
    calendar->setDate(testDate, -2000,  6,  1);
 
2394
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2395
    calendar->setDate(testDate, -2000, 12,  1);
 
2396
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2397
    calendar->setDate(testDate, -2000, 12, 31);
 
2398
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2399
 
 
2400
    calendar->setDate(testDate, -4712,  1,  2);
 
2401
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2402
    calendar->setDate(testDate, -4712,  2, 28);
 
2403
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2404
    calendar->setDate(testDate, -4712,  6,  1);
 
2405
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2406
    calendar->setDate(testDate, -4712, 12,  1);
 
2407
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2408
    calendar->setDate(testDate, -4712, 12, 31);
 
2409
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2410
 
 
2411
    calendar->setDate(testDate, 9999,  1,  1);
 
2412
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
2381
2413
    //QDate::dayOfYear doesn't check if invalid!!!
2382
2414
    //calendar->setDate( testDate, 9999,  2, 29 );
2383
2415
    //QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2384
 
    calendar->setDate( testDate, 9999,  6,  1 );
2385
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2386
 
    calendar->setDate( testDate, 9999, 12,  1 );
2387
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
2388
 
    calendar->setDate( testDate, 9999, 12, 31 );
2389
 
    QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
 
2416
    calendar->setDate(testDate, 9999,  6,  1);
 
2417
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2418
    calendar->setDate(testDate, 9999, 12,  1);
 
2419
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
 
2420
    calendar->setDate(testDate, 9999, 12, 31);
 
2421
    QCOMPARE(calendar->dayOfYear(testDate), testDate.dayOfYear());
2390
2422
 
2391
2423
    delete calendar;
2392
2424
}
2393
2425
 
2394
2426
void KCalendarTest::testQDateDayOfWeek()
2395
2427
{
2396
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
2428
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2397
2429
 
2398
2430
    QDate testDate;
2399
2431
 
2400
 
    calendar->setDate( testDate, 2000,  1,  1 );
2401
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2402
 
    calendar->setDate( testDate, 2000,  1,  2 );
2403
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2404
 
    calendar->setDate( testDate, 2000,  1,  3 );
2405
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2406
 
    calendar->setDate( testDate, 2000,  1,  4 );
2407
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2408
 
    calendar->setDate( testDate, 2000,  1,  5 );
2409
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2410
 
    calendar->setDate( testDate, 2000,  1,  6 );
2411
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2412
 
    calendar->setDate( testDate, 2000,  1,  7 );
2413
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2414
 
 
2415
 
    calendar->setDate( testDate, -4712,  1,  2 );
2416
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2417
 
    calendar->setDate( testDate, -4712,  1,  3 );
2418
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2419
 
    calendar->setDate( testDate, -4712,  1,  4 );
2420
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2421
 
    calendar->setDate( testDate, -4712,  1,  5 );
2422
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2423
 
    calendar->setDate( testDate, -4712,  1,  6 );
2424
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2425
 
    calendar->setDate( testDate, -4712,  1,  7 );
2426
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2427
 
    calendar->setDate( testDate, -4712,  1,  8 );
2428
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2429
 
 
2430
 
    calendar->setDate( testDate, 9999,  1,  1 );
2431
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2432
 
    calendar->setDate( testDate, 9999,  1,  2 );
2433
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2434
 
    calendar->setDate( testDate, 9999,  1,  3 );
2435
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2436
 
    calendar->setDate( testDate, 9999,  1,  4 );
2437
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2438
 
    calendar->setDate( testDate, 9999,  1,  5 );
2439
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2440
 
    calendar->setDate( testDate, 9999,  1,  6 );
2441
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
2442
 
    calendar->setDate( testDate, 9999,  1,  7 );
2443
 
    QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
 
2432
    calendar->setDate(testDate, 2000,  1,  1);
 
2433
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2434
    calendar->setDate(testDate, 2000,  1,  2);
 
2435
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2436
    calendar->setDate(testDate, 2000,  1,  3);
 
2437
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2438
    calendar->setDate(testDate, 2000,  1,  4);
 
2439
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2440
    calendar->setDate(testDate, 2000,  1,  5);
 
2441
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2442
    calendar->setDate(testDate, 2000,  1,  6);
 
2443
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2444
    calendar->setDate(testDate, 2000,  1,  7);
 
2445
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2446
 
 
2447
    calendar->setDate(testDate, -4712,  1,  2);
 
2448
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2449
    calendar->setDate(testDate, -4712,  1,  3);
 
2450
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2451
    calendar->setDate(testDate, -4712,  1,  4);
 
2452
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2453
    calendar->setDate(testDate, -4712,  1,  5);
 
2454
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2455
    calendar->setDate(testDate, -4712,  1,  6);
 
2456
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2457
    calendar->setDate(testDate, -4712,  1,  7);
 
2458
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2459
    calendar->setDate(testDate, -4712,  1,  8);
 
2460
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2461
 
 
2462
    calendar->setDate(testDate, 9999,  1,  1);
 
2463
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2464
    calendar->setDate(testDate, 9999,  1,  2);
 
2465
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2466
    calendar->setDate(testDate, 9999,  1,  3);
 
2467
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2468
    calendar->setDate(testDate, 9999,  1,  4);
 
2469
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2470
    calendar->setDate(testDate, 9999,  1,  5);
 
2471
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2472
    calendar->setDate(testDate, 9999,  1,  6);
 
2473
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
 
2474
    calendar->setDate(testDate, 9999,  1,  7);
 
2475
    QCOMPARE(calendar->dayOfWeek(testDate), testDate.dayOfWeek());
2444
2476
 
2445
2477
    delete calendar;
2446
2478
}
2448
2480
// Don't really need this as Gregorian currently uses QDate directly
2449
2481
void KCalendarTest::testQDateIsLeapYear()
2450
2482
{
2451
 
    const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
 
2483
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2452
2484
 
2453
2485
    QDate testDate;
2454
2486
 
2455
 
    calendar->setDate( testDate, 2000,  1,  1 );
2456
 
    QCOMPARE( calendar->isLeapYear( 2000 ),     testDate.isLeapYear( 2000 ) );
2457
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 2000 ) );
2458
 
    calendar->setDate( testDate, 2001,  1,  1 );
2459
 
    QCOMPARE( calendar->isLeapYear( 2001 ),     testDate.isLeapYear( 2001 ) );
2460
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 2001 ) );
2461
 
    calendar->setDate( testDate, 2004,  1,  1 );
2462
 
    QCOMPARE( calendar->isLeapYear( 2004 ),     testDate.isLeapYear( 2004 ) );
2463
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 2004 ) );
2464
 
 
2465
 
    calendar->setDate( testDate, 1900,  1,  1 );
2466
 
    QCOMPARE( calendar->isLeapYear( 1900 ),     testDate.isLeapYear( 1900 ) );
2467
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 1900 ) );
2468
 
    calendar->setDate( testDate, 1901,  1,  1 );
2469
 
    QCOMPARE( calendar->isLeapYear( 1901 ),     testDate.isLeapYear( 1901 ) );
2470
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 1901 ) );
2471
 
    calendar->setDate( testDate, 1904,  1,  1 );
2472
 
    QCOMPARE( calendar->isLeapYear( 1904 ),     testDate.isLeapYear( 1904 ) );
2473
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 1904 ) );
2474
 
 
2475
 
    calendar->setDate( testDate, -2000,  1,  1 );
2476
 
    QCOMPARE( calendar->isLeapYear( -2000 ),    testDate.isLeapYear( -2000 ) );
2477
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( -2000 ) );
2478
 
    calendar->setDate( testDate, -2001,  1,  1 );
2479
 
    QCOMPARE( calendar->isLeapYear( -2001 ),    testDate.isLeapYear( -2001 ) );
2480
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( -2001 ) );
2481
 
    calendar->setDate( testDate, -2004,  1,  1 );
2482
 
    QCOMPARE( calendar->isLeapYear( -2004 ),    testDate.isLeapYear( -2004 ) );
2483
 
    QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( -2004 ) );
 
2487
    calendar->setDate(testDate, 2000,  1,  1);
 
2488
    QCOMPARE(calendar->isLeapYear(2000),     testDate.isLeapYear(2000));
 
2489
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(2000));
 
2490
    calendar->setDate(testDate, 2001,  1,  1);
 
2491
    QCOMPARE(calendar->isLeapYear(2001),     testDate.isLeapYear(2001));
 
2492
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(2001));
 
2493
    calendar->setDate(testDate, 2004,  1,  1);
 
2494
    QCOMPARE(calendar->isLeapYear(2004),     testDate.isLeapYear(2004));
 
2495
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(2004));
 
2496
 
 
2497
    calendar->setDate(testDate, 1900,  1,  1);
 
2498
    QCOMPARE(calendar->isLeapYear(1900),     testDate.isLeapYear(1900));
 
2499
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(1900));
 
2500
    calendar->setDate(testDate, 1901,  1,  1);
 
2501
    QCOMPARE(calendar->isLeapYear(1901),     testDate.isLeapYear(1901));
 
2502
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(1901));
 
2503
    calendar->setDate(testDate, 1904,  1,  1);
 
2504
    QCOMPARE(calendar->isLeapYear(1904),     testDate.isLeapYear(1904));
 
2505
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(1904));
 
2506
 
 
2507
    calendar->setDate(testDate, -2000,  1,  1);
 
2508
    QCOMPARE(calendar->isLeapYear(-2000),    testDate.isLeapYear(-2000));
 
2509
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(-2000));
 
2510
    calendar->setDate(testDate, -2001,  1,  1);
 
2511
    QCOMPARE(calendar->isLeapYear(-2001),    testDate.isLeapYear(-2001));
 
2512
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(-2001));
 
2513
    calendar->setDate(testDate, -2004,  1,  1);
 
2514
    QCOMPARE(calendar->isLeapYear(-2004),    testDate.isLeapYear(-2004));
 
2515
    QCOMPARE(calendar->isLeapYear(testDate), testDate.isLeapYear(-2004));
2484
2516
 
2485
2517
    delete calendar;
2486
2518
}
2487
2519
 
2488
2520
void KCalendarTest::testKLocalizedDate()
2489
2521
{
2490
 
    KGlobal::locale()->setDateFormatShort( "%y-%m-%d" );
 
2522
    KGlobal::locale()->setDateFormatShort("%y-%m-%d");
2491
2523
    const KCalendarSystem *calendar = KGlobal::locale()->calendar();
2492
2524
 
2493
2525
    // Set up a bunch of KLocalizedDates and QDates that should be equal
2494
 
    QDate testQDate( 2010, 1, 1 );
2495
 
    KLocalizedDate testKLocalizedDate( testQDate );
 
2526
    QDate testQDate(2010, 1, 1);
 
2527
    KLocalizedDate testKLocalizedDate(testQDate);
2496
2528
 
2497
2529
    // Test KLocalizedDate output calls not in KCalendarSystem
2498
 
    QCOMPARE( KLocalizedDate().isNull(),        true );
2499
 
    QCOMPARE( KLocalizedDate().isValid(),       false );
2500
 
    QCOMPARE( testKLocalizedDate.isNull(),      testQDate.isNull() );
2501
 
    QCOMPARE( testKLocalizedDate.date(),        testQDate );
2502
 
    QCOMPARE( testKLocalizedDate.toJulianDay(), testQDate.toJulianDay() );
2503
 
    testKLocalizedDate.setDate( QDate( 2010, 6, 1 ) );
2504
 
    testQDate.setDate( 2010, 6, 1 );
2505
 
    QCOMPARE( testKLocalizedDate.date(),        testQDate );
 
2530
    QCOMPARE(KLocalizedDate().isNull(),        true);
 
2531
    QCOMPARE(KLocalizedDate().isValid(),       false);
 
2532
    QCOMPARE(testKLocalizedDate.isNull(),      testQDate.isNull());
 
2533
    QCOMPARE(testKLocalizedDate.date(),        testQDate);
 
2534
    QCOMPARE(testKLocalizedDate.toJulianDay(), testQDate.toJulianDay());
 
2535
    testKLocalizedDate.setDate(QDate(2010, 6, 1));
 
2536
    testQDate.setDate(2010, 6, 1);
 
2537
    QCOMPARE(testKLocalizedDate.date(),        testQDate);
2506
2538
 
2507
2539
    // Test static KLocalizedDate methods
2508
 
    QCOMPARE( KLocalizedDate::currentDate().date(),           QDate::currentDate() );
2509
 
    QCOMPARE( KLocalizedDate::fromDate( testQDate ).date(),   testQDate );
2510
 
    QCOMPARE( KLocalizedDate::fromJulianDay( 100000 ).date(), QDate::fromJulianDay( 100000 ) );
 
2540
    QCOMPARE(KLocalizedDate::currentDate().date(),           QDate::currentDate());
 
2541
    QCOMPARE(KLocalizedDate::fromDate(testQDate).date(),   testQDate);
 
2542
    QCOMPARE(KLocalizedDate::fromJulianDay(100000).date(), QDate::fromJulianDay(100000));
2511
2543
 
2512
2544
    // Compare KLocalizedDate output to KCalendarSystem output calls
2513
 
    QCOMPARE( testKLocalizedDate.isValid(),                     calendar->isValid( testQDate ) );
2514
 
    QCOMPARE( testKLocalizedDate.year(),                        calendar->year( testQDate ) );
2515
 
    QCOMPARE( testKLocalizedDate.month(),                       calendar->month( testQDate ) );
2516
 
    QCOMPARE( testKLocalizedDate.day(),                         calendar->day( testQDate ) );
2517
 
    QCOMPARE( testKLocalizedDate.eraName(),                     calendar->eraName( testQDate ) );
2518
 
    QCOMPARE( testKLocalizedDate.eraYear(),                     calendar->eraYear( testQDate ) );
2519
 
    QCOMPARE( testKLocalizedDate.yearInEra(),                   calendar->yearInEra( testQDate ) );
2520
 
    QCOMPARE( testKLocalizedDate.addYears( 5 ).date(),          calendar->addYears( testQDate, 5 ) );
2521
 
    QCOMPARE( testKLocalizedDate.addMonths( 5 ).date(),         calendar->addMonths( testQDate, 5 ) );
2522
 
    QCOMPARE( testKLocalizedDate.addDays( 5 ).date(),           calendar->addDays( testQDate, 5 ) );
2523
 
    QCOMPARE( testKLocalizedDate.monthsInYear(),                calendar->monthsInYear( testQDate ) );
2524
 
    QCOMPARE( testKLocalizedDate.weeksInYear(),                 calendar->weeksInYear( testQDate ) );
2525
 
    QCOMPARE( testKLocalizedDate.daysInYear(),                  calendar->daysInYear( testQDate ) );
2526
 
    QCOMPARE( testKLocalizedDate.daysInMonth(),                 calendar->daysInMonth( testQDate ) );
2527
 
    QCOMPARE( testKLocalizedDate.daysInWeek(),                  calendar->daysInWeek( testQDate ) );
2528
 
    QCOMPARE( testKLocalizedDate.dayOfYear(),                   calendar->dayOfYear( testQDate ) );
2529
 
    QCOMPARE( testKLocalizedDate.dayOfWeek(),                   calendar->dayOfWeek( testQDate ) );
2530
 
    QCOMPARE( testKLocalizedDate.week(),                        calendar->weekNumber( testQDate ) );
2531
 
    QCOMPARE( testKLocalizedDate.isLeapYear(),                  calendar->isLeapYear( testQDate ) );
2532
 
    QCOMPARE( testKLocalizedDate.firstDayOfYear().date(),       calendar->firstDayOfYear( testQDate ) );
2533
 
    QCOMPARE( testKLocalizedDate.lastDayOfYear().date(),        calendar->lastDayOfYear( testQDate ) );
2534
 
    QCOMPARE( testKLocalizedDate.firstDayOfMonth().date(),      calendar->firstDayOfMonth( testQDate ) );
2535
 
    QCOMPARE( testKLocalizedDate.lastDayOfMonth().date(),       calendar->lastDayOfMonth( testQDate ) );
 
2545
    QCOMPARE(testKLocalizedDate.isValid(),                     calendar->isValid(testQDate));
 
2546
    QCOMPARE(testKLocalizedDate.year(),                        calendar->year(testQDate));
 
2547
    QCOMPARE(testKLocalizedDate.month(),                       calendar->month(testQDate));
 
2548
    QCOMPARE(testKLocalizedDate.day(),                         calendar->day(testQDate));
 
2549
    QCOMPARE(testKLocalizedDate.eraName(),                     calendar->eraName(testQDate));
 
2550
    QCOMPARE(testKLocalizedDate.eraYear(),                     calendar->eraYear(testQDate));
 
2551
    QCOMPARE(testKLocalizedDate.yearInEra(),                   calendar->yearInEra(testQDate));
 
2552
    QCOMPARE(testKLocalizedDate.addYears(5).date(),          calendar->addYears(testQDate, 5));
 
2553
    QCOMPARE(testKLocalizedDate.addMonths(5).date(),         calendar->addMonths(testQDate, 5));
 
2554
    QCOMPARE(testKLocalizedDate.addDays(5).date(),           calendar->addDays(testQDate, 5));
 
2555
    QCOMPARE(testKLocalizedDate.monthsInYear(),                calendar->monthsInYear(testQDate));
 
2556
    QCOMPARE(testKLocalizedDate.weeksInYear(),                 calendar->weeksInYear(testQDate));
 
2557
    QCOMPARE(testKLocalizedDate.daysInYear(),                  calendar->daysInYear(testQDate));
 
2558
    QCOMPARE(testKLocalizedDate.daysInMonth(),                 calendar->daysInMonth(testQDate));
 
2559
    QCOMPARE(testKLocalizedDate.daysInWeek(),                  calendar->daysInWeek(testQDate));
 
2560
    QCOMPARE(testKLocalizedDate.dayOfYear(),                   calendar->dayOfYear(testQDate));
 
2561
    QCOMPARE(testKLocalizedDate.dayOfWeek(),                   calendar->dayOfWeek(testQDate));
 
2562
    QCOMPARE(testKLocalizedDate.week(),                        calendar->week(testQDate));
 
2563
    QCOMPARE(testKLocalizedDate.isLeapYear(),                  calendar->isLeapYear(testQDate));
 
2564
    QCOMPARE(testKLocalizedDate.firstDayOfYear().date(),       calendar->firstDayOfYear(testQDate));
 
2565
    QCOMPARE(testKLocalizedDate.lastDayOfYear().date(),        calendar->lastDayOfYear(testQDate));
 
2566
    QCOMPARE(testKLocalizedDate.firstDayOfMonth().date(),      calendar->firstDayOfMonth(testQDate));
 
2567
    QCOMPARE(testKLocalizedDate.lastDayOfMonth().date(),       calendar->lastDayOfMonth(testQDate));
2536
2568
 
2537
 
    QCOMPARE( testKLocalizedDate.week(KLocale::IsoWeekNumber),        calendar->weekNumber( testQDate ) );
2538
 
    QCOMPARE( testKLocalizedDate.weeksInYear(KLocale::IsoWeekNumber), calendar->weeksInYear( testQDate ) );
 
2569
    QCOMPARE(testKLocalizedDate.week(KLocale::IsoWeekNumber),        calendar->week(testQDate, KLocale::IsoWeekNumber));
 
2570
    QCOMPARE(testKLocalizedDate.weeksInYear(KLocale::IsoWeekNumber), calendar->weeksInYear(testQDate, KLocale::IsoWeekNumber));
2539
2571
 
2540
2572
    // Compare KLocalizedDate setDate to KCalendarSystem setDate
2541
 
    testKLocalizedDate.setDate( 2010, 3, 1 );
2542
 
    calendar->setDate( testQDate, 2010, 3, 1 );
2543
 
    QCOMPARE( testKLocalizedDate.date(), testQDate );
2544
 
    testKLocalizedDate.setDate( 2010, 100 );
2545
 
    calendar->setDate( testQDate, 2010, 100 );
2546
 
    QCOMPARE( testKLocalizedDate.date(), testQDate );
2547
 
    testKLocalizedDate.setDate( "AD", 2010, 9, 1 );
2548
 
    calendar->setDate( testQDate, "AD", 2010, 9, 1 );
2549
 
    QCOMPARE( testKLocalizedDate.date(), testQDate );
2550
 
    testKLocalizedDate.setDate( KLocale::IsoWeekNumber, 2010, 15, 1 );
2551
 
    calendar->setDateIsoWeek( testQDate, 2010, 15, 1 );
2552
 
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2573
    testKLocalizedDate.setDate(2010, 3, 1);
 
2574
    calendar->setDate(testQDate, 2010, 3, 1);
 
2575
    QCOMPARE(testKLocalizedDate.date(), testQDate);
 
2576
    testKLocalizedDate.setDate(2010, 100);
 
2577
    calendar->setDate(testQDate, 2010, 100);
 
2578
    QCOMPARE(testKLocalizedDate.date(), testQDate);
 
2579
    testKLocalizedDate.setDate("AD", 2010, 9, 1);
 
2580
    calendar->setDate(testQDate, "AD", 2010, 9, 1);
 
2581
    QCOMPARE(testKLocalizedDate.date(), testQDate);
 
2582
    testKLocalizedDate.setDate(KLocale::IsoWeekNumber, 2010, 15, 1);
 
2583
    calendar->setDateIsoWeek(testQDate, 2010, 15, 1);
 
2584
    QCOMPARE(testKLocalizedDate.date(), testQDate);
2553
2585
    testKLocalizedDate.setCurrentDate();
2554
2586
    testQDate = QDate::currentDate();
2555
 
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2587
    QCOMPARE(testKLocalizedDate.date(), testQDate);
2556
2588
 
2557
2589
    // Compare KLocalizedDate getDate to KCalendarSystem getDate
2558
2590
    int ky, km, kd, qy, qm, qd;
2559
 
    testKLocalizedDate.getDate( &ky, &km, &kd );
2560
 
    calendar->getDate( testQDate, &qy, &qm, &qd );
2561
 
    QCOMPARE( ky, qy );
2562
 
    QCOMPARE( km, qm );
2563
 
    QCOMPARE( kd, qd );
 
2591
    testKLocalizedDate.getDate(&ky, &km, &kd);
 
2592
    calendar->getDate(testQDate, &qy, &qm, &qd);
 
2593
    QCOMPARE(ky, qy);
 
2594
    QCOMPARE(km, qm);
 
2595
    QCOMPARE(kd, qd);
2564
2596
 
2565
2597
    // Compare KLocalizedDate format/read to KCalendarSystem format
2566
 
    QCOMPARE( testKLocalizedDate.formatDate(),           calendar->formatDate( testQDate ) );
2567
 
    QCOMPARE( testKLocalizedDate.formatDate("%d-%m-%y"), calendar->formatDate( testQDate, "%d-%m-%y" ) );
2568
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::Year),              calendar->yearString( testQDate ) );
2569
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::YearName),          calendar->yearString( testQDate ) );
2570
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::Month),             calendar->monthString( testQDate, KCalendarSystem::ShortFormat ) );
2571
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::MonthName),         calendar->monthName( testQDate ) );
2572
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::Day),               calendar->dayString( testQDate, KCalendarSystem::ShortFormat ) );
2573
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::DayName),           calendar->dayString( testQDate, KCalendarSystem::ShortFormat ) );
2574
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::JulianDay),         QString::number( testQDate.toJulianDay() ) );
2575
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::EraName),           calendar->eraName( testQDate ) );
2576
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::EraYear),           calendar->eraYear( testQDate ) );
2577
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::YearInEra),         calendar->yearInEraString( testQDate ) );
2578
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::DayOfYear),         calendar->dayOfYearString( testQDate, KCalendarSystem::ShortFormat ) );
2579
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::DayOfYearName),     calendar->dayOfYearString( testQDate, KCalendarSystem::ShortFormat ) );
2580
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::DayOfWeek),         calendar->dayOfWeekString( testQDate ) );
2581
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::DayOfWeekName),     calendar->weekDayName( testQDate ) );
2582
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::Week),              calendar->weekNumberString( testQDate, KCalendarSystem::ShortFormat ) );
 
2598
    QCOMPARE(testKLocalizedDate.formatDate(),           calendar->formatDate(testQDate));
 
2599
    QCOMPARE(testKLocalizedDate.formatDate("%d-%m-%y"), calendar->formatDate(testQDate, "%d-%m-%y"));
 
2600
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::Year),              calendar->yearString(testQDate));
 
2601
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::YearName),          calendar->yearString(testQDate));
 
2602
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::Month),             calendar->monthString(testQDate, KCalendarSystem::ShortFormat));
 
2603
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::MonthName),         calendar->monthName(testQDate));
 
2604
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::Day),               calendar->dayString(testQDate, KCalendarSystem::ShortFormat));
 
2605
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::DayName),           calendar->dayString(testQDate, KCalendarSystem::ShortFormat));
 
2606
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::JulianDay),         QString::number(testQDate.toJulianDay()));
 
2607
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::EraName),           calendar->eraName(testQDate));
 
2608
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::EraYear),           calendar->eraYear(testQDate));
 
2609
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::YearInEra),         calendar->yearInEraString(testQDate));
 
2610
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::DayOfYear),         calendar->dayOfYearString(testQDate, KCalendarSystem::ShortFormat));
 
2611
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::DayOfYearName),     calendar->dayOfYearString(testQDate, KCalendarSystem::ShortFormat));
 
2612
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::DayOfWeek),         calendar->dayOfWeekString(testQDate));
 
2613
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::DayOfWeekName),     calendar->weekDayName(testQDate));
 
2614
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::Week),              calendar->weekNumberString(testQDate, KCalendarSystem::ShortFormat));
2583
2615
    int weekYear;
2584
2616
    QDate weekDate;
2585
 
    calendar->weekNumber( testQDate, &weekYear );
2586
 
    calendar->setDate( weekDate, weekYear, 1, 1);
2587
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::WeekYear),          calendar->yearString( weekDate ) );
2588
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::MonthsInYear),      calendar->monthsInYearString( testQDate ) );
2589
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::WeeksInYear),       calendar->weeksInYearString( testQDate ) );
2590
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::DaysInYear),        calendar->daysInYearString( testQDate ) );
2591
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::DaysInMonth),       calendar->daysInMonthString( testQDate ) );
2592
 
    QCOMPARE( testKLocalizedDate.formatDate(KLocale::DaysInWeek),        calendar->daysInWeekString( testQDate ) );
 
2617
    calendar->weekNumber(testQDate, &weekYear);
 
2618
    calendar->setDate(weekDate, weekYear, 1, 1);
 
2619
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::WeekYear),          calendar->yearString(weekDate));
 
2620
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::MonthsInYear),      calendar->monthsInYearString(testQDate));
 
2621
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::WeeksInYear),       calendar->weeksInYearString(testQDate));
 
2622
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::DaysInYear),        calendar->daysInYearString(testQDate));
 
2623
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::DaysInMonth),       calendar->daysInMonthString(testQDate));
 
2624
    QCOMPARE(testKLocalizedDate.formatDate(KLocale::DaysInWeek),        calendar->daysInWeekString(testQDate));
2593
2625
 
2594
2626
    // Compare KLocalizedDate format/read to KCalendarSystem read
2595
 
    QCOMPARE( testKLocalizedDate.readDate( "2010-01-01" ).date(),                        calendar->readDate( "2010-01-01" ) );
2596
 
    QCOMPARE( testKLocalizedDate.readDate( "2010-01-01", KLocale::NormalFormat ).date(), calendar->readDate( "2010-01-01", KLocale::NormalFormat ) );
2597
 
    QCOMPARE( testKLocalizedDate.readDate( "2010-01-01", "%y-%m-%d" ).date(),            calendar->readDate( "2010-01-01", "%y-%m-%d" ) );
 
2627
    QCOMPARE(testKLocalizedDate.readDate("2010-01-01").date(),                        calendar->readDate("2010-01-01"));
 
2628
    QCOMPARE(testKLocalizedDate.readDate("2010-01-01", KLocale::NormalFormat).date(), calendar->readDate("2010-01-01", KLocale::NormalFormat));
 
2629
    QCOMPARE(testKLocalizedDate.readDate("2010-01-01", "%y-%m-%d").date(),            calendar->readDate("2010-01-01", "%y-%m-%d"));
2598
2630
 
2599
2631
    // Test new addOn methods
2600
 
    testKLocalizedDate.addYearsTo( 5 );
2601
 
    testQDate = calendar->addYears( testQDate, 5 );
2602
 
    QCOMPARE( testKLocalizedDate.date(), testQDate );
2603
 
    testKLocalizedDate.addMonthsTo( 5 );
2604
 
    testQDate = calendar->addMonths( testQDate, 5 );
2605
 
    QCOMPARE( testKLocalizedDate.date(), testQDate );
2606
 
    testKLocalizedDate.addDaysTo( 5 );
2607
 
    testQDate = calendar->addDays( testQDate, 5 );
2608
 
    QCOMPARE( testKLocalizedDate.date(), testQDate );
 
2632
    testKLocalizedDate.addYearsTo(5);
 
2633
    testQDate = calendar->addYears(testQDate, 5);
 
2634
    QCOMPARE(testKLocalizedDate.date(), testQDate);
 
2635
    testKLocalizedDate.addMonthsTo(5);
 
2636
    testQDate = calendar->addMonths(testQDate, 5);
 
2637
    QCOMPARE(testKLocalizedDate.date(), testQDate);
 
2638
    testKLocalizedDate.addDaysTo(5);
 
2639
    testQDate = calendar->addDays(testQDate, 5);
 
2640
    QCOMPARE(testKLocalizedDate.date(), testQDate);
2609
2641
 
2610
2642
    // Set up some dates for comparisons
2611
 
    QDate lowQDate( 2000, 1, 1 );
2612
 
    KLocalizedDate lowKLocalizedDate( lowQDate );
2613
 
    QDate highQDate( 2010, 1, 1 );
2614
 
    KLocalizedDate highKLocalizedDate( highQDate );
 
2643
    QDate lowQDate(2000, 1, 1);
 
2644
    KLocalizedDate lowKLocalizedDate(lowQDate);
 
2645
    QDate highQDate(2010, 1, 1);
 
2646
    KLocalizedDate highKLocalizedDate(highQDate);
2615
2647
 
2616
2648
    // Compare the difference methods
2617
2649
    int kdy, kdm, kdd, kdir, qdy, qdm, qdd, qdir;
2618
 
    lowKLocalizedDate.dateDifference( highKLocalizedDate, &kdy, &kdm, &kdd, &kdir );
2619
 
    calendar->dateDifference( lowKLocalizedDate.date(), highKLocalizedDate.date(), &qdy, &qdm, &qdd, &qdir );
2620
 
    QCOMPARE( kdy, qdy );
2621
 
    QCOMPARE( kdm, qdm );
2622
 
    QCOMPARE( kdd, qdd );
2623
 
    QCOMPARE( kdir, qdir );
2624
 
    lowKLocalizedDate.dateDifference( highQDate, &kdy, &kdm, &kdd, &kdir );
2625
 
    calendar->dateDifference( lowKLocalizedDate.date(), highQDate, &qdy, &qdm, &qdd, &qdir );
2626
 
    QCOMPARE( kdy, qdy );
2627
 
    QCOMPARE( kdm, qdm );
2628
 
    QCOMPARE( kdd, qdd );
2629
 
    QCOMPARE( kdir, qdir );
2630
 
    QCOMPARE( lowKLocalizedDate.yearsDifference( highKLocalizedDate ),  calendar->yearsDifference( lowQDate, highQDate ) );
2631
 
    QCOMPARE( lowKLocalizedDate.yearsDifference( highQDate ),  calendar->yearsDifference( lowQDate, highQDate ) );
2632
 
    QCOMPARE( lowKLocalizedDate.monthsDifference( highKLocalizedDate ), calendar->monthsDifference( lowQDate, highQDate ) );
2633
 
    QCOMPARE( lowKLocalizedDate.monthsDifference( highQDate ), calendar->monthsDifference( lowQDate, highQDate ) );
2634
 
    QCOMPARE( lowKLocalizedDate.daysDifference( highKLocalizedDate ),   calendar->daysDifference( lowQDate, highQDate ) );
2635
 
    QCOMPARE( lowKLocalizedDate.daysDifference( highQDate ),   calendar->daysDifference( lowQDate, highQDate ) );
 
2650
    lowKLocalizedDate.dateDifference(highKLocalizedDate, &kdy, &kdm, &kdd, &kdir);
 
2651
    calendar->dateDifference(lowKLocalizedDate.date(), highKLocalizedDate.date(), &qdy, &qdm, &qdd, &qdir);
 
2652
    QCOMPARE(kdy, qdy);
 
2653
    QCOMPARE(kdm, qdm);
 
2654
    QCOMPARE(kdd, qdd);
 
2655
    QCOMPARE(kdir, qdir);
 
2656
    lowKLocalizedDate.dateDifference(highQDate, &kdy, &kdm, &kdd, &kdir);
 
2657
    calendar->dateDifference(lowKLocalizedDate.date(), highQDate, &qdy, &qdm, &qdd, &qdir);
 
2658
    QCOMPARE(kdy, qdy);
 
2659
    QCOMPARE(kdm, qdm);
 
2660
    QCOMPARE(kdd, qdd);
 
2661
    QCOMPARE(kdir, qdir);
 
2662
    QCOMPARE(lowKLocalizedDate.yearsDifference(highKLocalizedDate),  calendar->yearsDifference(lowQDate, highQDate));
 
2663
    QCOMPARE(lowKLocalizedDate.yearsDifference(highQDate),  calendar->yearsDifference(lowQDate, highQDate));
 
2664
    QCOMPARE(lowKLocalizedDate.monthsDifference(highKLocalizedDate), calendar->monthsDifference(lowQDate, highQDate));
 
2665
    QCOMPARE(lowKLocalizedDate.monthsDifference(highQDate), calendar->monthsDifference(lowQDate, highQDate));
 
2666
    QCOMPARE(lowKLocalizedDate.daysDifference(highKLocalizedDate),   calendar->daysDifference(lowQDate, highQDate));
 
2667
    QCOMPARE(lowKLocalizedDate.daysDifference(highQDate),   calendar->daysDifference(lowQDate, highQDate));
2636
2668
 
2637
2669
    // Test new operators
2638
 
    QCOMPARE( lowKLocalizedDate == lowKLocalizedDate,   true );
2639
 
    QCOMPARE( lowKLocalizedDate == highKLocalizedDate,  false );
2640
 
    QCOMPARE( lowKLocalizedDate == lowQDate,   true );
2641
 
    QCOMPARE( lowKLocalizedDate == highQDate,  false );
2642
 
    QCOMPARE( lowKLocalizedDate != lowKLocalizedDate,   false );
2643
 
    QCOMPARE( lowKLocalizedDate != highKLocalizedDate,  true );
2644
 
    QCOMPARE( lowKLocalizedDate != lowQDate,   false );
2645
 
    QCOMPARE( lowKLocalizedDate != highQDate,  true );
2646
 
    QCOMPARE( highKLocalizedDate < lowKLocalizedDate,   false );
2647
 
    QCOMPARE( lowKLocalizedDate  < highKLocalizedDate,  true );
2648
 
    QCOMPARE( highKLocalizedDate < lowQDate,   false );
2649
 
    QCOMPARE( lowKLocalizedDate  < highQDate,  true );
2650
 
    QCOMPARE( highKLocalizedDate <= lowKLocalizedDate,  false );
2651
 
    QCOMPARE( lowKLocalizedDate  <= lowKLocalizedDate,  true );
2652
 
    QCOMPARE( lowKLocalizedDate  <= highKLocalizedDate, true );
2653
 
    QCOMPARE( highKLocalizedDate <= lowQDate,  false );
2654
 
    QCOMPARE( lowKLocalizedDate  <= lowQDate,  true );
2655
 
    QCOMPARE( lowKLocalizedDate  <= highQDate, true );
2656
 
    QCOMPARE( highKLocalizedDate > lowKLocalizedDate,   true );
2657
 
    QCOMPARE( lowKLocalizedDate  > highKLocalizedDate,  false );
2658
 
    QCOMPARE( highKLocalizedDate > lowQDate,   true );
2659
 
    QCOMPARE( lowKLocalizedDate  > highQDate,  false );
2660
 
    QCOMPARE( highKLocalizedDate >= lowKLocalizedDate,  true );
2661
 
    QCOMPARE( lowKLocalizedDate  >= lowKLocalizedDate,  true );
2662
 
    QCOMPARE( lowKLocalizedDate  >= highKLocalizedDate, false );
2663
 
    QCOMPARE( highKLocalizedDate >= lowQDate,  true );
2664
 
    QCOMPARE( lowKLocalizedDate  >= lowQDate,  true );
2665
 
    QCOMPARE( lowKLocalizedDate  >= highQDate, false );
 
2670
    QCOMPARE(lowKLocalizedDate == lowKLocalizedDate,   true);
 
2671
    QCOMPARE(lowKLocalizedDate == highKLocalizedDate,  false);
 
2672
    QCOMPARE(lowKLocalizedDate == lowQDate,   true);
 
2673
    QCOMPARE(lowKLocalizedDate == highQDate,  false);
 
2674
    QCOMPARE(lowKLocalizedDate != lowKLocalizedDate,   false);
 
2675
    QCOMPARE(lowKLocalizedDate != highKLocalizedDate,  true);
 
2676
    QCOMPARE(lowKLocalizedDate != lowQDate,   false);
 
2677
    QCOMPARE(lowKLocalizedDate != highQDate,  true);
 
2678
    QCOMPARE(highKLocalizedDate < lowKLocalizedDate,   false);
 
2679
    QCOMPARE(lowKLocalizedDate  < highKLocalizedDate,  true);
 
2680
    QCOMPARE(highKLocalizedDate < lowQDate,   false);
 
2681
    QCOMPARE(lowKLocalizedDate  < highQDate,  true);
 
2682
    QCOMPARE(highKLocalizedDate <= lowKLocalizedDate,  false);
 
2683
    QCOMPARE(lowKLocalizedDate  <= lowKLocalizedDate,  true);
 
2684
    QCOMPARE(lowKLocalizedDate  <= highKLocalizedDate, true);
 
2685
    QCOMPARE(highKLocalizedDate <= lowQDate,  false);
 
2686
    QCOMPARE(lowKLocalizedDate  <= lowQDate,  true);
 
2687
    QCOMPARE(lowKLocalizedDate  <= highQDate, true);
 
2688
    QCOMPARE(highKLocalizedDate > lowKLocalizedDate,   true);
 
2689
    QCOMPARE(lowKLocalizedDate  > highKLocalizedDate,  false);
 
2690
    QCOMPARE(highKLocalizedDate > lowQDate,   true);
 
2691
    QCOMPARE(lowKLocalizedDate  > highQDate,  false);
 
2692
    QCOMPARE(highKLocalizedDate >= lowKLocalizedDate,  true);
 
2693
    QCOMPARE(lowKLocalizedDate  >= lowKLocalizedDate,  true);
 
2694
    QCOMPARE(lowKLocalizedDate  >= highKLocalizedDate, false);
 
2695
    QCOMPARE(highKLocalizedDate >= lowQDate,  true);
 
2696
    QCOMPARE(lowKLocalizedDate  >= lowQDate,  true);
 
2697
    QCOMPARE(lowKLocalizedDate  >= highQDate, false);
2666
2698
 
2667
2699
    // Test changing Calendar System
2668
 
    KCalendarSystem *hijri = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
2669
 
    testKLocalizedDate.setCalendarSystem( KLocale::IslamicCivilCalendar );
2670
 
    QCOMPARE( testKLocalizedDate.year(), hijri->year( testQDate ) );
 
2700
    KCalendarSystem *hijri = KCalendarSystem::create(KLocale::IslamicCivilCalendar);
 
2701
    testKLocalizedDate.setCalendarSystem(KLocale::IslamicCivilCalendar);
 
2702
    QCOMPARE(testKLocalizedDate.year(), hijri->year(testQDate));
2671
2703
 
2672
2704
    // Test copy of calendar object
2673
2705
    if (true) {
2681
2713
    newOne = KLocalizedDate::currentDate();
2682
2714
    kDebug() << newOne;
2683
2715
 
2684
 
    KLocalizedDate calendarDate( testQDate, calendar );
2685
 
    QCOMPARE( calendarDate.date(), testQDate );
2686
 
    QCOMPARE( calendarDate.day(), calendar->day( testQDate ) );
 
2716
    KLocalizedDate calendarDate(testQDate, calendar);
 
2717
    QCOMPARE(calendarDate.date(), testQDate);
 
2718
    QCOMPARE(calendarDate.day(), calendar->day(testQDate));
2687
2719
 
2688
 
    KCalendarSystem *hijriCalendar =  KCalendarSystem::create( "hijri" );
2689
 
    KLocalizedDate hijriDate( testQDate, hijriCalendar );
2690
 
    QCOMPARE( hijriDate.date(), testQDate );
2691
 
    QCOMPARE( hijriDate.day(), hijriCalendar->day( testQDate ) );
 
2720
    KCalendarSystem *hijriCalendar =  KCalendarSystem::create(KLocale::IslamicCivilCalendar);
 
2721
    KLocalizedDate hijriDate(testQDate, hijriCalendar);
 
2722
    QCOMPARE(hijriDate.date(), testQDate);
 
2723
    QCOMPARE(hijriDate.day(), hijriCalendar->day(testQDate));
2692
2724
    delete hijriCalendar;
2693
2725
}
 
2726
 
 
2727
void KCalendarTest::testWeekNumberSystem()
 
2728
{
 
2729
    KLocale *locale = new KLocale(*KGlobal::locale());
 
2730
    const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
 
2731
    int weekYear = 0;
 
2732
 
 
2733
    // Test the 7 days the year can start on:
 
2734
    // Monday    == 2018
 
2735
    // Tuesday   == 2013
 
2736
    // Wednesday == 2014
 
2737
    // Thursday  == 2015
 
2738
    // Friday    == 2016
 
2739
    // Saturday  == 2011
 
2740
    // Sunday    == 2012
 
2741
 
 
2742
    // ISO Week
 
2743
    // Monday    == 2018 == Week 1 2018
 
2744
    // Tuesday   == 2013 == Week 1 2013
 
2745
    // Wednesday == 2014 == Week 1 2014
 
2746
    // Thursday  == 2015 == Week 1 2015
 
2747
    // Friday    == 2016 == Week 53 2015
 
2748
    // Saturday  == 2011 == Week 52 2010
 
2749
    // Sunday    == 2012 == Week 52 2011
 
2750
 
 
2751
    locale->setWeekStartDay(1);
 
2752
    locale->setWeekNumberSystem(KLocale::IsoWeekNumber);
 
2753
 
 
2754
    QCOMPARE(calendar->week(QDate(2018, 1, 1), &weekYear), 1);
 
2755
    QCOMPARE(weekYear, 2018);
 
2756
    QCOMPARE(calendar->week(QDate(2013, 1, 1), &weekYear), 1);
 
2757
    QCOMPARE(weekYear, 2013);
 
2758
    QCOMPARE(calendar->week(QDate(2014, 1, 1), &weekYear), 1);
 
2759
    QCOMPARE(weekYear, 2014);
 
2760
    QCOMPARE(calendar->week(QDate(2015, 1, 1), &weekYear), 1);
 
2761
    QCOMPARE(weekYear, 2015);
 
2762
    QCOMPARE(calendar->week(QDate(2016, 1, 1), &weekYear), 53);
 
2763
    QCOMPARE(weekYear, 2015);
 
2764
    QCOMPARE(calendar->week(QDate(2011, 1, 1), &weekYear), 52);
 
2765
    QCOMPARE(weekYear, 2010);
 
2766
    QCOMPARE(calendar->week(QDate(2012, 1, 1), &weekYear), 52);
 
2767
    QCOMPARE(weekYear, 2011);
 
2768
 
 
2769
    QCOMPARE(calendar->week(QDate(2014, 12, 31), &weekYear), 1);
 
2770
    QCOMPARE(weekYear, 2015);
 
2771
    QCOMPARE(calendar->week(QDate(2015, 12, 31), &weekYear), 53);
 
2772
    QCOMPARE(weekYear, 2015);
 
2773
 
 
2774
    QCOMPARE(calendar->weeksInYear(2010), 52);
 
2775
    QCOMPARE(calendar->weeksInYear(2015), 53);
 
2776
 
 
2777
    // First Full Week starting Sunday, aka US Week
 
2778
    locale->setWeekStartDay(7);
 
2779
    locale->setWeekNumberSystem(KLocale::FirstFullWeek);
 
2780
 
 
2781
    // Mon = Jan 1 2018 = Week 52 2017, Sun = Jan 7 = Week 1
 
2782
    QCOMPARE(calendar->week(QDate(2018, 1, 1), &weekYear), 53);        //First Day
 
2783
    QCOMPARE(weekYear, 2017);
 
2784
    QCOMPARE(calendar->week(QDate(2018, 1, 6), &weekYear), 53);        //First Saturday
 
2785
    QCOMPARE(weekYear, 2017);
 
2786
    QCOMPARE(calendar->week(QDate(2018, 1, 7), &weekYear), 1);         //First Sunday
 
2787
    QCOMPARE(weekYear, 2018);
 
2788
    QCOMPARE(calendar->week(QDate(2018, 1, 13), &weekYear), 1);        //Second Saturday
 
2789
    QCOMPARE(weekYear, 2018);
 
2790
    QCOMPARE(calendar->week(QDate(2018, 1, 14), &weekYear), 2);        //Second Sunday
 
2791
    QCOMPARE(weekYear, 2018);
 
2792
    QCOMPARE(calendar->week(QDate(2018, 12, 31), &weekYear), 52);       //Last Day
 
2793
    QCOMPARE(weekYear, 2018);
 
2794
 
 
2795
    // Tue = Jan 1 2013 = Week 52 2012, Sun = Jan 6 = Week 1
 
2796
    QCOMPARE(calendar->week(QDate(2013, 1, 1), &weekYear), 53);        //First Day
 
2797
    QCOMPARE(weekYear, 2012);
 
2798
    QCOMPARE(calendar->week(QDate(2013, 1, 5), &weekYear), 53);        //First Saturday
 
2799
    QCOMPARE(weekYear, 2012);
 
2800
    QCOMPARE(calendar->week(QDate(2013, 1, 6), &weekYear), 1);         //First Sunday
 
2801
    QCOMPARE(weekYear, 2013);
 
2802
    QCOMPARE(calendar->week(QDate(2013, 1, 12), &weekYear), 1);        //Second Saturday
 
2803
    QCOMPARE(weekYear, 2013);
 
2804
    QCOMPARE(calendar->week(QDate(2013, 1, 13), &weekYear), 2);        //Second Sunday
 
2805
    QCOMPARE(weekYear, 2013);
 
2806
    QCOMPARE(calendar->week(QDate(2013, 12, 31), &weekYear), 52);       //Last Day
 
2807
    QCOMPARE(weekYear, 2013);
 
2808
 
 
2809
    // Wed = Jan 1 2014 = Week 52 2013, Sun = Jan 5 = Week 1
 
2810
    QCOMPARE(calendar->week(QDate(2014, 1, 1), &weekYear), 52);        //First Day
 
2811
    QCOMPARE(weekYear, 2013);
 
2812
    QCOMPARE(calendar->week(QDate(2014, 1, 4), &weekYear), 52);        //First Saturday
 
2813
    QCOMPARE(weekYear, 2013);
 
2814
    QCOMPARE(calendar->week(QDate(2014, 1, 5), &weekYear), 1);         //First Sunday
 
2815
    QCOMPARE(weekYear, 2014);
 
2816
    QCOMPARE(calendar->week(QDate(2014, 1, 11), &weekYear), 1);        //Second Saturday
 
2817
    QCOMPARE(weekYear, 2014);
 
2818
    QCOMPARE(calendar->week(QDate(2014, 1, 12), &weekYear), 2);        //Second Sunday
 
2819
    QCOMPARE(weekYear, 2014);
 
2820
    QCOMPARE(calendar->week(QDate(2014, 12, 31), &weekYear), 52);       //Last Day
 
2821
    QCOMPARE(weekYear, 2014);
 
2822
 
 
2823
    // Thu = Jan 1 2015 = Week 52 2014, Sun = Jan 4 = Week 1
 
2824
    QCOMPARE(calendar->week(QDate(2015, 1, 1), &weekYear), 52);        //First Day
 
2825
    QCOMPARE(weekYear, 2014);
 
2826
    QCOMPARE(calendar->week(QDate(2015, 1, 3), &weekYear), 52);        //First Saturday
 
2827
    QCOMPARE(weekYear, 2014);
 
2828
    QCOMPARE(calendar->week(QDate(2015, 1, 4), &weekYear), 1);         //First Sunday
 
2829
    QCOMPARE(weekYear, 2015);
 
2830
    QCOMPARE(calendar->week(QDate(2015, 1, 10), &weekYear), 1);        //Second Saturday
 
2831
    QCOMPARE(weekYear, 2015);
 
2832
    QCOMPARE(calendar->week(QDate(2015, 1, 11), &weekYear), 2);        //Second Sunday
 
2833
    QCOMPARE(weekYear, 2015);
 
2834
    QCOMPARE(calendar->week(QDate(2015, 12, 31), &weekYear), 52);       //Last Day
 
2835
    QCOMPARE(weekYear, 2015);
 
2836
 
 
2837
    // Fri = Jan 1 2016 = Week 52 2015, Sun = Jan 3 = Week 1
 
2838
    QCOMPARE(calendar->week(QDate(2016, 1, 1), &weekYear), 52);        //First Day
 
2839
    QCOMPARE(weekYear, 2015);
 
2840
    QCOMPARE(calendar->week(QDate(2016, 1, 2), &weekYear), 52);        //First Saturday
 
2841
    QCOMPARE(weekYear, 2015);
 
2842
    QCOMPARE(calendar->week(QDate(2016, 1, 3), &weekYear), 1);         //First Sunday
 
2843
    QCOMPARE(weekYear, 2016);
 
2844
    QCOMPARE(calendar->week(QDate(2016, 1, 9), &weekYear), 1);         //Second Saturday
 
2845
    QCOMPARE(weekYear, 2016);
 
2846
    QCOMPARE(calendar->week(QDate(2016, 1, 10), &weekYear), 2);        //Second Sunday
 
2847
    QCOMPARE(weekYear, 2016);
 
2848
    QCOMPARE(calendar->week(QDate(2016, 12, 31), &weekYear), 52);       //Last Day
 
2849
    QCOMPARE(weekYear, 2016);
 
2850
 
 
2851
    // Sat = Jan 1 2011 = Week 52 2010, Sun = Jan 2 = Week 1
 
2852
    QCOMPARE(calendar->week(QDate(2011, 1, 1), &weekYear), 52);        //First Day, First Saturday
 
2853
    QCOMPARE(weekYear, 2010);
 
2854
    QCOMPARE(calendar->week(QDate(2011, 1, 2), &weekYear), 1);         //First Sunday
 
2855
    QCOMPARE(weekYear, 2011);
 
2856
    QCOMPARE(calendar->week(QDate(2011, 1, 8), &weekYear), 1);         //Second Saturday
 
2857
    QCOMPARE(weekYear, 2011);
 
2858
    QCOMPARE(calendar->week(QDate(2011, 1, 9), &weekYear), 2);         //Second Sunday
 
2859
    QCOMPARE(weekYear, 2011);
 
2860
    QCOMPARE(calendar->week(QDate(2011, 12, 31), &weekYear), 52);       //Last Day
 
2861
    QCOMPARE(weekYear, 2011);
 
2862
 
 
2863
    // Sun = Jan 1 2012 = Week 1 2012, Sun = Jan 1 = Week 1
 
2864
    QCOMPARE(calendar->week(QDate(2012, 1, 1), &weekYear), 1);         //First Day, First Sunday
 
2865
    QCOMPARE(weekYear, 2012);
 
2866
    QCOMPARE(calendar->week(QDate(2012, 1, 7), &weekYear), 1);         //First Saturday
 
2867
    QCOMPARE(weekYear, 2012);
 
2868
    QCOMPARE(calendar->week(QDate(2012, 1, 8), &weekYear), 2);         //Second Sunday
 
2869
    QCOMPARE(weekYear, 2012);
 
2870
    QCOMPARE(calendar->week(QDate(2012, 12, 31), &weekYear), 53);       //Last Day
 
2871
    QCOMPARE(weekYear, 2012);
 
2872
 
 
2873
    // First Full Week starting Monday
 
2874
    locale->setWeekStartDay(1);
 
2875
    locale->setWeekNumberSystem(KLocale::FirstFullWeek);
 
2876
 
 
2877
    // Mon = Jan 1 2018 = Week 52 2017, Mon = Jan 1 = Week 1
 
2878
    QCOMPARE(calendar->week(QDate(2018, 1, 1), &weekYear), 1);          //First Day, First Monday
 
2879
    QCOMPARE(weekYear, 2018);
 
2880
    QCOMPARE(calendar->week(QDate(2018, 1, 7), &weekYear), 1);          //First Sunday
 
2881
    QCOMPARE(weekYear, 2018);
 
2882
    QCOMPARE(calendar->week(QDate(2018, 1, 8), &weekYear), 2);          //Second Monday
 
2883
    QCOMPARE(weekYear, 2018);
 
2884
    QCOMPARE(calendar->week(QDate(2018, 12, 31), &weekYear), 53);       //Last Day
 
2885
    QCOMPARE(weekYear, 2018);
 
2886
 
 
2887
    // Tue = Jan 1 2013 = Week 52 2012, Mon = Jan 7 = Week 1
 
2888
    QCOMPARE(calendar->week(QDate(2013, 1, 1), &weekYear), 53);         //First Day
 
2889
    QCOMPARE(weekYear, 2012);
 
2890
    QCOMPARE(calendar->week(QDate(2013, 1, 6), &weekYear), 53);         //First Sunday
 
2891
    QCOMPARE(weekYear, 2012);
 
2892
    QCOMPARE(calendar->week(QDate(2013, 1, 7), &weekYear), 1);          //First Monday
 
2893
    QCOMPARE(weekYear, 2013);
 
2894
    QCOMPARE(calendar->week(QDate(2013, 1, 13), &weekYear), 1);         //Second Saturday
 
2895
    QCOMPARE(weekYear, 2013);
 
2896
    QCOMPARE(calendar->week(QDate(2013, 1, 14), &weekYear), 2);         //Second Monday
 
2897
    QCOMPARE(weekYear, 2013);
 
2898
    QCOMPARE(calendar->week(QDate(2013, 12, 31), &weekYear), 52);       //Last Day
 
2899
    QCOMPARE(weekYear, 2013);
 
2900
 
 
2901
    // Wed = Jan 1 2014 = Week 52 2013, Mon = Jan 6 = Week 1
 
2902
    QCOMPARE(calendar->week(QDate(2014, 1, 1), &weekYear), 52);         //First Day
 
2903
    QCOMPARE(weekYear, 2013);
 
2904
    QCOMPARE(calendar->week(QDate(2014, 1, 5), &weekYear), 52);         //First Sunday
 
2905
    QCOMPARE(weekYear, 2013);
 
2906
    QCOMPARE(calendar->week(QDate(2014, 1, 6), &weekYear), 1);          //First Monday
 
2907
    QCOMPARE(weekYear, 2014);
 
2908
    QCOMPARE(calendar->week(QDate(2014, 1, 12), &weekYear), 1);         //Second Saturday
 
2909
    QCOMPARE(weekYear, 2014);
 
2910
    QCOMPARE(calendar->week(QDate(2014, 1, 13), &weekYear), 2);         //Second Monday
 
2911
    QCOMPARE(weekYear, 2014);
 
2912
    QCOMPARE(calendar->week(QDate(2014, 12, 31), &weekYear), 52);       //Last Day
 
2913
    QCOMPARE(weekYear, 2014);
 
2914
 
 
2915
    // Thu = Jan 1 2015 = Week 52 2014, Mon = Jan 5 = Week 1
 
2916
    QCOMPARE(calendar->week(QDate(2015, 1, 1), &weekYear), 52);         //First Day
 
2917
    QCOMPARE(weekYear, 2014);
 
2918
    QCOMPARE(calendar->week(QDate(2015, 1, 4), &weekYear), 52);         //First Sunday
 
2919
    QCOMPARE(weekYear, 2014);
 
2920
    QCOMPARE(calendar->week(QDate(2015, 1, 5), &weekYear), 1);          //First Monday
 
2921
    QCOMPARE(weekYear, 2015);
 
2922
    QCOMPARE(calendar->week(QDate(2015, 1, 11), &weekYear), 1);         //Second Saturday
 
2923
    QCOMPARE(weekYear, 2015);
 
2924
    QCOMPARE(calendar->week(QDate(2015, 1, 12), &weekYear), 2);         //Second Monday
 
2925
    QCOMPARE(weekYear, 2015);
 
2926
    QCOMPARE(calendar->week(QDate(2015, 12, 31), &weekYear), 52);       //Last Day
 
2927
    QCOMPARE(weekYear, 2015);
 
2928
 
 
2929
    // Fri = Jan 1 2016 = Week 52 2015, Mon = Jan 4 = Week 1
 
2930
    QCOMPARE(calendar->week(QDate(2016, 1, 1), &weekYear), 52);         //First Day
 
2931
    QCOMPARE(weekYear, 2015);
 
2932
    QCOMPARE(calendar->week(QDate(2016, 1, 3), &weekYear), 52);         //First Sunday
 
2933
    QCOMPARE(weekYear, 2015);
 
2934
    QCOMPARE(calendar->week(QDate(2016, 1, 4), &weekYear), 1);          //First Monday
 
2935
    QCOMPARE(weekYear, 2016);
 
2936
    QCOMPARE(calendar->week(QDate(2016, 1, 10), &weekYear), 1);         //Second Saturday
 
2937
    QCOMPARE(weekYear, 2016);
 
2938
    QCOMPARE(calendar->week(QDate(2016, 1, 11), &weekYear), 2);         //Second Monday
 
2939
    QCOMPARE(weekYear, 2016);
 
2940
    QCOMPARE(calendar->week(QDate(2016, 12, 31), &weekYear), 52);       //Last Day
 
2941
    QCOMPARE(weekYear, 2016);
 
2942
 
 
2943
    // Sat = Jan 1 2011 = Week 52 2010, Mon = Jan 3 = Week 1
 
2944
    QCOMPARE(calendar->week(QDate(2011, 1, 1), &weekYear), 52);        //First Day
 
2945
    QCOMPARE(weekYear, 2010);
 
2946
    QCOMPARE(calendar->week(QDate(2011, 1, 2), &weekYear), 52);        //First Sunday
 
2947
    QCOMPARE(weekYear, 2010);
 
2948
    QCOMPARE(calendar->week(QDate(2011, 1, 3), &weekYear), 1);         //First Monday
 
2949
    QCOMPARE(weekYear, 2011);
 
2950
    QCOMPARE(calendar->week(QDate(2011, 1, 9), &weekYear), 1);         //Second Sunday
 
2951
    QCOMPARE(weekYear, 2011);
 
2952
    QCOMPARE(calendar->week(QDate(2011, 1, 10), &weekYear), 2);        //Second Monday
 
2953
    QCOMPARE(weekYear, 2011);
 
2954
    QCOMPARE(calendar->week(QDate(2011, 12, 31), &weekYear), 52);       //Last Day
 
2955
    QCOMPARE(weekYear, 2011);
 
2956
 
 
2957
    // Sun = Jan 1 2012 = Week 52 2011, Mon = Jan 2 = Week 1
 
2958
    QCOMPARE(calendar->week(QDate(2012, 1, 1), &weekYear), 52);         //First Day, First Sunday
 
2959
    QCOMPARE(weekYear, 2011);
 
2960
    QCOMPARE(calendar->week(QDate(2012, 1, 2), &weekYear), 1);          //First Monday
 
2961
    QCOMPARE(weekYear, 2012);
 
2962
    QCOMPARE(calendar->week(QDate(2012, 1, 8), &weekYear), 1);          //Second Sunday
 
2963
    QCOMPARE(weekYear, 2012);
 
2964
    QCOMPARE(calendar->week(QDate(2012, 1, 9), &weekYear), 2);          //Second Monday
 
2965
    QCOMPARE(weekYear, 2012);
 
2966
    QCOMPARE(calendar->week(QDate(2012, 12, 31), &weekYear), 53);       //Last Day
 
2967
    QCOMPARE(weekYear, 2012);
 
2968
 
 
2969
 
 
2970
    // First Partial Week, second week starting Sunday
 
2971
    locale->setWeekStartDay(7);
 
2972
    locale->setWeekNumberSystem(KLocale::FirstPartialWeek);
 
2973
 
 
2974
    // Mon = Jan 1 2018 = Week 1, Sun = Jan 7 = Week 2
 
2975
    QCOMPARE(calendar->week(QDate(2018, 1, 1), &weekYear), 1);         //First Day
 
2976
    QCOMPARE(weekYear, 2018);
 
2977
    QCOMPARE(calendar->week(QDate(2018, 1, 6), &weekYear), 1);         //First Saturday
 
2978
    QCOMPARE(weekYear, 2018);
 
2979
    QCOMPARE(calendar->week(QDate(2018, 1, 7), &weekYear), 2);         //First Sunday
 
2980
    QCOMPARE(weekYear, 2018);
 
2981
    QCOMPARE(calendar->week(QDate(2018, 1, 13), &weekYear), 2);        //Second Saturday
 
2982
    QCOMPARE(weekYear, 2018);
 
2983
    QCOMPARE(calendar->week(QDate(2018, 1, 14), &weekYear), 3);        //Second Sunday
 
2984
    QCOMPARE(weekYear, 2018);
 
2985
    QCOMPARE(calendar->week(QDate(2018, 12, 31), &weekYear), 53);       //Last Day
 
2986
    QCOMPARE(weekYear, 2018);
 
2987
 
 
2988
    // Tue = Jan 1 2013 = Week 1, Sun = Jan 6 = Week 2
 
2989
    QCOMPARE(calendar->week(QDate(2013, 1, 1), &weekYear), 1);        //First Day
 
2990
    QCOMPARE(weekYear, 2013);
 
2991
    QCOMPARE(calendar->week(QDate(2013, 1, 5), &weekYear), 1);        //First Saturday
 
2992
    QCOMPARE(weekYear, 2013);
 
2993
    QCOMPARE(calendar->week(QDate(2013, 1, 6), &weekYear), 2);         //First Sunday
 
2994
    QCOMPARE(weekYear, 2013);
 
2995
    QCOMPARE(calendar->week(QDate(2013, 1, 12), &weekYear), 2);        //Second Saturday
 
2996
    QCOMPARE(weekYear, 2013);
 
2997
    QCOMPARE(calendar->week(QDate(2013, 1, 13), &weekYear), 3);        //Second Sunday
 
2998
    QCOMPARE(weekYear, 2013);
 
2999
    QCOMPARE(calendar->week(QDate(2013, 12, 31), &weekYear), 53);       //Last Day
 
3000
    QCOMPARE(weekYear, 2013);
 
3001
 
 
3002
    // Wed = Jan 1 2014 = Week 1, Sun = Jan 5 = Week 2
 
3003
    QCOMPARE(calendar->week(QDate(2014, 1, 1), &weekYear), 1);        //First Day
 
3004
    QCOMPARE(weekYear, 2014);
 
3005
    QCOMPARE(calendar->week(QDate(2014, 1, 4), &weekYear), 1);        //First Saturday
 
3006
    QCOMPARE(weekYear, 2014);
 
3007
    QCOMPARE(calendar->week(QDate(2014, 1, 5), &weekYear), 2);         //First Sunday
 
3008
    QCOMPARE(weekYear, 2014);
 
3009
    QCOMPARE(calendar->week(QDate(2014, 1, 11), &weekYear), 2);        //Second Saturday
 
3010
    QCOMPARE(weekYear, 2014);
 
3011
    QCOMPARE(calendar->week(QDate(2014, 1, 12), &weekYear), 3);        //Second Sunday
 
3012
    QCOMPARE(weekYear, 2014);
 
3013
    QCOMPARE(calendar->week(QDate(2014, 12, 31), &weekYear), 53);       //Last Day
 
3014
    QCOMPARE(weekYear, 2014);
 
3015
 
 
3016
    // Thu = Jan 1 2015 = Week 1, Sun = Jan 4 = Week 2
 
3017
    QCOMPARE(calendar->week(QDate(2015, 1, 1), &weekYear), 1);        //First Day
 
3018
    QCOMPARE(weekYear, 2015);
 
3019
    QCOMPARE(calendar->week(QDate(2015, 1, 3), &weekYear), 1);        //First Saturday
 
3020
    QCOMPARE(weekYear, 2015);
 
3021
    QCOMPARE(calendar->week(QDate(2015, 1, 4), &weekYear), 2);         //First Sunday
 
3022
    QCOMPARE(weekYear, 2015);
 
3023
    QCOMPARE(calendar->week(QDate(2015, 1, 10), &weekYear), 2);        //Second Saturday
 
3024
    QCOMPARE(weekYear, 2015);
 
3025
    QCOMPARE(calendar->week(QDate(2015, 1, 11), &weekYear), 3);        //Second Sunday
 
3026
    QCOMPARE(weekYear, 2015);
 
3027
    QCOMPARE(calendar->week(QDate(2015, 12, 31), &weekYear), 53);       //Last Day
 
3028
    QCOMPARE(weekYear, 2015);
 
3029
 
 
3030
    // Fri = Jan 1 2016 = Week 1, Sun = Jan 3 = Week 2
 
3031
    QCOMPARE(calendar->week(QDate(2016, 1, 1), &weekYear), 1);        //First Day
 
3032
    QCOMPARE(weekYear, 2016);
 
3033
    QCOMPARE(calendar->week(QDate(2016, 1, 2), &weekYear), 1);        //First Saturday
 
3034
    QCOMPARE(weekYear, 2016);
 
3035
    QCOMPARE(calendar->week(QDate(2016, 1, 3), &weekYear), 2);         //First Sunday
 
3036
    QCOMPARE(weekYear, 2016);
 
3037
    QCOMPARE(calendar->week(QDate(2016, 1, 9), &weekYear), 2);         //Second Saturday
 
3038
    QCOMPARE(weekYear, 2016);
 
3039
    QCOMPARE(calendar->week(QDate(2016, 1, 10), &weekYear), 3);        //Second Sunday
 
3040
    QCOMPARE(weekYear, 2016);
 
3041
    QCOMPARE(calendar->week(QDate(2016, 12, 31), &weekYear), 53);       //Last Day
 
3042
    QCOMPARE(weekYear, 2016);
 
3043
 
 
3044
    // Sat = Jan 1 2011 = Week 1, Sun = Jan 2 = Week 2
 
3045
    QCOMPARE(calendar->week(QDate(2011, 1, 1), &weekYear), 1);        //First Day, First Saturday
 
3046
    QCOMPARE(weekYear, 2011);
 
3047
    QCOMPARE(calendar->week(QDate(2011, 1, 2), &weekYear), 2);         //First Sunday
 
3048
    QCOMPARE(weekYear, 2011);
 
3049
    QCOMPARE(calendar->week(QDate(2011, 1, 8), &weekYear), 2);         //Second Saturday
 
3050
    QCOMPARE(weekYear, 2011);
 
3051
    QCOMPARE(calendar->week(QDate(2011, 1, 9), &weekYear), 3);         //Second Sunday
 
3052
    QCOMPARE(weekYear, 2011);
 
3053
    QCOMPARE(calendar->week(QDate(2011, 12, 31), &weekYear), 53);       //Last Day
 
3054
    QCOMPARE(weekYear, 2011);
 
3055
 
 
3056
    // Sun = Jan 1 2012 = Week 1, Sun = Jan 1 = Week 1
 
3057
    QCOMPARE(calendar->week(QDate(2012, 1, 1), &weekYear), 1);         //First Day, First Sunday
 
3058
    QCOMPARE(weekYear, 2012);
 
3059
    QCOMPARE(calendar->week(QDate(2012, 1, 7), &weekYear), 1);         //First Saturday
 
3060
    QCOMPARE(weekYear, 2012);
 
3061
    QCOMPARE(calendar->week(QDate(2012, 1, 8), &weekYear), 2);         //Second Sunday
 
3062
    QCOMPARE(weekYear, 2012);
 
3063
    QCOMPARE(calendar->week(QDate(2012, 12, 31), &weekYear), 53);       //Last Day
 
3064
    QCOMPARE(weekYear, 2012);
 
3065
 
 
3066
    // First Partial Week starting Monday
 
3067
    locale->setWeekStartDay(1);
 
3068
    locale->setWeekNumberSystem(KLocale::FirstPartialWeek);
 
3069
 
 
3070
    // Mon = Jan 1 2018 = Week 1, Mon = Jan 1 = Week 2
 
3071
    QCOMPARE(calendar->week(QDate(2018, 1, 1), &weekYear), 1);          //First Day, First Monday
 
3072
    QCOMPARE(weekYear, 2018);
 
3073
    QCOMPARE(calendar->week(QDate(2018, 1, 7), &weekYear), 1);          //First Sunday
 
3074
    QCOMPARE(weekYear, 2018);
 
3075
    QCOMPARE(calendar->week(QDate(2018, 1, 8), &weekYear), 2);          //Second Monday
 
3076
    QCOMPARE(weekYear, 2018);
 
3077
    QCOMPARE(calendar->week(QDate(2018, 12, 31), &weekYear), 53);       //Last Day
 
3078
    QCOMPARE(weekYear, 2018);
 
3079
 
 
3080
    // Tue = Jan 1 2013 = Week 1, Mon = Jan 7 = Week 2
 
3081
    QCOMPARE(calendar->week(QDate(2013, 1, 1), &weekYear), 1);          //First Day
 
3082
    QCOMPARE(weekYear, 2013);
 
3083
    QCOMPARE(calendar->week(QDate(2013, 1, 6), &weekYear), 1);          //First Sunday
 
3084
    QCOMPARE(weekYear, 2013);
 
3085
    QCOMPARE(calendar->week(QDate(2013, 1, 7), &weekYear), 2);          //First Monday
 
3086
    QCOMPARE(weekYear, 2013);
 
3087
    QCOMPARE(calendar->week(QDate(2013, 1, 13), &weekYear), 2);         //Second Saturday
 
3088
    QCOMPARE(weekYear, 2013);
 
3089
    QCOMPARE(calendar->week(QDate(2013, 1, 14), &weekYear), 3);         //Second Monday
 
3090
    QCOMPARE(weekYear, 2013);
 
3091
    QCOMPARE(calendar->week(QDate(2013, 12, 31), &weekYear), 53);       //Last Day
 
3092
    QCOMPARE(weekYear, 2013);
 
3093
 
 
3094
    // Wed = Jan 1 2014 = Week 1, Mon = Jan 6 = Week 2
 
3095
    QCOMPARE(calendar->week(QDate(2014, 1, 1), &weekYear), 1);          //First Day
 
3096
    QCOMPARE(weekYear, 2014);
 
3097
    QCOMPARE(calendar->week(QDate(2014, 1, 5), &weekYear), 1);          //First Sunday
 
3098
    QCOMPARE(weekYear, 2014);
 
3099
    QCOMPARE(calendar->week(QDate(2014, 1, 6), &weekYear), 2);          //First Monday
 
3100
    QCOMPARE(weekYear, 2014);
 
3101
    QCOMPARE(calendar->week(QDate(2014, 1, 12), &weekYear), 2);         //Second Saturday
 
3102
    QCOMPARE(weekYear, 2014);
 
3103
    QCOMPARE(calendar->week(QDate(2014, 1, 13), &weekYear), 3);         //Second Monday
 
3104
    QCOMPARE(weekYear, 2014);
 
3105
    QCOMPARE(calendar->week(QDate(2014, 12, 31), &weekYear), 53);       //Last Day
 
3106
    QCOMPARE(weekYear, 2014);
 
3107
 
 
3108
    // Thu = Jan 1 2015 = Week 1, Mon = Jan 5 = Week 2
 
3109
    QCOMPARE(calendar->week(QDate(2015, 1, 1), &weekYear), 1);          //First Day
 
3110
    QCOMPARE(weekYear, 2015);
 
3111
    QCOMPARE(calendar->week(QDate(2015, 1, 4), &weekYear), 1);          //First Sunday
 
3112
    QCOMPARE(weekYear, 2015);
 
3113
    QCOMPARE(calendar->week(QDate(2015, 1, 5), &weekYear), 2);          //First Monday
 
3114
    QCOMPARE(weekYear, 2015);
 
3115
    QCOMPARE(calendar->week(QDate(2015, 1, 11), &weekYear), 2);         //Second Saturday
 
3116
    QCOMPARE(weekYear, 2015);
 
3117
    QCOMPARE(calendar->week(QDate(2015, 1, 12), &weekYear), 3);         //Second Monday
 
3118
    QCOMPARE(weekYear, 2015);
 
3119
    QCOMPARE(calendar->week(QDate(2015, 12, 31), &weekYear), 53);       //Last Day
 
3120
    QCOMPARE(weekYear, 2015);
 
3121
 
 
3122
    // Fri = Jan 1 2016 = Week 1, Mon = Jan 4 = Week 2
 
3123
    QCOMPARE(calendar->week(QDate(2016, 1, 1), &weekYear), 1);          //First Day
 
3124
    QCOMPARE(weekYear, 2016);
 
3125
    QCOMPARE(calendar->week(QDate(2016, 1, 3), &weekYear), 1);          //First Sunday
 
3126
    QCOMPARE(weekYear, 2016);
 
3127
    QCOMPARE(calendar->week(QDate(2016, 1, 4), &weekYear), 2);          //First Monday
 
3128
    QCOMPARE(weekYear, 2016);
 
3129
    QCOMPARE(calendar->week(QDate(2016, 1, 10), &weekYear), 2);         //Second Saturday
 
3130
    QCOMPARE(weekYear, 2016);
 
3131
    QCOMPARE(calendar->week(QDate(2016, 1, 11), &weekYear), 3);         //Second Monday
 
3132
    QCOMPARE(weekYear, 2016);
 
3133
    QCOMPARE(calendar->week(QDate(2016, 12, 31), &weekYear), 53);       //Last Day
 
3134
    QCOMPARE(weekYear, 2016);
 
3135
 
 
3136
    // Sat = Jan 1 2011 = Week 1, Mon = Jan 3 = Week 2
 
3137
    QCOMPARE(calendar->week(QDate(2011, 1, 1), &weekYear), 1);         //First Day
 
3138
    QCOMPARE(weekYear, 2011);
 
3139
    QCOMPARE(calendar->week(QDate(2011, 1, 2), &weekYear), 1);         //First Sunday
 
3140
    QCOMPARE(weekYear, 2011);
 
3141
    QCOMPARE(calendar->week(QDate(2011, 1, 3), &weekYear), 2);         //First Monday
 
3142
    QCOMPARE(weekYear, 2011);
 
3143
    QCOMPARE(calendar->week(QDate(2011, 1, 9), &weekYear), 2);         //Second Sunday
 
3144
    QCOMPARE(weekYear, 2011);
 
3145
    QCOMPARE(calendar->week(QDate(2011, 1, 10), &weekYear), 3);        //Second Monday
 
3146
    QCOMPARE(weekYear, 2011);
 
3147
    QCOMPARE(calendar->week(QDate(2011, 12, 31), &weekYear), 53);       //Last Day
 
3148
    QCOMPARE(weekYear, 2011);
 
3149
 
 
3150
    // Sun = Jan 1 2012 = Week 1, Mon = Jan 2 = Week 2
 
3151
    QCOMPARE(calendar->week(QDate(2012, 1, 1), &weekYear), 1);         //First Day, First Sunday
 
3152
    QCOMPARE(weekYear, 2012);
 
3153
    QCOMPARE(calendar->week(QDate(2012, 1, 2), &weekYear), 2);          //First Monday
 
3154
    QCOMPARE(weekYear, 2012);
 
3155
    QCOMPARE(calendar->week(QDate(2012, 1, 8), &weekYear), 2);          //Second Sunday
 
3156
    QCOMPARE(weekYear, 2012);
 
3157
    QCOMPARE(calendar->week(QDate(2012, 1, 9), &weekYear), 3);          //Second Monday
 
3158
    QCOMPARE(weekYear, 2012);
 
3159
    QCOMPARE(calendar->week(QDate(2012, 12, 31), &weekYear), 54);       //Last Day
 
3160
    QCOMPARE(weekYear, 2012);
 
3161
 
 
3162
    // Simple weeks starting Jan 1
 
3163
    locale->setWeekStartDay(1);
 
3164
    locale->setWeekNumberSystem(KLocale::SimpleWeek);
 
3165
 
 
3166
    // Mon = Jan 1 2018
 
3167
    QCOMPARE(calendar->week(QDate(2018, 1, 1), &weekYear), 1);         //First Day, Monday
 
3168
    QCOMPARE(weekYear, 2018);
 
3169
    QCOMPARE(calendar->week(QDate(2018, 1, 7), &weekYear), 1);
 
3170
    QCOMPARE(weekYear, 2018);
 
3171
    QCOMPARE(calendar->week(QDate(2018, 1, 8), &weekYear), 2);         //Second Week
 
3172
    QCOMPARE(weekYear, 2018);
 
3173
    QCOMPARE(calendar->week(QDate(2018, 1, 14), &weekYear), 2);
 
3174
    QCOMPARE(weekYear, 2018);
 
3175
    QCOMPARE(calendar->week(QDate(2018, 1, 15), &weekYear), 3);        //Third Week
 
3176
    QCOMPARE(weekYear, 2018);
 
3177
 
 
3178
    // Tue = Jan 1 2013
 
3179
    QCOMPARE(calendar->week(QDate(2013, 1, 1), &weekYear), 1);         //First Day, Tuesday
 
3180
    QCOMPARE(weekYear, 2013);
 
3181
    QCOMPARE(calendar->week(QDate(2013, 1, 7), &weekYear), 1);
 
3182
    QCOMPARE(weekYear, 2013);
 
3183
    QCOMPARE(calendar->week(QDate(2013, 1, 8), &weekYear), 2);         //Second Week
 
3184
    QCOMPARE(weekYear, 2013);
 
3185
    QCOMPARE(calendar->week(QDate(2013, 1, 14), &weekYear), 2);
 
3186
    QCOMPARE(weekYear, 2013);
 
3187
    QCOMPARE(calendar->week(QDate(2013, 1, 15), &weekYear), 3);        //Third Week
 
3188
    QCOMPARE(weekYear, 2013);
 
3189
 
 
3190
    // Wed = Jan 1 2014
 
3191
    QCOMPARE(calendar->week(QDate(2014, 1, 1), &weekYear), 1);         //First Day, Wednesday
 
3192
    QCOMPARE(weekYear, 2014);
 
3193
    QCOMPARE(calendar->week(QDate(2014, 1, 7), &weekYear), 1);
 
3194
    QCOMPARE(weekYear, 2014);
 
3195
    QCOMPARE(calendar->week(QDate(2014, 1, 8), &weekYear), 2);         //Second Week
 
3196
    QCOMPARE(weekYear, 2014);
 
3197
    QCOMPARE(calendar->week(QDate(2014, 1, 14), &weekYear), 2);
 
3198
    QCOMPARE(weekYear, 2014);
 
3199
    QCOMPARE(calendar->week(QDate(2014, 1, 15), &weekYear), 3);        //Third Week
 
3200
    QCOMPARE(weekYear, 2014);
 
3201
 
 
3202
    // Thu = Jan 1 2015
 
3203
    QCOMPARE(calendar->week(QDate(2015, 1, 1), &weekYear), 1);         //First Day, Thursday
 
3204
    QCOMPARE(weekYear, 2015);
 
3205
    QCOMPARE(calendar->week(QDate(2015, 1, 7), &weekYear), 1);
 
3206
    QCOMPARE(weekYear, 2015);
 
3207
    QCOMPARE(calendar->week(QDate(2015, 1, 8), &weekYear), 2);         //Second Week
 
3208
    QCOMPARE(weekYear, 2015);
 
3209
    QCOMPARE(calendar->week(QDate(2015, 1, 14), &weekYear), 2);
 
3210
    QCOMPARE(weekYear, 2015);
 
3211
    QCOMPARE(calendar->week(QDate(2015, 1, 15), &weekYear), 3);        //Third Week
 
3212
    QCOMPARE(weekYear, 2015);
 
3213
 
 
3214
    // Fri = Jan 1 2016
 
3215
    QCOMPARE(calendar->week(QDate(2016, 1, 1), &weekYear), 1);         //First Day, Monday
 
3216
    QCOMPARE(weekYear, 2016);
 
3217
    QCOMPARE(calendar->week(QDate(2016, 1, 7), &weekYear), 1);
 
3218
    QCOMPARE(weekYear, 2016);
 
3219
    QCOMPARE(calendar->week(QDate(2016, 1, 8), &weekYear), 2);         //Second Week
 
3220
    QCOMPARE(weekYear, 2016);
 
3221
    QCOMPARE(calendar->week(QDate(2016, 1, 14), &weekYear), 2);
 
3222
    QCOMPARE(weekYear, 2016);
 
3223
    QCOMPARE(calendar->week(QDate(2016, 1, 15), &weekYear), 3);        //Third Week
 
3224
    QCOMPARE(weekYear, 2016);
 
3225
 
 
3226
    // Sat = Jan 1 2011
 
3227
    QCOMPARE(calendar->week(QDate(2011, 1, 1), &weekYear), 1);         //First Day, Monday
 
3228
    QCOMPARE(weekYear, 2011);
 
3229
    QCOMPARE(calendar->week(QDate(2011, 1, 7), &weekYear), 1);
 
3230
    QCOMPARE(weekYear, 2011);
 
3231
    QCOMPARE(calendar->week(QDate(2011, 1, 8), &weekYear), 2);         //Second Week
 
3232
    QCOMPARE(weekYear, 2011);
 
3233
    QCOMPARE(calendar->week(QDate(2011, 1, 14), &weekYear), 2);
 
3234
    QCOMPARE(weekYear, 2011);
 
3235
    QCOMPARE(calendar->week(QDate(2011, 1, 15), &weekYear), 3);        //Third Week
 
3236
    QCOMPARE(weekYear, 2011);
 
3237
 
 
3238
    // Sun = Jan 1 2012
 
3239
    QCOMPARE(calendar->week(QDate(2012, 1, 1), &weekYear), 1);         //First Day, Monday
 
3240
    QCOMPARE(weekYear, 2012);
 
3241
    QCOMPARE(calendar->week(QDate(2012, 1, 7), &weekYear), 1);
 
3242
    QCOMPARE(weekYear, 2012);
 
3243
    QCOMPARE(calendar->week(QDate(2012, 1, 8), &weekYear), 2);         //Second Week
 
3244
    QCOMPARE(weekYear, 2012);
 
3245
    QCOMPARE(calendar->week(QDate(2012, 1, 14), &weekYear), 2);
 
3246
    QCOMPARE(weekYear, 2012);
 
3247
    QCOMPARE(calendar->week(QDate(2012, 1, 15), &weekYear), 3);        //Third Week
 
3248
    QCOMPARE(weekYear, 2012);
 
3249
 
 
3250
    delete calendar;
 
3251
    delete locale;
 
3252
}