• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kcalendarsystemgregorian.cpp
1 /*
2  Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
3  Copyright (c) 2002-2003 Hans Petter Bieker <bieker@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 // Derived gregorian kde calendar class
22 // Just a schema.
23 
24 #include <tqdatetime.h>
25 #include <tqstring.h>
26 
27 #include <tdelocale.h>
28 #include <kdebug.h>
29 
30 #include "kcalendarsystemgregorian.h"
31 
32 KCalendarSystemGregorian::KCalendarSystemGregorian(const TDELocale * locale)
33  : KCalendarSystem(locale)
34 {
35 }
36 
37 KCalendarSystemGregorian::~KCalendarSystemGregorian()
38 {
39 }
40 
41 int KCalendarSystemGregorian::year(const TQDate& date) const
42 {
43  return date.year();
44 }
45 
46 int KCalendarSystemGregorian::monthsInYear( const TQDate & date ) const
47 {
48  Q_UNUSED( date )
49 
50  return 12;
51 }
52 
53 int KCalendarSystemGregorian::weeksInYear(int year) const
54 {
55  TQDate temp;
56  temp.setYMD(year, 12, 31);
57 
58  // If the last day of the year is in the first week, we have to check the
59  // week before
60  if ( temp.weekNumber() == 1 )
61  temp = temp.addDays(-7);
62 
63  return temp.weekNumber();
64 }
65 
66 int KCalendarSystemGregorian::weekNumber(const TQDate& date,
67  int * yearNum) const
68 {
69  return date.weekNumber(yearNum);
70 }
71 
72 TQString KCalendarSystemGregorian::monthName(const TQDate& date,
73  bool shortName) const
74 {
75  return monthName(month(date), year(date), shortName);
76 }
77 
78 TQString KCalendarSystemGregorian::monthNamePossessive(const TQDate& date, bool shortName) const
79 {
80  return monthNamePossessive(month(date), year(date), shortName);
81 }
82 
83 TQString KCalendarSystemGregorian::monthName(int month, int year, bool shortName) const
84 {
85  Q_UNUSED(year);
86 
87  if ( shortName )
88  switch ( month )
89  {
90  case 1:
91  return locale()->translate("January", "Jan");
92  case 2:
93  return locale()->translate("February", "Feb");
94  case 3:
95  return locale()->translate("March", "Mar");
96  case 4:
97  return locale()->translate("April", "Apr");
98  case 5:
99  return locale()->translate("May short", "May");
100  case 6:
101  return locale()->translate("June", "Jun");
102  case 7:
103  return locale()->translate("July", "Jul");
104  case 8:
105  return locale()->translate("August", "Aug");
106  case 9:
107  return locale()->translate("September", "Sep");
108  case 10:
109  return locale()->translate("October", "Oct");
110  case 11:
111  return locale()->translate("November", "Nov");
112  case 12:
113  return locale()->translate("December", "Dec");
114  }
115  else
116  switch ( month )
117  {
118  case 1:
119  return locale()->translate("January");
120  case 2:
121  return locale()->translate("February");
122  case 3:
123  return locale()->translate("March");
124  case 4:
125  return locale()->translate("April");
126  case 5:
127  return locale()->translate("May long", "May");
128  case 6:
129  return locale()->translate("June");
130  case 7:
131  return locale()->translate("July");
132  case 8:
133  return locale()->translate("August");
134  case 9:
135  return locale()->translate("September");
136  case 10:
137  return locale()->translate("October");
138  case 11:
139  return locale()->translate("November");
140  case 12:
141  return locale()->translate("December");
142  }
143 
144  return TQString::null;
145 }
146 
147 TQString KCalendarSystemGregorian::monthNamePossessive(int month, int year,
148  bool shortName) const
149 {
150  Q_UNUSED(year);
151 
152  if ( shortName )
153  switch ( month )
154  {
155  case 1:
156  return locale()->translate("of January", "of Jan");
157  case 2:
158  return locale()->translate("of February", "of Feb");
159  case 3:
160  return locale()->translate("of March", "of Mar");
161  case 4:
162  return locale()->translate("of April", "of Apr");
163  case 5:
164  return locale()->translate("of May short", "of May");
165  case 6:
166  return locale()->translate("of June", "of Jun");
167  case 7:
168  return locale()->translate("of July", "of Jul");
169  case 8:
170  return locale()->translate("of August", "of Aug");
171  case 9:
172  return locale()->translate("of September", "of Sep");
173  case 10:
174  return locale()->translate("of October", "of Oct");
175  case 11:
176  return locale()->translate("of November", "of Nov");
177  case 12:
178  return locale()->translate("of December", "of Dec");
179  }
180  else
181  switch ( month )
182  {
183  case 1:
184  return locale()->translate("of January");
185  case 2:
186  return locale()->translate("of February");
187  case 3:
188  return locale()->translate("of March");
189  case 4:
190  return locale()->translate("of April");
191  case 5:
192  return locale()->translate("of May long", "of May");
193  case 6:
194  return locale()->translate("of June");
195  case 7:
196  return locale()->translate("of July");
197  case 8:
198  return locale()->translate("of August");
199  case 9:
200  return locale()->translate("of September");
201  case 10:
202  return locale()->translate("of October");
203  case 11:
204  return locale()->translate("of November");
205  case 12:
206  return locale()->translate("of December");
207  }
208 
209  return TQString::null;
210 }
211 
212 bool KCalendarSystemGregorian::setYMD(TQDate & date, int y, int m, int d) const
213 {
214  // We don't want Qt to add 1900 to them
215  if ( y >= 0 && y <= 99 )
216  return false;
217 
218  // TQDate supports gregorian internally
219  return date.setYMD(y, m, d);
220 }
221 
222 TQDate KCalendarSystemGregorian::addYears(const TQDate & date, int nyears) const
223 {
224  return date.addYears(nyears);
225 }
226 
227 TQDate KCalendarSystemGregorian::addMonths(const TQDate & date, int nmonths) const
228 {
229  return date.addMonths(nmonths);
230 }
231 
232 TQDate KCalendarSystemGregorian::addDays(const TQDate & date, int ndays) const
233 {
234  return date.addDays(ndays);
235 }
236 
237 TQString KCalendarSystemGregorian::weekDayName(int col, bool shortName) const
238 {
239  // ### Should this really be different to each calendar system? Or are we
240  // only going to support weeks with 7 days?
241 
242  return KCalendarSystem::weekDayName(col, shortName);
243 }
244 
245 TQString KCalendarSystemGregorian::weekDayName(const TQDate& date, bool shortName) const
246 {
247  return weekDayName(dayOfWeek(date), shortName);
248 }
249 
250 
251 int KCalendarSystemGregorian::dayOfWeek(const TQDate& date) const
252 {
253  return date.dayOfWeek();
254 }
255 
256 int KCalendarSystemGregorian::dayOfYear(const TQDate & date) const
257 {
258  return date.dayOfYear();
259 }
260 
261 int KCalendarSystemGregorian::daysInMonth(const TQDate& date) const
262 {
263  return date.daysInMonth();
264 }
265 
266 int KCalendarSystemGregorian::minValidYear() const
267 {
268  return 1753; // TQDate limit
269 }
270 
271 int KCalendarSystemGregorian::maxValidYear() const
272 {
273  return 8000; // TQDate limit
274 }
275 
276 int KCalendarSystemGregorian::day(const TQDate& date) const
277 {
278  return date.day();
279 }
280 
281 int KCalendarSystemGregorian::month(const TQDate& date) const
282 {
283  return date.month();
284 }
285 
286 int KCalendarSystemGregorian::daysInYear(const TQDate& date) const
287 {
288  return date.daysInYear();
289 }
290 
291 int KCalendarSystemGregorian::weekDayOfPray() const
292 {
293  return 7; // sunday
294 }
295 
296 TQString KCalendarSystemGregorian::calendarName() const
297 {
298  return TQString::fromLatin1("gregorian");
299 }
300 
301 bool KCalendarSystemGregorian::isLunar() const
302 {
303  return false;
304 }
305 
306 bool KCalendarSystemGregorian::isLunisolar() const
307 {
308  return false;
309 }
310 
311 bool KCalendarSystemGregorian::isSolar() const
312 {
313  return true;
314 }
315 
316 int KCalendarSystemGregorian::yearStringToInteger(const TQString & sNum, int & iLength) const
317 {
318  int iYear;
319  iYear = KCalendarSystem::yearStringToInteger(sNum, iLength);
320 
321  // Qt treats a year in the range 0-100 as 1900-1999.
322  // It is nicer for the user if we treat 0-68 as 2000-2068
323  if (iYear < 69)
324  iYear += 2000;
325  else if (iYear < 100)
326  iYear += 1900;
327 
328  return iYear;
329 }
KCalendarSystem
CalendarSystem abstract class, default derived kde gregorian class and factory class.
Definition: kcalendarsystem.h:43
KCalendarSystem::weekDayName
virtual TQString weekDayName(int weekDay, bool shortName=false) const =0
Gets specific calendar type week day name If an invalid week day is specified, TQString::null is retu...
Definition: kcalendarsystem.cpp:119
KCalendarSystem::yearStringToInteger
virtual int yearStringToInteger(const TQString &sNum, int &iLength) const
Converts a year literal of a part of a string into a integer starting at the beginning of the string.
Definition: kcalendarsystem.cpp:114
KCalendarSystem::year
virtual int year(const TQDate &date) const =0
Gets specific calendar type year for a given gregorian date.
TDELocale
TDELocale provides support for country specific stuff like the national language.
Definition: tdelocale.h:124
tdelocale.h

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.1
This website is maintained by Timothy Pearson.