moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / libkdeedu / extdate / extcalendarsystem.cpp
blob1f49b9f53d6360e27c32af2490cba8e47ad38373
1 /*
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
27 // systems.
28 // Also default gregorian and factory classes
30 #include <kglobal.h>
32 #include "extcalendarsystem.h"
33 #include "klocale.h"
35 class ExtCalendarSystemPrivate
37 public:
38 const KLocale * locale;
41 ExtCalendarSystem::ExtCalendarSystem(const KLocale * locale)
42 : d(new ExtCalendarSystemPrivate)
44 d->locale = locale;
47 ExtCalendarSystem::~ExtCalendarSystem()
49 delete d;
52 const KLocale * ExtCalendarSystem::locale() const
54 if ( d->locale )
55 return d->locale;
57 return KGlobal::locale();
60 QString ExtCalendarSystem::dayString(const ExtDate & pDate, bool bShort) const
62 QString sResult;
64 sResult.setNum(day(pDate));
65 if (!bShort && sResult.length() == 1 )
66 sResult.prepend('0');
68 return sResult;
71 QString ExtCalendarSystem::monthString(const ExtDate & pDate, bool bShort) const
73 QString sResult;
75 sResult.setNum(month(pDate));
76 if (!bShort && sResult.length() == 1 )
77 sResult.prepend('0');
79 return sResult;
82 QString ExtCalendarSystem::yearString(const ExtDate & pDate, bool bShort) const
84 QString sResult;
86 sResult.setNum(year(pDate));
87 if (bShort && sResult.length() == 4 )
88 sResult = sResult.right(2);
90 return sResult;
93 static int stringToInteger(const QString & sNum, int & iLength)
95 unsigned int iPos = 0;
97 int result = 0;
98 for (; sNum.length() > iPos && sNum.at(iPos).isDigit(); iPos++)
100 result *= 10;
101 result += sNum.at(iPos).digitValue();
104 iLength = iPos;
105 return result;
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
126 if ( shortName )
127 switch ( weekDay )
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");
137 else
138 switch ( weekDay )
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;