KHolidays

zodiac.cpp
1/*
2 This file is part of the kholidays library.
3
4 SPDX-FileCopyrightText: 2005-2007 Allen Winter <winter@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "zodiac.h"
10
11#include <QCoreApplication>
12#include <QDate>
13#include <QSharedData>
14
15using namespace KHolidays;
16
17class Q_DECL_HIDDEN KHolidays::ZodiacPrivate : public QSharedData
18{
19public:
20 explicit ZodiacPrivate(Zodiac::ZodiacType type)
21 : mType(type)
22 {
23 }
24
25 ZodiacPrivate(const ZodiacPrivate &other)
26 : QSharedData(other)
27 {
28 mType = other.mType;
29 }
30
31 Zodiac::ZodiacType mType;
32};
33
34Zodiac::Zodiac(ZodiacType type)
35 : d(new ZodiacPrivate(type))
36{
37}
38
39Zodiac::Zodiac(const Zodiac &other)
40 : d(other.d)
41{
42}
43
44Zodiac::~Zodiac()
45{
46}
47
48Zodiac &Zodiac::operator=(const Zodiac &other)
49{
50 if (&other != this) {
51 d = other.d;
52 }
53
54 return *this;
55}
56
58{
59 return signName(signAtDate(date));
60}
61
62QString Zodiac::signName(Zodiac::ZodiacSigns sign)
63{
64 switch (sign) {
65 case Aries:
66 return QCoreApplication::translate("Zodiac", "Aries");
67 case Taurus:
68 return QCoreApplication::translate("Zodiac", "Taurus");
69 case Gemini:
70 return QCoreApplication::translate("Zodiac", "Gemini");
71 case Cancer:
72 return QCoreApplication::translate("Zodiac", "Cancer");
73 case Leo:
74 return QCoreApplication::translate("Zodiac", "Leo");
75 case Virgo:
76 return QCoreApplication::translate("Zodiac", "Virgo");
77 case Libra:
78 return QCoreApplication::translate("Zodiac", "Libra");
79 case Scorpio:
80 return QCoreApplication::translate("Zodiac", "Scorpio");
81 case Sagittarius:
82 return QCoreApplication::translate("Zodiac", "Sagittarius");
83 case Capricorn:
84 return QCoreApplication::translate("Zodiac", "Capricorn");
85 case Aquarius:
86 return QCoreApplication::translate("Zodiac", "Aquarius");
87 case Pisces:
88 return QCoreApplication::translate("Zodiac", "Pisces");
89 case None:
90 return QString();
91 }
92 return QString();
93}
94
95Zodiac::ZodiacSigns Zodiac::signAtDate(const QDate &date) const
96{
97 QDate startdate;
98 QDate enddate;
99
100 switch (d->mType) {
101 case Tropical:
102 startdate = QDate(date.year(), 1, 1);
103 enddate = QDate(date.year(), 1, 19);
104 if (date >= startdate && date <= enddate) {
105 return Capricorn;
106 }
107
108 startdate = enddate.addDays(1);
109 enddate = startdate.addDays(29);
110 if (date >= startdate && date <= enddate) {
111 return Aquarius;
112 }
113
114 startdate = enddate.addDays(1);
115 enddate = QDate(date.year(), 3, 20);
116 if (date >= startdate && date <= enddate) {
117 return Pisces;
118 }
119
120 startdate = enddate.addDays(1); // March 21
121 enddate = startdate.addDays(29);
122 if (date >= startdate && date <= enddate) {
123 return Aries;
124 }
125
126 startdate = enddate.addDays(1);
127 enddate = startdate.addDays(30);
128 if (date >= startdate && date <= enddate) {
129 return Taurus;
130 }
131
132 startdate = enddate.addDays(1);
133 enddate = startdate.addDays(30);
134 if (date >= startdate && date <= enddate) {
135 return Gemini;
136 }
137
138 startdate = enddate.addDays(1);
139 enddate = startdate.addDays(31);
140 if (date >= startdate && date <= enddate) {
141 return Cancer;
142 }
143
144 startdate = enddate.addDays(1);
145 enddate = startdate.addDays(30);
146 if (date >= startdate && date <= enddate) {
147 return Leo;
148 }
149
150 startdate = enddate.addDays(1);
151 enddate = startdate.addDays(30);
152 if (date >= startdate && date <= enddate) {
153 return Virgo;
154 }
155
156 startdate = enddate.addDays(1);
157 enddate = startdate.addDays(29);
158 if (date >= startdate && date <= enddate) {
159 return Libra;
160 }
161
162 startdate = enddate.addDays(1);
163 enddate = startdate.addDays(29);
164 if (date >= startdate && date <= enddate) {
165 return Scorpio;
166 }
167
168 startdate = enddate.addDays(1);
169 enddate = startdate.addDays(29);
170 if (date >= startdate && date <= enddate) {
171 return Sagittarius;
172 }
173
174 return Capricorn;
175
176 case Sidereal:
177 startdate = QDate(date.year(), 1, 1);
178 enddate = QDate(date.year(), 1, 14);
179 if (date >= startdate && date <= enddate) {
180 return Sagittarius;
181 }
182
183 startdate = enddate.addDays(1);
184 enddate = startdate.addDays(28);
185 if (date >= startdate && date <= enddate) {
186 return Capricorn;
187 }
188
189 startdate = enddate.addDays(1);
190 enddate = QDate(date.year(), 3, 14);
191 if (date >= startdate && date <= enddate) {
192 return Aquarius;
193 }
194
195 startdate = enddate.addDays(1);
196 enddate = QDate(date.year(), 4, 13);
197 if (date >= startdate && date <= enddate) {
198 return Pisces;
199 }
200
201 startdate = QDate(date.year(), 4, 14); // April 14
202 enddate = startdate.addDays(30);
203 if (date >= startdate && date <= enddate) {
204 return Aries;
205 }
206
207 startdate = enddate.addDays(1);
208 enddate = startdate.addDays(30);
209 if (date >= startdate && date <= enddate) {
210 return Taurus;
211 }
212
213 startdate = enddate.addDays(1);
214 enddate = startdate.addDays(31);
215 if (date >= startdate && date <= enddate) {
216 return Gemini;
217 }
218
219 startdate = enddate.addDays(1);
220 enddate = startdate.addDays(30);
221 if (date >= startdate && date <= enddate) {
222 return Cancer;
223 }
224
225 startdate = enddate.addDays(1);
226 enddate = startdate.addDays(30);
227 if (date >= startdate && date <= enddate) {
228 return Leo;
229 }
230
231 startdate = enddate.addDays(1);
232 enddate = startdate.addDays(30);
233 if (date >= startdate && date <= enddate) {
234 return Virgo;
235 }
236
237 startdate = enddate.addDays(1);
238 enddate = startdate.addDays(29);
239 if (date >= startdate && date <= enddate) {
240 return Libra;
241 }
242
243 startdate = enddate.addDays(1);
244 enddate = startdate.addDays(28);
245 if (date >= startdate && date <= enddate) {
246 return Scorpio;
247 }
248
249 return Sagittarius;
250 }
251 return None;
252}
253
254QString Zodiac::signSymbol(Zodiac::ZodiacSigns sign)
255{
256 switch (sign) {
257 case Aries:
258 return QCoreApplication::translate("HolidayRegion", "ram", "zodiac symbol for Aries");
259 case Taurus:
260 return QCoreApplication::translate("HolidayRegion", "bull", "zodiac symbol for Taurus");
261 case Gemini:
262 return QCoreApplication::translate("HolidayRegion", "twins", "zodiac symbol for Gemini");
263 case Cancer:
264 return QCoreApplication::translate("HolidayRegion", "crab", "zodiac symbol for Cancer");
265 case Leo:
266 return QCoreApplication::translate("HolidayRegion", "lion", "zodiac symbol for Leo");
267 case Virgo:
268 return QCoreApplication::translate("HolidayRegion", "virgin", "zodiac symbol for Virgo");
269 case Libra:
270 return QCoreApplication::translate("HolidayRegion", "scales", "zodiac symbol for Libra");
271 case Scorpio:
272 return QCoreApplication::translate("HolidayRegion", "scorpion", "zodiac symbol for Scorpion");
273 case Sagittarius:
274 return QCoreApplication::translate("HolidayRegion", "archer", "zodiac symbol for Sagittarius");
275 case Capricorn:
276 return QCoreApplication::translate("HolidayRegion", "goat", "zodiac symbol for Capricorn");
277 case Aquarius:
278 return QCoreApplication::translate("HolidayRegion", "water carrier", "zodiac symbol for Aquarius");
279 case Pisces:
280 return QCoreApplication::translate("HolidayRegion", "fish", "zodiac symbol for Pices");
281 case None:
282 return QString();
283 }
284 return QString();
285}
Represents and manages the Zodiac calendar.
Definition zodiac.h:52
ZodiacSigns signAtDate(const QDate &date) const
Return the Zodiac sign for the specified Gregorian date.
Definition zodiac.cpp:95
QString signNameAtDate(const QDate &date) const
Return the Zodiac sign as a text string for the specified date.
Definition zodiac.cpp:57
static QString signName(ZodiacSigns sign)
Return the string representation of Zodiac sign.
Definition zodiac.cpp:62
static QString signSymbol(ZodiacSigns sign)
Convert the Zodiac sign to a Zodiac symbol.
Definition zodiac.cpp:254
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
QDate addDays(qint64 ndays) const const
int year() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:59:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.