moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / libkdeedu / extdate / extcalendarsystemgregorian.cpp
blobc62422133d526db4ceca9b75b6ff5433be3ee856
1 /*
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
27 // Just a schema.
30 #include <klocale.h>
31 #include <kdebug.h>
33 #include "extcalendarsystemgregorian.h"
35 ExtCalendarSystemGregorian::ExtCalendarSystemGregorian(const KLocale * locale)
36 : ExtCalendarSystem(locale)
40 ExtCalendarSystemGregorian::~ExtCalendarSystemGregorian()
44 int ExtCalendarSystemGregorian::year(const ExtDate& date) const
46 return date.year();
49 int ExtCalendarSystemGregorian::monthsInYear( const ExtDate & date ) const
51 Q_UNUSED( date )
53 return 12;
56 int ExtCalendarSystemGregorian::weeksInYear(int year) const
58 ExtDate temp;
59 temp.setYMD(year, 12, 31);
61 // If the last day of the year is in the first week, we have to check the
62 // week before
63 if ( temp.weekNumber() == 1 )
64 temp = temp.addDays(-7);
66 return temp.weekNumber();
69 int ExtCalendarSystemGregorian::weekNumber(const ExtDate& date,
70 int * yearNum) const
72 return date.weekNumber(yearNum);
75 QString ExtCalendarSystemGregorian::monthName(const ExtDate& date,
76 bool shortName) const
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
88 Q_UNUSED(year);
90 if ( shortName )
91 switch ( month )
93 case 1:
94 return locale()->translate("January", "Jan");
95 case 2:
96 return locale()->translate("February", "Feb");
97 case 3:
98 return locale()->translate("March", "Mar");
99 case 4:
100 return locale()->translate("April", "Apr");
101 case 5:
102 return locale()->translate("May short", "May");
103 case 6:
104 return locale()->translate("June", "Jun");
105 case 7:
106 return locale()->translate("July", "Jul");
107 case 8:
108 return locale()->translate("August", "Aug");
109 case 9:
110 return locale()->translate("September", "Sep");
111 case 10:
112 return locale()->translate("October", "Oct");
113 case 11:
114 return locale()->translate("November", "Nov");
115 case 12:
116 return locale()->translate("December", "Dec");
118 else
119 switch ( month )
121 case 1:
122 return locale()->translate("January");
123 case 2:
124 return locale()->translate("February");
125 case 3:
126 return locale()->translate("March");
127 case 4:
128 return locale()->translate("April");
129 case 5:
130 return locale()->translate("May long", "May");
131 case 6:
132 return locale()->translate("June");
133 case 7:
134 return locale()->translate("July");
135 case 8:
136 return locale()->translate("August");
137 case 9:
138 return locale()->translate("September");
139 case 10:
140 return locale()->translate("October");
141 case 11:
142 return locale()->translate("November");
143 case 12:
144 return locale()->translate("December");
147 return QString::null;
150 QString ExtCalendarSystemGregorian::monthNamePossessive(int month, int year,
151 bool shortName) const
153 Q_UNUSED(year);
155 if ( shortName )
156 switch ( month )
158 case 1:
159 return locale()->translate("of January", "of Jan");
160 case 2:
161 return locale()->translate("of February", "of Feb");
162 case 3:
163 return locale()->translate("of March", "of Mar");
164 case 4:
165 return locale()->translate("of April", "of Apr");
166 case 5:
167 return locale()->translate("of May short", "of May");
168 case 6:
169 return locale()->translate("of June", "of Jun");
170 case 7:
171 return locale()->translate("of July", "of Jul");
172 case 8:
173 return locale()->translate("of August", "of Aug");
174 case 9:
175 return locale()->translate("of September", "of Sep");
176 case 10:
177 return locale()->translate("of October", "of Oct");
178 case 11:
179 return locale()->translate("of November", "of Nov");
180 case 12:
181 return locale()->translate("of December", "of Dec");
183 else
184 switch ( month )
186 case 1:
187 return locale()->translate("of January");
188 case 2:
189 return locale()->translate("of February");
190 case 3:
191 return locale()->translate("of March");
192 case 4:
193 return locale()->translate("of April");
194 case 5:
195 return locale()->translate("of May long", "of May");
196 case 6:
197 return locale()->translate("of June");
198 case 7:
199 return locale()->translate("of July");
200 case 8:
201 return locale()->translate("of August");
202 case 9:
203 return locale()->translate("of September");
204 case 10:
205 return locale()->translate("of October");
206 case 11:
207 return locale()->translate("of November");
208 case 12:
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
267 return -50000;
270 int ExtCalendarSystemGregorian::maxValidYear() const
272 return 50000;
275 int ExtCalendarSystemGregorian::day(const ExtDate& date) const
277 return date.day();
280 int ExtCalendarSystemGregorian::month(const ExtDate& date) const
282 return date.month();
285 int ExtCalendarSystemGregorian::daysInYear(const ExtDate& date) const
287 return date.daysInYear();
290 int ExtCalendarSystemGregorian::weekDayOfPray() const
292 return 7; // sunday
295 QString ExtCalendarSystemGregorian::calendarName() const
297 return QString::fromLatin1("gregorian");
300 bool ExtCalendarSystemGregorian::isLunar() const
302 return false;
305 bool ExtCalendarSystemGregorian::isLunisolar() const
307 return false;
310 bool ExtCalendarSystemGregorian::isSolar() const
312 return true;
315 int ExtCalendarSystemGregorian::yearStringToInteger(const QString & sNum, int & iLength) const
317 int iYear;
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
322 if (iYear < 69)
323 iYear += 2000;
324 else if (iYear < 100)
325 iYear += 1900;
327 return iYear;