2 Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
3 Copyright (c) 2002 Hans Petter Bieker <bieker@kde.org>
4 Copyright (c) 2004 Jason Harris <jharris@30doradus.org>
6 This class has been derived from ExtCalendarSystem;
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 // Gregorian calendar system implementation factory for creation of kde calendar
28 // Also default gregorian and factory classes
32 #include "extcalendarsystem.h"
35 class ExtCalendarSystemPrivate
38 const KLocale
* locale
;
41 ExtCalendarSystem::ExtCalendarSystem(const KLocale
* locale
)
42 : d(new ExtCalendarSystemPrivate
)
47 ExtCalendarSystem::~ExtCalendarSystem()
52 const KLocale
* ExtCalendarSystem::locale() const
57 return KGlobal::locale();
60 QString
ExtCalendarSystem::dayString(const ExtDate
& pDate
, bool bShort
) const
64 sResult
.setNum(day(pDate
));
65 if (!bShort
&& sResult
.length() == 1 )
71 QString
ExtCalendarSystem::monthString(const ExtDate
& pDate
, bool bShort
) const
75 sResult
.setNum(month(pDate
));
76 if (!bShort
&& sResult
.length() == 1 )
82 QString
ExtCalendarSystem::yearString(const ExtDate
& pDate
, bool bShort
) const
86 sResult
.setNum(year(pDate
));
87 if (bShort
&& sResult
.length() == 4 )
88 sResult
= sResult
.right(2);
93 static int stringToInteger(const QString
& sNum
, int & iLength
)
95 unsigned int iPos
= 0;
98 for (; sNum
.length() > iPos
&& sNum
.at(iPos
).isDigit(); iPos
++)
101 result
+= sNum
.at(iPos
).digitValue();
109 int ExtCalendarSystem::dayStringToInteger(const QString
& sNum
, int & iLength
) const
111 return stringToInteger(sNum
, iLength
);
114 int ExtCalendarSystem::monthStringToInteger(const QString
& sNum
, int & iLength
) const
116 return stringToInteger(sNum
, iLength
);
119 int ExtCalendarSystem::yearStringToInteger(const QString
& sNum
, int & iLength
) const
121 return stringToInteger(sNum
, iLength
);
124 QString
ExtCalendarSystem::weekDayName (int weekDay
, bool shortName
) const
129 case 1: return locale()->translate("Monday", "Mon");
130 case 2: return locale()->translate("Tuesday", "Tue");
131 case 3: return locale()->translate("Wednesday", "Wed");
132 case 4: return locale()->translate("Thursday", "Thu");
133 case 5: return locale()->translate("Friday", "Fri");
134 case 6: return locale()->translate("Saturday", "Sat");
135 case 7: return locale()->translate("Sunday", "Sun");
140 case 1: return locale()->translate("Monday");
141 case 2: return locale()->translate("Tuesday");
142 case 3: return locale()->translate("Wednesday");
143 case 4: return locale()->translate("Thursday");
144 case 5: return locale()->translate("Friday");
145 case 6: return locale()->translate("Saturday");
146 case 7: return locale()->translate("Sunday");
149 return QString::null
;