2 Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
3 Copyright (c) 2002-2003 Hans Petter Bieker <bieker@kde.org>
4 Copyright (c) 2004 Jason Harris <jharris@30doradus.org>
6 This class has been derived from KCalendarSystemGregorian;
7 the changesd made just replace QDate objects with ExtDate objects.
8 These changes by Jason Harris <jharris@30doradus.org>
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
20 You should have received a copy of the GNU Library General Public License
21 along with this library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.
26 // Derived gregorian kde calendar class
33 #include "extcalendarsystemgregorian.h"
35 ExtCalendarSystemGregorian::ExtCalendarSystemGregorian(const KLocale
* locale
)
36 : ExtCalendarSystem(locale
)
40 ExtCalendarSystemGregorian::~ExtCalendarSystemGregorian()
44 int ExtCalendarSystemGregorian::year(const ExtDate
& date
) const
49 int ExtCalendarSystemGregorian::monthsInYear( const ExtDate
& date
) const
56 int ExtCalendarSystemGregorian::weeksInYear(int year
) const
59 temp
.setYMD(year
, 12, 31);
61 // If the last day of the year is in the first week, we have to check the
63 if ( temp
.weekNumber() == 1 )
64 temp
= temp
.addDays(-7);
66 return temp
.weekNumber();
69 int ExtCalendarSystemGregorian::weekNumber(const ExtDate
& date
,
72 return date
.weekNumber(yearNum
);
75 QString
ExtCalendarSystemGregorian::monthName(const ExtDate
& date
,
78 return monthName(month(date
), year(date
), shortName
);
81 QString
ExtCalendarSystemGregorian::monthNamePossessive(const ExtDate
& date
, bool shortName
) const
83 return monthNamePossessive(month(date
), year(date
), shortName
);
86 QString
ExtCalendarSystemGregorian::monthName(int month
, int year
, bool shortName
) const
94 return locale()->translate("January", "Jan");
96 return locale()->translate("February", "Feb");
98 return locale()->translate("March", "Mar");
100 return locale()->translate("April", "Apr");
102 return locale()->translate("May short", "May");
104 return locale()->translate("June", "Jun");
106 return locale()->translate("July", "Jul");
108 return locale()->translate("August", "Aug");
110 return locale()->translate("September", "Sep");
112 return locale()->translate("October", "Oct");
114 return locale()->translate("November", "Nov");
116 return locale()->translate("December", "Dec");
122 return locale()->translate("January");
124 return locale()->translate("February");
126 return locale()->translate("March");
128 return locale()->translate("April");
130 return locale()->translate("May long", "May");
132 return locale()->translate("June");
134 return locale()->translate("July");
136 return locale()->translate("August");
138 return locale()->translate("September");
140 return locale()->translate("October");
142 return locale()->translate("November");
144 return locale()->translate("December");
147 return QString::null
;
150 QString
ExtCalendarSystemGregorian::monthNamePossessive(int month
, int year
,
151 bool shortName
) const
159 return locale()->translate("of January", "of Jan");
161 return locale()->translate("of February", "of Feb");
163 return locale()->translate("of March", "of Mar");
165 return locale()->translate("of April", "of Apr");
167 return locale()->translate("of May short", "of May");
169 return locale()->translate("of June", "of Jun");
171 return locale()->translate("of July", "of Jul");
173 return locale()->translate("of August", "of Aug");
175 return locale()->translate("of September", "of Sep");
177 return locale()->translate("of October", "of Oct");
179 return locale()->translate("of November", "of Nov");
181 return locale()->translate("of December", "of Dec");
187 return locale()->translate("of January");
189 return locale()->translate("of February");
191 return locale()->translate("of March");
193 return locale()->translate("of April");
195 return locale()->translate("of May long", "of May");
197 return locale()->translate("of June");
199 return locale()->translate("of July");
201 return locale()->translate("of August");
203 return locale()->translate("of September");
205 return locale()->translate("of October");
207 return locale()->translate("of November");
209 return locale()->translate("of December");
212 return QString::null
;
215 bool ExtCalendarSystemGregorian::setYMD(ExtDate
& date
, int y
, int m
, int d
) const
217 // ExtDate supports gregorian internally
218 return date
.setYMD(y
, m
, d
);
221 ExtDate
ExtCalendarSystemGregorian::addYears(const ExtDate
& date
, int nyears
) const
223 return date
.addYears(nyears
);
226 ExtDate
ExtCalendarSystemGregorian::addMonths(const ExtDate
& date
, int nmonths
) const
228 return date
.addMonths(nmonths
);
231 ExtDate
ExtCalendarSystemGregorian::addDays(const ExtDate
& date
, int ndays
) const
233 return date
.addDays(ndays
);
236 QString
ExtCalendarSystemGregorian::weekDayName(int col
, bool shortName
) const
238 // ### Should this really be different to each calendar system? Or are we
239 // only going to support weeks with 7 days?
241 return ExtCalendarSystem::weekDayName(col
, shortName
);
244 QString
ExtCalendarSystemGregorian::weekDayName(const ExtDate
& date
, bool shortName
) const
246 return weekDayName(dayOfWeek(date
), shortName
);
250 int ExtCalendarSystemGregorian::dayOfWeek(const ExtDate
& date
) const
252 return date
.dayOfWeek();
255 int ExtCalendarSystemGregorian::dayOfYear(const ExtDate
& date
) const
257 return date
.dayOfYear();
260 int ExtCalendarSystemGregorian::daysInMonth(const ExtDate
& date
) const
262 return date
.daysInMonth();
265 int ExtCalendarSystemGregorian::minValidYear() const
270 int ExtCalendarSystemGregorian::maxValidYear() const
275 int ExtCalendarSystemGregorian::day(const ExtDate
& date
) const
280 int ExtCalendarSystemGregorian::month(const ExtDate
& date
) const
285 int ExtCalendarSystemGregorian::daysInYear(const ExtDate
& date
) const
287 return date
.daysInYear();
290 int ExtCalendarSystemGregorian::weekDayOfPray() const
295 QString
ExtCalendarSystemGregorian::calendarName() const
297 return QString::fromLatin1("gregorian");
300 bool ExtCalendarSystemGregorian::isLunar() const
305 bool ExtCalendarSystemGregorian::isLunisolar() const
310 bool ExtCalendarSystemGregorian::isSolar() const
315 int ExtCalendarSystemGregorian::yearStringToInteger(const QString
& sNum
, int & iLength
) const
318 iYear
= ExtCalendarSystem::yearStringToInteger(sNum
, iLength
);
320 // Qt treats a year in the range 0-100 as 1900-1999.
321 // It is nicer for the user if we treat 0-68 as 2000-2068
324 else if (iYear
< 100)