17
37
#include "kcalendartest.moc"
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*/)
21
41
void KCalendarTest::testTypes()
23
43
const KCalendarSystem *calendar;
24
calendar = KCalendarSystem::create( "coptic" );
25
QCOMPARE( calendar->calendarType(), QString("coptic") );
26
QCOMPARE( calendar->calendarSystem(), KLocale::CopticCalendar );
28
calendar = KCalendarSystem::create( "ethiopian" );
29
QCOMPARE( calendar->calendarType(), QString("ethiopian") );
30
QCOMPARE( calendar->calendarSystem(), KLocale::EthiopianCalendar );
32
calendar = KCalendarSystem::create( "gregorian" );
33
QCOMPARE( calendar->calendarType(), QString("gregorian") );
34
QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
36
calendar = KCalendarSystem::create( "gregorian-proleptic" );
37
QCOMPARE( calendar->calendarType(), QString("gregorian-proleptic") );
38
QCOMPARE( calendar->calendarSystem(), KLocale::GregorianCalendar );
40
calendar = KCalendarSystem::create( "hebrew" );
41
QCOMPARE( calendar->calendarType(), QString("hebrew") );
42
QCOMPARE( calendar->calendarSystem(), KLocale::HebrewCalendar );
44
calendar = KCalendarSystem::create( "hijri" );
45
QCOMPARE( calendar->calendarType(), QString("hijri") );
46
QCOMPARE( calendar->calendarSystem(), KLocale::IslamicCivilCalendar );
48
calendar = KCalendarSystem::create( "indian-national" );
49
QCOMPARE( calendar->calendarType(), QString("indian-national") );
50
QCOMPARE( calendar->calendarSystem(), KLocale::IndianNationalCalendar );
52
calendar = KCalendarSystem::create( "jalali" );
53
QCOMPARE( calendar->calendarType(), QString("jalali") );
54
QCOMPARE( calendar->calendarSystem(), KLocale::JalaliCalendar );
56
calendar = KCalendarSystem::create( "japanese" );
57
QCOMPARE( calendar->calendarType(), QString("japanese") );
58
QCOMPARE( calendar->calendarSystem(), KLocale::JapaneseCalendar );
60
calendar = KCalendarSystem::create( "julian" );
61
QCOMPARE( calendar->calendarType(), QString("julian") );
62
QCOMPARE( calendar->calendarSystem(), KLocale::JulianCalendar );
64
calendar = KCalendarSystem::create( "minguo" );
65
QCOMPARE( calendar->calendarType(), QString("minguo") );
66
QCOMPARE( calendar->calendarSystem(), KLocale::MinguoCalendar );
68
calendar = KCalendarSystem::create( "thai" );
69
QCOMPARE( calendar->calendarType(), QString("thai") );
70
QCOMPARE( calendar->calendarSystem(), KLocale::ThaiCalendar );
72
calendar = KCalendarSystem::create( "invalid" );
73
QCOMPARE( calendar->calendarType(), QString("gregorian") );
74
QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
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);
48
calendar = KCalendarSystem::create("ethiopian");
49
QCOMPARE(calendar->calendarType(), QString("ethiopian"));
50
QCOMPARE(calendar->calendarSystem(), KLocale::EthiopianCalendar);
52
calendar = KCalendarSystem::create("gregorian");
53
QCOMPARE(calendar->calendarType(), QString("gregorian"));
54
QCOMPARE(calendar->calendarSystem(), KLocale::QDateCalendar);
56
calendar = KCalendarSystem::create("gregorian-proleptic");
57
QCOMPARE(calendar->calendarType(), QString("gregorian-proleptic"));
58
QCOMPARE(calendar->calendarSystem(), KLocale::GregorianCalendar);
60
calendar = KCalendarSystem::create("hebrew");
61
QCOMPARE(calendar->calendarType(), QString("hebrew"));
62
QCOMPARE(calendar->calendarSystem(), KLocale::HebrewCalendar);
64
calendar = KCalendarSystem::create("hijri");
65
QCOMPARE(calendar->calendarType(), QString("hijri"));
66
QCOMPARE(calendar->calendarSystem(), KLocale::IslamicCivilCalendar);
68
calendar = KCalendarSystem::create("indian-national");
69
QCOMPARE(calendar->calendarType(), QString("indian-national"));
70
QCOMPARE(calendar->calendarSystem(), KLocale::IndianNationalCalendar);
72
calendar = KCalendarSystem::create("jalali");
73
QCOMPARE(calendar->calendarType(), QString("jalali"));
74
QCOMPARE(calendar->calendarSystem(), KLocale::JalaliCalendar);
76
calendar = KCalendarSystem::create("japanese");
77
QCOMPARE(calendar->calendarType(), QString("japanese"));
78
QCOMPARE(calendar->calendarSystem(), KLocale::JapaneseCalendar);
80
calendar = KCalendarSystem::create("julian");
81
QCOMPARE(calendar->calendarType(), QString("julian"));
82
QCOMPARE(calendar->calendarSystem(), KLocale::JulianCalendar);
84
calendar = KCalendarSystem::create("minguo");
85
QCOMPARE(calendar->calendarType(), QString("minguo"));
86
QCOMPARE(calendar->calendarSystem(), KLocale::MinguoCalendar);
88
calendar = KCalendarSystem::create("thai");
89
QCOMPARE(calendar->calendarType(), QString("thai"));
90
QCOMPARE(calendar->calendarSystem(), KLocale::ThaiCalendar);
92
calendar = KCalendarSystem::create("invalid");
93
QCOMPARE(calendar->calendarType(), QString("gregorian"));
94
QCOMPARE(calendar->calendarSystem(), KLocale::QDateCalendar);
96
calendar = KCalendarSystem::create(QString());
97
QCOMPARE(calendar->calendarType(), QString("gregorian"));
98
QCOMPARE(calendar->calendarSystem(), KLocale::QDateCalendar);
81
calendar = KCalendarSystem::create( KLocale::QDateCalendar );
82
QCOMPARE( calendar->calendarType(), QString("gregorian") );
83
QCOMPARE( calendar->calendarSystem(), KLocale::QDateCalendar );
85
calendar = KCalendarSystem::create( KLocale::CopticCalendar );
86
QCOMPARE( calendar->calendarType(), QString("coptic") );
87
QCOMPARE( calendar->calendarSystem(), KLocale::CopticCalendar );
89
calendar = KCalendarSystem::create( KLocale::EthiopianCalendar );
90
QCOMPARE( calendar->calendarType(), QString("ethiopian") );
91
QCOMPARE( calendar->calendarSystem(), KLocale::EthiopianCalendar );
93
calendar = KCalendarSystem::create( KLocale::GregorianCalendar );
94
QCOMPARE( calendar->calendarType(), QString("gregorian-proleptic") );
95
QCOMPARE( calendar->calendarSystem(), KLocale::GregorianCalendar );
97
calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
98
QCOMPARE( calendar->calendarType(), QString("hebrew") );
99
QCOMPARE( calendar->calendarSystem(), KLocale::HebrewCalendar );
101
calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
102
QCOMPARE( calendar->calendarType(), QString("hijri") );
103
QCOMPARE( calendar->calendarSystem(), KLocale::IslamicCivilCalendar );
105
calendar = KCalendarSystem::create( KLocale::IndianNationalCalendar );
106
QCOMPARE( calendar->calendarType(), QString("indian-national") );
107
QCOMPARE( calendar->calendarSystem(), KLocale::IndianNationalCalendar );
109
calendar = KCalendarSystem::create( KLocale::JalaliCalendar );
110
QCOMPARE( calendar->calendarType(), QString("jalali") );
111
QCOMPARE( calendar->calendarSystem(), KLocale::JalaliCalendar );
113
calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
114
QCOMPARE( calendar->calendarType(), QString("japanese") );
115
QCOMPARE( calendar->calendarSystem(), KLocale::JapaneseCalendar );
117
calendar = KCalendarSystem::create( KLocale::JulianCalendar );
118
QCOMPARE( calendar->calendarType(), QString("julian") );
119
QCOMPARE( calendar->calendarSystem(), KLocale::JulianCalendar );
121
calendar = KCalendarSystem::create( KLocale::MinguoCalendar );
122
QCOMPARE( calendar->calendarType(), QString("minguo") );
123
QCOMPARE( calendar->calendarSystem(), KLocale::MinguoCalendar );
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);
105
calendar = KCalendarSystem::create(KLocale::CopticCalendar);
106
QCOMPARE(calendar->calendarType(), QString("coptic"));
107
QCOMPARE(calendar->calendarSystem(), KLocale::CopticCalendar);
109
calendar = KCalendarSystem::create(KLocale::EthiopianCalendar);
110
QCOMPARE(calendar->calendarType(), QString("ethiopian"));
111
QCOMPARE(calendar->calendarSystem(), KLocale::EthiopianCalendar);
113
calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
114
QCOMPARE(calendar->calendarType(), QString("gregorian-proleptic"));
115
QCOMPARE(calendar->calendarSystem(), KLocale::GregorianCalendar);
117
calendar = KCalendarSystem::create(KLocale::HebrewCalendar);
118
QCOMPARE(calendar->calendarType(), QString("hebrew"));
119
QCOMPARE(calendar->calendarSystem(), KLocale::HebrewCalendar);
121
calendar = KCalendarSystem::create(KLocale::IslamicCivilCalendar);
122
QCOMPARE(calendar->calendarType(), QString("hijri"));
123
QCOMPARE(calendar->calendarSystem(), KLocale::IslamicCivilCalendar);
125
calendar = KCalendarSystem::create(KLocale::IndianNationalCalendar);
126
QCOMPARE(calendar->calendarType(), QString("indian-national"));
127
QCOMPARE(calendar->calendarSystem(), KLocale::IndianNationalCalendar);
129
calendar = KCalendarSystem::create(KLocale::JalaliCalendar);
130
QCOMPARE(calendar->calendarType(), QString("jalali"));
131
QCOMPARE(calendar->calendarSystem(), KLocale::JalaliCalendar);
133
calendar = KCalendarSystem::create(KLocale::JapaneseCalendar);
134
QCOMPARE(calendar->calendarType(), QString("japanese"));
135
QCOMPARE(calendar->calendarSystem(), KLocale::JapaneseCalendar);
137
calendar = KCalendarSystem::create(KLocale::JulianCalendar);
138
QCOMPARE(calendar->calendarType(), QString("julian"));
139
QCOMPARE(calendar->calendarSystem(), KLocale::JulianCalendar);
141
calendar = KCalendarSystem::create(KLocale::MinguoCalendar);
142
QCOMPARE(calendar->calendarType(), QString("minguo"));
143
QCOMPARE(calendar->calendarSystem(), KLocale::MinguoCalendar);
145
calendar = KCalendarSystem::create(KLocale::ThaiCalendar);
146
QCOMPARE(calendar->calendarType(), QString("thai"));
147
QCOMPARE(calendar->calendarSystem(), KLocale::ThaiCalendar);
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"));
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 ) );
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" ) );
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));
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"));
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"));
188
208
void KCalendarTest::testFormatDate()
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);
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"));
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-"));
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"));
246
testDate.setDate( 2005, 1, 2 );
266
testDate.setDate(2005, 1, 2);
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"));
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"));
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"));
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"));
301
321
//Test various year options
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" ) );
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" ) );
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" ) );
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" ) );
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" ) );
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" ) );
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" ) );
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" ) );
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" ) );
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"));
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"));
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"));
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"));
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"));
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"));
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"));
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"));
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"));
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"));
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"));
484
504
void KCalendarTest::testFormatUnicode()
486
KLocale *locale = new KLocale( *KGlobal::locale() );
487
locale->setDateFormatShort( "%y-%m-%d" );
488
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
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" );
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);
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");
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");
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)
519
QCOMPARE( calendar->formatDate( testDate, testFormat, KLocale::UnicodeFormat ), testDate.toString( testFormat ) );
539
QCOMPARE(calendar->formatDate(testDate, testFormat, KLocale::UnicodeFormat), testDate.toString(testFormat));
522
542
void KCalendarTest::testReadDate()
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();
529
549
//Test default settings
530
QDate testDate( 2005, 10, 20 );
550
QDate testDate(2005, 10, 20);
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));
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));
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));
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());
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 ) );
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 ) );
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 ) );
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 ) );
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));
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));
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));
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));
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));
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 ) );
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 ) );
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 ) );
614
calendar->setDateIsoWeek( testDate, currentYear, 46, 5 );
615
QCOMPARE( calendar->readDate( "W46-5", "W%V-%u" ), testDate );
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));
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));
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));
634
calendar->setDateIsoWeek(testDate, currentYear, 46, 5);
635
QCOMPARE(calendar->readDate("W46-5", "W%V-%u"), testDate);
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());
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));
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));
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
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));
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));
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));
755
775
void KCalendarTest::testIsoWeekDate()
757
KLocale *locale = new KLocale( *KGlobal::locale() );
758
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
760
int earliestValidYear = calendar->year( calendar->earliestValidDate() );
761
int latestValidYear = calendar->year( calendar->latestValidDate() );
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 );
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 );
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 );
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() );
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() );
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() );
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 ) );
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 ) );
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);
780
int earliestValidYear = calendar->year(calendar->earliestValidDate());
781
int latestValidYear = calendar->year(calendar->latestValidDate());
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);
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);
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);
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());
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());
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());
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));
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));
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));
835
855
void KCalendarTest::testHebrewStrings()
838
Ref table for numbers to Hebrew chars
840
Value 1 2 3 4 5 6 7 8 9
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
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
848
x 100 Qof �0�5 Resh �0�6 Shin �0�7 Tav �0�8
849
0x05E7 0x05E8 0x05E9 0x05EA
851
Note special cases 15 = 9 + 6 �0�0�0�7 and 16 = 9 + 7 �0�0�0�8
858
Ref table for numbers to Hebrew chars
860
Value 1 2 3 4 5 6 7 8 9
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
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
868
x 100 Qof �0�5 Resh �0�6 Shin �0�7 Tav �0�8
869
0x05E7 0x05E8 0x05E9 0x05EA
871
Note special cases 15 = 9 + 6 �0�0�0�7 and 16 = 9 + 7 �0�0�0�8
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") {
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);
881
901
kDebug() << "Cannot set Hebrew language, please install and re-test!";
883
setlocale( LC_ALL, oldLocale.toLatin1() );
903
setlocale(LC_ALL, oldLocale.toLatin1());
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)
888
908
QDate resultDate;
889
calendar->setDateIsoWeek( resultDate, year, isoWeek, dayOfWeek );
909
calendar->setDateIsoWeek(resultDate, year, isoWeek, dayOfWeek);
890
910
return resultDate;
893
913
void KCalendarTest::testDayOfYearDate()
895
KLocale *locale = new KLocale( *KGlobal::locale() );
896
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar, locale );
898
int earliestValidYear = calendar->year( calendar->earliestValidDate() );
899
int latestValidYear = calendar->year( calendar->latestValidDate() );
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 );
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 );
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() );
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);
918
int earliestValidYear = calendar->year(calendar->earliestValidDate());
919
int latestValidYear = calendar->year(calendar->latestValidDate());
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);
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);
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());
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());
935
QDate KCalendarTest::setDayOfYearDate( const KCalendarSystem * calendar, int year, int dayOfYear )
955
QDate KCalendarTest::setDayOfYearDate(const KCalendarSystem * calendar, int year, int dayOfYear)
937
957
QDate resultDate;
938
calendar->setDate( resultDate, year, dayOfYear );
958
calendar->setDate(resultDate, year, dayOfYear);
939
959
return resultDate;
942
962
void KCalendarTest::testDateDifference()
944
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
964
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
945
965
QDate testDate1, testDate2;
947
967
// Date Difference
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);
977
997
// Years Difference
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);
994
1014
// Months Difference
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);
1014
1034
// Days Difference
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);
1022
1042
// Test for crossing Julian/Gregorian switch!!!
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)
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);
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 );
1046
void KCalendarTest::compareYearDifference( const KCalendarSystem *calendar,
1047
const QDate &lowDate, const QDate &highDate,
1050
if ( highDate >= lowDate ) {
1051
QCOMPARE( calendar->yearsDifference( lowDate, highDate ), yearsDiff );
1053
if ( highDate > lowDate ) {
1054
QCOMPARE( calendar->yearsDifference( highDate, lowDate ), -yearsDiff );
1058
void KCalendarTest::compareMonthDifference( const KCalendarSystem *calendar,
1059
const QDate &lowDate, const QDate &highDate,
1062
if ( highDate >= lowDate ) {
1063
QCOMPARE( calendar->monthsDifference( lowDate, highDate ), monthsDiff );
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);
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);
1066
void KCalendarTest::compareYearDifference(const KCalendarSystem *calendar,
1067
const QDate &lowDate, const QDate &highDate,
1070
if (highDate >= lowDate) {
1071
QCOMPARE(calendar->yearsDifference(lowDate, highDate), yearsDiff);
1073
if (highDate > lowDate) {
1074
QCOMPARE(calendar->yearsDifference(highDate, lowDate), -yearsDiff);
1078
void KCalendarTest::compareMonthDifference(const KCalendarSystem *calendar,
1079
const QDate &lowDate, const QDate &highDate,
1082
if (highDate >= lowDate) {
1083
QCOMPARE(calendar->monthsDifference(lowDate, highDate), monthsDiff);
1085
if (highDate > lowDate) {
1086
QCOMPARE(calendar->monthsDifference(highDate, lowDate), -monthsDiff);
1070
1090
void KCalendarTest::testFirstLast()
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);
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));
1085
1105
void KCalendarTest::testEra()
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();
1091
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1111
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
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());
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" ) );
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 );
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 );
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() );
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"));
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);
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);
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());
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));
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"));
1159
1179
cg.deleteGroup();
1160
1180
cg.markAsClean();
1162
1182
delete calendar;
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)
1167
1187
QDate resultDate;
1168
calendar->setDate( resultDate, era, yearInEra, month, day );
1188
calendar->setDate(resultDate, era, yearInEra, month, day);
1169
1189
return resultDate;
1172
void KCalendarTest::testGregorian()
1192
void KCalendarTest::testQDateCalendar()
1174
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1175
QDate testDate( 2005, 9, 10 );
1177
QCOMPARE( calendar->dayOfYear( testDate ), 253 );
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 );
1185
QDate newDate = calendar->addYears( testDate, 4);
1186
QCOMPARE( newDate.year(), 2004 );
1187
QCOMPARE( calendar->daysInYear( newDate ), 366 );
1189
newDate = calendar->addMonths( testDate, -4 );
1190
QCOMPARE( newDate.year(), 1999 );
1191
QCOMPARE( newDate.month(), 11 );
1192
QCOMPARE( newDate.day(), 1 );
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);
1197
QCOMPARE(calendar->dayOfYear(testDate), 253);
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);
1205
QDate newDate = calendar->addYears(testDate, 4);
1206
QCOMPARE(newDate.year(), 2004);
1207
QCOMPARE(calendar->daysInYear(newDate), 366);
1209
newDate = calendar->addMonths(testDate, -4);
1210
QCOMPARE(newDate.year(), 1999);
1211
QCOMPARE(newDate.month(), 11);
1212
QCOMPARE(newDate.day(), 1);
1214
newDate = calendar->addDays(newDate, 20);
1215
QCOMPARE(newDate.year(), 1999);
1216
QCOMPARE(newDate.month(), 11);
1217
QCOMPARE(newDate.day(), 21);
1199
1219
delete calendar;
1202
1222
void KCalendarTest::testHebrew()
1204
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::HebrewCalendar );
1205
QDate testDate( 2005, 9, 10 ); // 5756-13-06
1206
QCOMPARE( calendar->dayOfYear( testDate ), 360 );
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 );
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 );
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 );
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);
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);
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);
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);
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);
1232
1252
delete calendar;
1235
void KCalendarTest::testHijri()
1255
void KCalendarTest::testIslamicCivil()
1237
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IslamicCivilCalendar );
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 );
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 );
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 );
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 );
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 );
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);
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);
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);
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);
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);
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);
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);
1290
1310
QDate newDate = calendar->addYears(testDate, 4);
1291
QCOMPARE( newDate.year(), 2566 );
1292
QCOMPARE( calendar->daysInYear(newDate), 355 );
1294
newDate = calendar->addMonths( testDate, -4 );
1295
QCOMPARE( newDate.year(), 2561 );
1296
QCOMPARE( newDate.month(), 11 );
1297
QCOMPARE( newDate.day(), 10 );
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);
1314
newDate = calendar->addMonths(testDate, -4);
1315
QCOMPARE(newDate.year(), 2561);
1316
QCOMPARE(newDate.month(), 11);
1317
QCOMPARE(newDate.day(), 10);
1319
newDate = calendar->addDays(newDate, 20);
1320
QCOMPARE(newDate.year(), 2561);
1321
QCOMPARE(newDate.month(), 11);
1322
QCOMPARE(newDate.day(), 30);
1304
1324
delete calendar;
1308
1328
void KCalendarTest::testIndianNational()
1310
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::IndianNationalCalendar );
1311
QDate testDate( 2005, 9, 10 );
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 );
1322
QCOMPARE( calendar->isLeapYear( 2009 ), false );
1323
QCOMPARE( calendar->isLeapYear( testDate ), false );
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);
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);
1342
QCOMPARE(calendar->isLeapYear(2009), false);
1343
QCOMPARE(calendar->isLeapYear(testDate), false);
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);
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() );
1338
testRoundTrip( calendar );
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());
1358
testRoundTrip(calendar);
1363
void KCalendarTest::testQDateCalendarBasic()
1365
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
1367
testCalendarSystemType(calendar, KLocale::QDateCalendar, "gregorian", "Gregorian");
1369
QCOMPARE(calendar->epoch(), QDate(1, 1, 1));
1370
QCOMPARE(calendar->earliestValidDate(), QDate(-4712, 1, 1));
1371
QCOMPARE(calendar->latestValidDate(), QDate(9999, 12, 31));
1373
testValid(calendar, 0, 10000, 13, 32, QDate(-5000, 1, 1));
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);
1382
QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
1384
QCOMPARE(calendar->monthsInYear(2007), 12);
1385
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
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"));
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");
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");
1397
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
1399
QCOMPARE(calendar->weekStartDay(), 1);
1400
QCOMPARE(calendar->weekDayOfPray(), 7);
1402
QCOMPARE(calendar->isProleptic(), false);
1403
QCOMPARE(calendar->isLunar(), false);
1404
QCOMPARE(calendar->isLunisolar(), false);
1405
QCOMPARE(calendar->isSolar(), true);
1407
testRoundTrip(calendar);
1412
void KCalendarTest::testQDateCalendarYmd()
1414
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
1415
testYmd(calendar, 2007, 1, 1, QDate(2007, 1, 1).toJulianDay());
1419
void KCalendarTest::testQDateCalendarSpecialCases()
1421
KConfigGroup lcg(KGlobal::config(), QString("Locale"));
1422
KConfigGroup cg = lcg.group(QString("KCalendarSystem %1").arg("gregorian"));
1425
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
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");
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");
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");
1343
1448
void KCalendarTest::testGregorianBasic()
1345
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1347
testCalendarSystemType( calendar, KLocale::QDateCalendar, "gregorian", "Gregorian" );
1349
QCOMPARE( calendar->epoch(), QDate( 1, 1, 1 ) );
1350
QCOMPARE( calendar->earliestValidDate(), QDate( -4712, 1, 1 ) );
1351
QCOMPARE( calendar->latestValidDate(), QDate( 9999, 12, 31 ) );
1353
testValid( calendar, 0, 10000, 13, 32, QDate( -5000, 1, 1 ) );
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 );
1362
QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1364
QCOMPARE( calendar->monthsInYear( 2007 ), 12 );
1365
QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
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") );
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" );
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" );
1377
QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1379
QCOMPARE( calendar->weekStartDay(), 1 );
1380
QCOMPARE( calendar->weekDayOfPray(), 7 );
1382
QCOMPARE( calendar->isProleptic(), false );
1383
QCOMPARE( calendar->isLunar(), false );
1384
QCOMPARE( calendar->isLunisolar(), false );
1385
QCOMPARE( calendar->isSolar(), true );
1387
testRoundTrip( calendar );
1392
void KCalendarTest::testGregorianYmd()
1394
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
1395
testYmd( calendar, 2007, 1, 1, QDate( 2007, 1, 1 ).toJulianDay() );
1399
void KCalendarTest::testGregorianSpecialCases()
1401
KConfigGroup lcg( KGlobal::config(), QString( "Locale" ) );
1402
KConfigGroup cg = lcg.group( QString( "KCalendarSystem %1" ).arg( "gregorian" ) );
1405
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::QDateCalendar );
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" );
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" );
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" );
1428
void KCalendarTest::testGregorianProlepticBasic()
1430
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::GregorianCalendar );
1432
testCalendarSystemType( calendar, KLocale::GregorianCalendar, "gregorian-proleptic", "Gregorian (Proleptic)" );
1434
QCOMPARE( calendar->epoch(), QDate::fromJulianDay( 1721426 ) );
1435
QCOMPARE( calendar->earliestValidDate(), QDate::fromJulianDay( 38 ) );
1436
QCOMPARE( calendar->latestValidDate(), QDate( 9999, 12, 31 ) );
1438
testValid( calendar, 0, 10000, 13, 32, QDate() );
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 );
1447
QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1449
QCOMPARE( calendar->monthsInYear( 2007 ), 12 );
1450
QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
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") );
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" );
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" );
1462
QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1464
QCOMPARE( calendar->weekStartDay(), 1 );
1465
QCOMPARE( calendar->weekDayOfPray(), 7 );
1467
QCOMPARE( calendar->isProleptic(), true );
1468
QCOMPARE( calendar->isLunar(), false );
1469
QCOMPARE( calendar->isLunisolar(), false );
1470
QCOMPARE( calendar->isSolar(), true );
1472
testRoundTrip( calendar );
1450
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::GregorianCalendar);
1452
testCalendarSystemType(calendar, KLocale::GregorianCalendar, "gregorian-proleptic", "Gregorian (Proleptic)");
1454
QCOMPARE(calendar->epoch(), QDate::fromJulianDay(1721426));
1455
QCOMPARE(calendar->earliestValidDate(), QDate::fromJulianDay(38));
1456
QCOMPARE(calendar->latestValidDate(), QDate(9999, 12, 31));
1458
testValid(calendar, 0, 10000, 13, 32, QDate());
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);
1467
QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
1469
QCOMPARE(calendar->monthsInYear(2007), 12);
1470
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
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"));
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");
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");
1482
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
1484
QCOMPARE(calendar->weekStartDay(), 1);
1485
QCOMPARE(calendar->weekDayOfPray(), 7);
1487
QCOMPARE(calendar->isProleptic(), true);
1488
QCOMPARE(calendar->isLunar(), false);
1489
QCOMPARE(calendar->isLunisolar(), false);
1490
QCOMPARE(calendar->isSolar(), true);
1492
testRoundTrip(calendar);
1474
1494
delete calendar;
1621
1641
void KCalendarTest::testJalaliBasic()
1623
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JalaliCalendar );
1643
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JalaliCalendar);
1624
1644
QDate testDate;
1626
testCalendarSystemType( calendar, KLocale::JalaliCalendar, "jalali", "Jalali" );
1646
testCalendarSystemType(calendar, KLocale::JalaliCalendar, "jalali", "Jalali");
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 );
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 );
1640
testDate = QDate( 2005, 8, 31 ); // 1384-06-09 Wednesday
1642
QCOMPARE( calendar->daysInWeek( testDate ), 7 );
1643
QCOMPARE( calendar->monthsInYear( 1384 ), 12 );
1644
QCOMPARE( calendar->monthsInYear( testDate ), 12 );
1646
testYear( calendar, testDate, 1384, "84", "1384" );
1647
testMonth( calendar, testDate, 6, "6", "06" );
1648
testDay( calendar, testDate, 9, "9", "09" );
1650
testEraDate( calendar, testDate, 1384, "1384", "1384", "AP", "Anno Persico" );
1652
testWeekDayName( calendar, 3, testDate, "4sh", "Chahar shanbe" );
1653
testMonthName( calendar, 6, 1384, testDate, "Sha", "Shahrivar", "of Sha", "of Shahrivar" );
1655
QCOMPARE( calendar->monthsInYear( testDate ), 12 );
1657
QCOMPARE( calendar->weekStartDay(), 1 );
1658
QCOMPARE( calendar->weekDayOfPray(), 5 );
1660
QCOMPARE( calendar->isProleptic(), false );
1661
QCOMPARE( calendar->isLunar(), false );
1662
QCOMPARE( calendar->isLunisolar(), false );
1663
QCOMPARE( calendar->isSolar(), true );
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);
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);
1660
testDate = QDate(2005, 8, 31); // 1384-06-09 Wednesday
1662
QCOMPARE(calendar->daysInWeek(testDate), 7);
1663
QCOMPARE(calendar->monthsInYear(1384), 12);
1664
QCOMPARE(calendar->monthsInYear(testDate), 12);
1666
testYear(calendar, testDate, 1384, "84", "1384");
1667
testMonth(calendar, testDate, 6, "6", "06");
1668
testDay(calendar, testDate, 9, "9", "09");
1670
testEraDate(calendar, testDate, 1384, "1384", "1384", "AP", "Anno Persico");
1672
testWeekDayName(calendar, 3, testDate, "4", "4sh", "Chahar shanbe");
1673
testMonthName(calendar, 6, 1384, testDate, "S", "Sha", "Shahrivar", "of Sha", "of Shahrivar");
1675
QCOMPARE(calendar->monthsInYear(testDate), 12);
1677
QCOMPARE(calendar->weekStartDay(), 1);
1678
QCOMPARE(calendar->weekDayOfPray(), 5);
1680
QCOMPARE(calendar->isProleptic(), false);
1681
QCOMPARE(calendar->isLunar(), false);
1682
QCOMPARE(calendar->isLunisolar(), false);
1683
QCOMPARE(calendar->isSolar(), true);
1685
testRoundTrip(calendar);
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);
1673
1693
delete calendar;
1676
1696
void KCalendarTest::testJalaliYmd()
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;
1683
1703
void KCalendarTest::testJapanese()
1685
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1686
QDate testDate( 2005, 9, 10 );
1688
QCOMPARE( calendar->dayOfYear( testDate ), 253 );
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 );
1696
QDate newDate = calendar->addYears( testDate, 4);
1697
QCOMPARE( newDate.year(), 2004 );
1698
QCOMPARE( calendar->daysInYear( newDate ), 366 );
1700
newDate = calendar->addMonths( testDate, -4 );
1701
QCOMPARE( newDate.year(), 1999 );
1702
QCOMPARE( newDate.month(), 11 );
1703
QCOMPARE( newDate.day(), 1 );
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);
1708
QCOMPARE(calendar->dayOfYear(testDate), 253);
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);
1716
QDate newDate = calendar->addYears(testDate, 4);
1717
QCOMPARE(newDate.year(), 2004);
1718
QCOMPARE(calendar->daysInYear(newDate), 366);
1720
newDate = calendar->addMonths(testDate, -4);
1721
QCOMPARE(newDate.year(), 1999);
1722
QCOMPARE(newDate.month(), 11);
1723
QCOMPARE(newDate.day(), 1);
1725
newDate = calendar->addDays(newDate, 20);
1726
QCOMPARE(newDate.year(), 1999);
1727
QCOMPARE(newDate.month(), 11);
1728
QCOMPARE(newDate.day(), 21);
1710
1730
delete calendar;
1713
1733
void KCalendarTest::testJapaneseBasic()
1715
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1735
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JapaneseCalendar);
1716
1736
QDate testDate;
1718
testCalendarSystemType( calendar, KLocale::JapaneseCalendar, "japanese", "Japanese" );
1720
QCOMPARE( calendar->epoch(), QDate::fromJulianDay( 1721426 ) );
1721
QCOMPARE( calendar->earliestValidDate(), QDate::fromJulianDay( 1721426 ) );
1722
QCOMPARE( calendar->latestValidDate(), QDate( 9999, 12, 31 ) );
1724
testValid( calendar, 0, 10000, 13, 32, QDate( -5000, 1, 1 ) );
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 );
1733
QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1734
QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
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" );
1741
testEraDate( calendar, testDate, 19, "19", "0019", "Heisei", "Heisei" );
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" );
1746
QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1748
QCOMPARE( calendar->weekStartDay(), 1 );
1749
QCOMPARE( calendar->weekDayOfPray(), 7 );
1751
QCOMPARE( calendar->isProleptic(), false );
1752
QCOMPARE( calendar->isLunar(), false );
1753
QCOMPARE( calendar->isLunisolar(), false );
1754
QCOMPARE( calendar->isSolar(), true );
1756
testRoundTrip( calendar );
1738
testCalendarSystemType(calendar, KLocale::JapaneseCalendar, "japanese", "Japanese");
1740
QCOMPARE(calendar->epoch(), QDate::fromJulianDay(1721426));
1741
QCOMPARE(calendar->earliestValidDate(), QDate::fromJulianDay(1721426));
1742
QCOMPARE(calendar->latestValidDate(), QDate(9999, 12, 31));
1744
testValid(calendar, 0, 10000, 13, 32, QDate(-5000, 1, 1));
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);
1753
QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
1754
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
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");
1761
testEraDate(calendar, testDate, 19, "19", "0019", "Heisei", "Heisei");
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");
1766
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
1768
QCOMPARE(calendar->weekStartDay(), 1);
1769
QCOMPARE(calendar->weekDayOfPray(), 7);
1771
QCOMPARE(calendar->isProleptic(), false);
1772
QCOMPARE(calendar->isLunar(), false);
1773
QCOMPARE(calendar->isLunisolar(), false);
1774
QCOMPARE(calendar->isSolar(), true);
1776
testRoundTrip(calendar);
1758
1778
delete calendar;
1761
1781
void KCalendarTest::testJapaneseYmd()
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;
1768
1788
void KCalendarTest::testJapaneseSpecialCases()
1770
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::JapaneseCalendar );
1790
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::JapaneseCalendar);
1772
1792
// Test Japanese Eras
1773
1793
// Heisei > 1 1990-01-01 onwards
1860
1880
void KCalendarTest::testThaiBasic()
1862
const KCalendarSystem *calendar = KCalendarSystem::create( KLocale::ThaiCalendar );
1864
testCalendarSystemType( calendar, KLocale::ThaiCalendar, "thai", "Thai" );
1866
QCOMPARE( calendar->epoch(), QDate( -544, 1, 7 ) );
1867
QCOMPARE( calendar->earliestValidDate(), QDate( -544, 1, 7 ) );
1868
QCOMPARE( calendar->latestValidDate(), QDate( 9456, 12, 31 ) );
1870
testValid( calendar, -1, 10000, 13, 32, QDate() );
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 );
1879
QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
1881
QCOMPARE( calendar->monthsInYear( 2007 + 543 ), 12 );
1882
QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
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") );
1888
testEraDate( calendar, QDate( 2007, 1, 1 ), 2007 + 543, "2550", "2550", "BE", "Buddhist Era" );
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" );
1893
QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
1895
QCOMPARE( calendar->weekStartDay(), 1 );
1896
QCOMPARE( calendar->weekDayOfPray(), 7 );
1898
QCOMPARE( calendar->isProleptic(), false );
1899
QCOMPARE( calendar->isLunar(), false );
1900
QCOMPARE( calendar->isLunisolar(), false );
1901
QCOMPARE( calendar->isSolar(), true );
1903
testRoundTrip( calendar );
1882
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::ThaiCalendar);
1884
testCalendarSystemType(calendar, KLocale::ThaiCalendar, "thai", "Thai");
1886
QCOMPARE(calendar->epoch(), QDate(-544, 1, 7));
1887
QCOMPARE(calendar->earliestValidDate(), QDate(-544, 1, 7));
1888
QCOMPARE(calendar->latestValidDate(), QDate(9456, 12, 31));
1890
testValid(calendar, -1, 10000, 13, 32, QDate());
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);
1899
QCOMPARE(calendar->daysInWeek(QDate(2007, 1, 1)), 7);
1901
QCOMPARE(calendar->monthsInYear(2007 + 543), 12);
1902
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
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"));
1908
testEraDate(calendar, QDate(2007, 1, 1), 2007 + 543, "2550", "2550", "BE", "Buddhist Era");
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");
1913
QCOMPARE(calendar->monthsInYear(QDate(2007, 1, 1)), 12);
1915
QCOMPARE(calendar->weekStartDay(), 1);
1916
QCOMPARE(calendar->weekDayOfPray(), 7);
1918
QCOMPARE(calendar->isProleptic(), false);
1919
QCOMPARE(calendar->isLunar(), false);
1920
QCOMPARE(calendar->isLunisolar(), false);
1921
QCOMPARE(calendar->isSolar(), true);
1923
testRoundTrip(calendar);
1905
1925
delete calendar;
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)
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);
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)
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);
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);
1934
QCOMPARE( calendar->isValid( 1, 1, 0 ), false );
1935
QCOMPARE( calendar->isValid( 1, 1, highInvalidDay ), false );
1937
QCOMPARE( calendar->isValid( 1, 1, 1 ), true );
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);
1959
QCOMPARE(calendar->isValid(1, 1, 1), true);
1961
QCOMPARE(calendar->isValid(invalidDate), false);
1962
QCOMPARE(calendar->isValid(QDate(2000, 1, 1)), true);
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)
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);
1951
void KCalendarTest::testEarliestValidDate( const KCalendarSystem *calendar, int y, int m, int d, int jd )
1953
QCOMPARE( calendar->earliestValidDate(), QDate::fromJulianDay( jd ) );
1954
testYmd( calendar, y, m, d, jd );
1957
void KCalendarTest::testLatestValidDate( const KCalendarSystem *calendar, int y, int m, int d, int jd )
1959
QCOMPARE( calendar->latestValidDate(), QDate::fromJulianDay( jd ) );
1960
testYmd( calendar, y, m, d, jd );
1963
void KCalendarTest::testYmd( const KCalendarSystem *calendar, int y, int m, int d, int jd )
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)
1975
QCOMPARE(calendar->earliestValidDate(), QDate::fromJulianDay(jd));
1976
testYmd(calendar, y, m, d, jd);
1979
void KCalendarTest::testLatestValidDate(const KCalendarSystem *calendar, int y, int m, int d, int jd)
1981
QCOMPARE(calendar->latestValidDate(), QDate::fromJulianDay(jd));
1982
testYmd(calendar, y, m, d, jd);
1985
void KCalendarTest::testYmd(const KCalendarSystem *calendar, int y, int m, int d, int jd)
1987
QDate testDate1 = QDate::fromJulianDay(jd);
1988
QCOMPARE(calendar->year(testDate1), y);
1989
QCOMPARE(calendar->month(testDate1), m);
1990
QCOMPARE(calendar->day(testDate1), d);
1970
1992
QDate testDate2;
1971
QVERIFY( calendar->setYMD( testDate2, y, m, d ) );
1972
QCOMPARE( testDate1, testDate2 );
1975
void KCalendarTest::testYear( const KCalendarSystem *calendar, const QDate &date,
1976
int year, const QString &shortString, const QString &longString )
1978
QCOMPARE( calendar->year( date ), year );
1979
QCOMPARE( calendar->yearString( date, KCalendarSystem::ShortFormat ), shortString );
1980
QCOMPARE( calendar->yearString( date, KCalendarSystem::LongFormat ), longString );
1982
QCOMPARE( calendar->yearStringToInteger( longString, i ), year );
1983
QCOMPARE( i, longString.length() );
1986
void KCalendarTest::testMonth( const KCalendarSystem *calendar, const QDate &date,
1987
int month, const QString &shortString, const QString &longString )
1989
QCOMPARE( calendar->month( date ), month );
1990
QCOMPARE( calendar->monthString( date, KCalendarSystem::ShortFormat ), shortString );
1991
QCOMPARE( calendar->monthString( date, KCalendarSystem::LongFormat ), longString );
1993
QCOMPARE( calendar->monthStringToInteger( longString, i ), month );
1994
QCOMPARE( i, longString.length() );
1997
void KCalendarTest::testDay( const KCalendarSystem *calendar, const QDate &date,
1998
int day, const QString &shortString, const QString &longString )
2000
QCOMPARE( calendar->day( date ), day );
2001
QCOMPARE( calendar->dayString( date, KCalendarSystem::ShortFormat ), shortString );
2002
QCOMPARE( calendar->dayString( date, KCalendarSystem::LongFormat ), longString );
2004
QCOMPARE( calendar->dayStringToInteger( longString, i ), day );
2005
QCOMPARE( i, longString.length() );
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 )
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);
1997
void KCalendarTest::testYear(const KCalendarSystem *calendar, const QDate &date,
1998
int year, const QString &shortString, const QString &longString)
2000
QCOMPARE(calendar->year(date), year);
2001
QCOMPARE(calendar->yearString(date, KCalendarSystem::ShortFormat), shortString);
2002
QCOMPARE(calendar->yearString(date, KCalendarSystem::LongFormat), longString);
2004
QCOMPARE(calendar->yearStringToInteger(longString, i), year);
2005
QCOMPARE(i, longString.length());
2008
void KCalendarTest::testMonth(const KCalendarSystem *calendar, const QDate &date,
2009
int month, const QString &shortString, const QString &longString)
2011
QCOMPARE(calendar->month(date), month);
2012
QCOMPARE(calendar->monthString(date, KCalendarSystem::ShortFormat), shortString);
2013
QCOMPARE(calendar->monthString(date, KCalendarSystem::LongFormat), longString);
2015
QCOMPARE(calendar->monthStringToInteger(longString, i), month);
2016
QCOMPARE(i, longString.length());
2019
void KCalendarTest::testDay(const KCalendarSystem *calendar, const QDate &date,
2020
int day, const QString &shortString, const QString &longString)
2022
QCOMPARE(calendar->day(date), day);
2023
QCOMPARE(calendar->dayString(date, KCalendarSystem::ShortFormat), shortString);
2024
QCOMPARE(calendar->dayString(date, KCalendarSystem::LongFormat), longString);
2026
QCOMPARE(calendar->dayStringToInteger(longString, i), day);
2027
QCOMPARE(i, longString.length());
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)
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);
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") )
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)
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);
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());
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());
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);
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);
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)
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);
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());
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());
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);
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);
2083
void KCalendarTest::testRoundTrip( const KCalendarSystem *calendar, bool testFullRange )
2115
void KCalendarTest::testRoundTrip(const KCalendarSystem *calendar, bool testFullRange)
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.";
2136
2168
void KCalendarTest::testQDateYearMonthDay()
2138
const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
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 );
2146
testQDateYMD( calendar, 9999, 1, 1 );
2147
testQDateYMD( calendar, 9999, 6, 15 );
2148
testQDateYMD( calendar, 9999, 12, 31 );
2150
testQDateYMD( calendar, 1, 1, 1 );
2151
testQDateYMD( calendar, 1, 6, 15 );
2152
testQDateYMD( calendar, 1, 12, 31 );
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);
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);
2178
testQDateYMD(calendar, 9999, 1, 1);
2179
testQDateYMD(calendar, 9999, 6, 15);
2180
testQDateYMD(calendar, 9999, 12, 31);
2182
testQDateYMD(calendar, 1, 1, 1);
2183
testQDateYMD(calendar, 1, 6, 15);
2184
testQDateYMD(calendar, 1, 12, 31);
2186
testQDateYMD(calendar, -4712, 1, 2);
2187
testQDateYMD(calendar, -4712, 6, 15);
2188
testQDateYMD(calendar, -4712, 12, 31);
2158
2190
delete calendar;
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)
2163
2195
QDate testDate;
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());
2171
2203
void KCalendarTest::testQDateAddYears()
2173
const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
2205
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2175
2207
QDate testDate;
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 ) );
2181
calendar->setDate( testDate, 2000, 2, 29 );
2182
QCOMPARE( calendar->addYears( testDate, 1 ), testDate.addYears( 1 ) );
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));
2213
calendar->setDate(testDate, 2000, 2, 29);
2214
QCOMPARE(calendar->addYears(testDate, 1), testDate.addYears(1));
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));
2188
2220
delete calendar;
2191
2223
void KCalendarTest::testQDateAddMonths()
2193
const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
2225
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2195
2227
QDate testDate;
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 ) );
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 ) );
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 ) );
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 ) );
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 ) );
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 ) );
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 ) );
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));
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));
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));
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));
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));
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));
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));
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));
2229
2261
delete calendar;
2232
2264
void KCalendarTest::testQDateAddDays()
2234
const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
2266
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2236
2268
QDate testDate;
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));
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));
2246
2278
delete calendar;
2249
2281
void KCalendarTest::testQDateDaysInYear()
2251
const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
2283
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2253
2285
QDate testDate;
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() );
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
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
2281
QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
2283
calendar->setDate( testDate, 1, 1, 1 );
2284
QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
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());
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
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
2313
QCOMPARE(calendar->daysInYear(testDate), testDate.daysInYear());
2315
calendar->setDate(testDate, 1, 1, 1);
2316
QCOMPARE(calendar->daysInYear(testDate), testDate.daysInYear());
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());
2291
2323
delete calendar;
2295
2327
void KCalendarTest::testQDateDaysInMonth()
2297
const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
2329
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2299
2331
QDate testDate;
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());
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());
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());
2337
2369
delete calendar;
2340
2372
void KCalendarTest::testQDateDayOfYear()
2342
const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
2374
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2344
2376
QDate testDate;
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() );
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() );
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() );
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());
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());
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());
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());
2391
2423
delete calendar;
2394
2426
void KCalendarTest::testQDateDayOfWeek()
2396
const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
2428
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2398
2430
QDate testDate;
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() );
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() );
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());
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());
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());
2445
2477
delete calendar;
2448
2480
// Don't really need this as Gregorian currently uses QDate directly
2449
2481
void KCalendarTest::testQDateIsLeapYear()
2451
const KCalendarSystem *calendar = KCalendarSystem::create( "gregorian" );
2483
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar);
2453
2485
QDate testDate;
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 ) );
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 ) );
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));
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));
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));
2485
2517
delete calendar;
2488
2520
void KCalendarTest::testKLocalizedDate()
2490
KGlobal::locale()->setDateFormatShort( "%y-%m-%d" );
2522
KGlobal::locale()->setDateFormatShort("%y-%m-%d");
2491
2523
const KCalendarSystem *calendar = KGlobal::locale()->calendar();
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);
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);
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));
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));
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));
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);
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 );
2591
testKLocalizedDate.getDate(&ky, &km, &kd);
2592
calendar->getDate(testQDate, &qy, &qm, &qd);
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));
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));
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"));
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);
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);
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);
2655
QCOMPARE(kdir, qdir);
2656
lowKLocalizedDate.dateDifference(highQDate, &kdy, &kdm, &kdd, &kdir);
2657
calendar->dateDifference(lowKLocalizedDate.date(), highQDate, &qdy, &qdm, &qdd, &qdir);
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));
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);
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));
2672
2704
// Test copy of calendar object
2681
2713
newOne = KLocalizedDate::currentDate();
2682
2714
kDebug() << newOne;
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));
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;
2727
void KCalendarTest::testWeekNumberSystem()
2729
KLocale *locale = new KLocale(*KGlobal::locale());
2730
const KCalendarSystem *calendar = KCalendarSystem::create(KLocale::QDateCalendar, locale);
2733
// Test the 7 days the year can start on:
2736
// Wednesday == 2014
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
2751
locale->setWeekStartDay(1);
2752
locale->setWeekNumberSystem(KLocale::IsoWeekNumber);
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);
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);
2774
QCOMPARE(calendar->weeksInYear(2010), 52);
2775
QCOMPARE(calendar->weeksInYear(2015), 53);
2777
// First Full Week starting Sunday, aka US Week
2778
locale->setWeekStartDay(7);
2779
locale->setWeekNumberSystem(KLocale::FirstFullWeek);
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);
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);
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);
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);
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);
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);
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);
2873
// First Full Week starting Monday
2874
locale->setWeekStartDay(1);
2875
locale->setWeekNumberSystem(KLocale::FirstFullWeek);
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);
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);
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);
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);
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);
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);
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);
2970
// First Partial Week, second week starting Sunday
2971
locale->setWeekStartDay(7);
2972
locale->setWeekNumberSystem(KLocale::FirstPartialWeek);
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);
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);
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);
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);
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);
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);
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);
3066
// First Partial Week starting Monday
3067
locale->setWeekStartDay(1);
3068
locale->setWeekNumberSystem(KLocale::FirstPartialWeek);
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);
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);
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);
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);
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);
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);
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);
3162
// Simple weeks starting Jan 1
3163
locale->setWeekStartDay(1);
3164
locale->setWeekNumberSystem(KLocale::SimpleWeek);
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);
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);
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);
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);
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);
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);
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);