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

tdecore

  • tdecore
kcalendarsystem.cpp
1/*
2 Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
3 Copyright (c) 2002 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// Gregorian calendar system implementation factory for creation of kde calendar
22// systems.
23// Also default gregorian and factory classes
24
25#include <tdeglobal.h>
26
27#include "kcalendarsystem.h"
28#include "tdelocale.h"
29
30class KCalendarSystemPrivate
31{
32public:
33 const TDELocale * locale;
34};
35
36KCalendarSystem::KCalendarSystem(const TDELocale * locale)
37 : d(new KCalendarSystemPrivate)
38{
39 d->locale = locale;
40}
41
42KCalendarSystem::~KCalendarSystem()
43{
44 delete d;
45}
46
47const TDELocale * KCalendarSystem::locale() const
48{
49 if ( d->locale )
50 return d->locale;
51
52 return TDEGlobal::locale();
53}
54
55TQString KCalendarSystem::dayString(const TQDate & pDate, bool bShort) const
56{
57 TQString sResult;
58
59 sResult.setNum(day(pDate));
60 if (!bShort && sResult.length() == 1 )
61 sResult.prepend('0');
62
63 return sResult;
64}
65
66TQString KCalendarSystem::monthString(const TQDate & pDate, bool bShort) const
67{
68 TQString sResult;
69
70 sResult.setNum(month(pDate));
71 if (!bShort && sResult.length() == 1 )
72 sResult.prepend('0');
73
74 return sResult;
75}
76
77TQString KCalendarSystem::yearString(const TQDate & pDate, bool bShort) const
78{
79 TQString sResult;
80
81 sResult.setNum(year(pDate));
82 if (bShort && sResult.length() == 4 )
83 sResult = sResult.right(2);
84
85 return sResult;
86}
87
88static int stringToInteger(const TQString & sNum, int & iLength)
89{
90 unsigned int iPos = 0;
91
92 int result = 0;
93 for (; sNum.length() > iPos && sNum.at(iPos).isDigit(); iPos++)
94 {
95 result *= 10;
96 result += sNum.at(iPos).digitValue();
97 }
98
99 iLength = iPos;
100 return result;
101}
102
103
104int KCalendarSystem::dayStringToInteger(const TQString & sNum, int & iLength) const
105{
106 return stringToInteger(sNum, iLength);
107}
108
109int KCalendarSystem::monthStringToInteger(const TQString & sNum, int & iLength) const
110{
111 return stringToInteger(sNum, iLength);
112}
113
114int KCalendarSystem::yearStringToInteger(const TQString & sNum, int & iLength) const
115{
116 return stringToInteger(sNum, iLength);
117}
118
119TQString KCalendarSystem::weekDayName (int weekDay, bool shortName) const
120{
121 if ( shortName )
122 switch ( weekDay )
123 {
124 case 1: return locale()->translate("Monday", "Mon");
125 case 2: return locale()->translate("Tuesday", "Tue");
126 case 3: return locale()->translate("Wednesday", "Wed");
127 case 4: return locale()->translate("Thursday", "Thu");
128 case 5: return locale()->translate("Friday", "Fri");
129 case 6: return locale()->translate("Saturday", "Sat");
130 case 7: return locale()->translate("Sunday", "Sun");
131 }
132 else
133 switch ( weekDay )
134 {
135 case 1: return locale()->translate("Monday");
136 case 2: return locale()->translate("Tuesday");
137 case 3: return locale()->translate("Wednesday");
138 case 4: return locale()->translate("Thursday");
139 case 5: return locale()->translate("Friday");
140 case 6: return locale()->translate("Saturday");
141 case 7: return locale()->translate("Sunday");
142 }
143
144 return TQString::null;
145}
146
KCalendarSystem::monthStringToInteger
virtual int monthStringToInteger(const TQString &sNum, int &iLength) const
Converts a month literal of a part of a string into a integer starting at the beginning of the string...
Definition: kcalendarsystem.cpp:109
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::KCalendarSystem
KCalendarSystem(const TDELocale *locale=0)
Constructor of abstract calendar class.
Definition: kcalendarsystem.cpp:36
KCalendarSystem::day
virtual int day(const TQDate &date) const =0
Gets specific calendar type day number of month for a given date.
KCalendarSystem::~KCalendarSystem
virtual ~KCalendarSystem()
Descructor.
Definition: kcalendarsystem.cpp:42
KCalendarSystem::month
virtual int month(const TQDate &date) const =0
Gets specific calendar type month for a given gregorian date.
KCalendarSystem::dayString
virtual TQString dayString(const TQDate &pDate, bool bShort) const
Converts a date into a day literal.
Definition: kcalendarsystem.cpp:55
KCalendarSystem::monthString
virtual TQString monthString(const TQDate &pDate, bool bShort) const
Converts a date into a month literal.
Definition: kcalendarsystem.cpp:66
KCalendarSystem::locale
const TDELocale * locale() const
Gets the locale the calendar uses for translations.
Definition: kcalendarsystem.cpp:47
KCalendarSystem::yearString
virtual TQString yearString(const TQDate &pDate, bool bShort) const
Converts a date into a year literal.
Definition: kcalendarsystem.cpp:77
KCalendarSystem::year
virtual int year(const TQDate &date) const =0
Gets specific calendar type year for a given gregorian date.
KCalendarSystem::dayStringToInteger
virtual int dayStringToInteger(const TQString &sNum, int &iLength) const
Converts a day literal of a part of a string into a integer starting at the beginning of the string.
Definition: kcalendarsystem.cpp:104
TDEGlobal::locale
static TDELocale * locale()
Returns the global locale object.
Definition: tdeglobal.cpp:108
TDELocale
TDELocale provides support for country specific stuff like the national language.
Definition: tdelocale.h:124
TDELocale::translate
TQString translate(const char *index) const
Translates the string into the corresponding string in the national language, if available.
Definition: tdelocale.cpp:768
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.4
This website is maintained by Timothy Pearson.