File indexing completed on 2024-12-08 09:38:11
0001 /* 0002 This file is part of the kholidays library. 0003 0004 SPDX-FileCopyrightText: 2005-2007 Allen Winter <winter@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "zodiac.h" 0010 0011 #include <QCoreApplication> 0012 #include <QDate> 0013 #include <QSharedData> 0014 0015 using namespace KHolidays; 0016 0017 class Q_DECL_HIDDEN KHolidays::ZodiacPrivate : public QSharedData 0018 { 0019 public: 0020 explicit ZodiacPrivate(Zodiac::ZodiacType type) 0021 : mType(type) 0022 { 0023 } 0024 0025 ZodiacPrivate(const ZodiacPrivate &other) 0026 : QSharedData(other) 0027 { 0028 mType = other.mType; 0029 } 0030 0031 Zodiac::ZodiacType mType; 0032 }; 0033 0034 Zodiac::Zodiac(ZodiacType type) 0035 : d(new ZodiacPrivate(type)) 0036 { 0037 } 0038 0039 Zodiac::Zodiac(const Zodiac &other) 0040 : d(other.d) 0041 { 0042 } 0043 0044 Zodiac::~Zodiac() 0045 { 0046 } 0047 0048 Zodiac &Zodiac::operator=(const Zodiac &other) 0049 { 0050 if (&other != this) { 0051 d = other.d; 0052 } 0053 0054 return *this; 0055 } 0056 0057 QString Zodiac::signNameAtDate(const QDate &date) const 0058 { 0059 return signName(signAtDate(date)); 0060 } 0061 0062 QString Zodiac::signName(Zodiac::ZodiacSigns sign) 0063 { 0064 switch (sign) { 0065 case Aries: 0066 return QCoreApplication::translate("Zodiac", "Aries"); 0067 case Taurus: 0068 return QCoreApplication::translate("Zodiac", "Taurus"); 0069 case Gemini: 0070 return QCoreApplication::translate("Zodiac", "Gemini"); 0071 case Cancer: 0072 return QCoreApplication::translate("Zodiac", "Cancer"); 0073 case Leo: 0074 return QCoreApplication::translate("Zodiac", "Leo"); 0075 case Virgo: 0076 return QCoreApplication::translate("Zodiac", "Virgo"); 0077 case Libra: 0078 return QCoreApplication::translate("Zodiac", "Libra"); 0079 case Scorpio: 0080 return QCoreApplication::translate("Zodiac", "Scorpio"); 0081 case Sagittarius: 0082 return QCoreApplication::translate("Zodiac", "Sagittarius"); 0083 case Capricorn: 0084 return QCoreApplication::translate("Zodiac", "Capricorn"); 0085 case Aquarius: 0086 return QCoreApplication::translate("Zodiac", "Aquarius"); 0087 case Pisces: 0088 return QCoreApplication::translate("Zodiac", "Pisces"); 0089 case None: 0090 return QString(); 0091 } 0092 return QString(); 0093 } 0094 0095 Zodiac::ZodiacSigns Zodiac::signAtDate(const QDate &date) const 0096 { 0097 QDate startdate; 0098 QDate enddate; 0099 0100 switch (d->mType) { 0101 case Tropical: 0102 startdate = QDate(date.year(), 1, 1); 0103 enddate = QDate(date.year(), 1, 19); 0104 if (date >= startdate && date <= enddate) { 0105 return Capricorn; 0106 } 0107 0108 startdate = enddate.addDays(1); 0109 enddate = startdate.addDays(29); 0110 if (date >= startdate && date <= enddate) { 0111 return Aquarius; 0112 } 0113 0114 startdate = enddate.addDays(1); 0115 enddate = QDate(date.year(), 3, 20); 0116 if (date >= startdate && date <= enddate) { 0117 return Pisces; 0118 } 0119 0120 startdate = enddate.addDays(1); // March 21 0121 enddate = startdate.addDays(29); 0122 if (date >= startdate && date <= enddate) { 0123 return Aries; 0124 } 0125 0126 startdate = enddate.addDays(1); 0127 enddate = startdate.addDays(30); 0128 if (date >= startdate && date <= enddate) { 0129 return Taurus; 0130 } 0131 0132 startdate = enddate.addDays(1); 0133 enddate = startdate.addDays(30); 0134 if (date >= startdate && date <= enddate) { 0135 return Gemini; 0136 } 0137 0138 startdate = enddate.addDays(1); 0139 enddate = startdate.addDays(31); 0140 if (date >= startdate && date <= enddate) { 0141 return Cancer; 0142 } 0143 0144 startdate = enddate.addDays(1); 0145 enddate = startdate.addDays(30); 0146 if (date >= startdate && date <= enddate) { 0147 return Leo; 0148 } 0149 0150 startdate = enddate.addDays(1); 0151 enddate = startdate.addDays(30); 0152 if (date >= startdate && date <= enddate) { 0153 return Virgo; 0154 } 0155 0156 startdate = enddate.addDays(1); 0157 enddate = startdate.addDays(29); 0158 if (date >= startdate && date <= enddate) { 0159 return Libra; 0160 } 0161 0162 startdate = enddate.addDays(1); 0163 enddate = startdate.addDays(29); 0164 if (date >= startdate && date <= enddate) { 0165 return Scorpio; 0166 } 0167 0168 startdate = enddate.addDays(1); 0169 enddate = startdate.addDays(29); 0170 if (date >= startdate && date <= enddate) { 0171 return Sagittarius; 0172 } 0173 0174 return Capricorn; 0175 0176 case Sidereal: 0177 startdate = QDate(date.year(), 1, 1); 0178 enddate = QDate(date.year(), 1, 14); 0179 if (date >= startdate && date <= enddate) { 0180 return Sagittarius; 0181 } 0182 0183 startdate = enddate.addDays(1); 0184 enddate = startdate.addDays(28); 0185 if (date >= startdate && date <= enddate) { 0186 return Capricorn; 0187 } 0188 0189 startdate = enddate.addDays(1); 0190 enddate = QDate(date.year(), 3, 14); 0191 if (date >= startdate && date <= enddate) { 0192 return Aquarius; 0193 } 0194 0195 startdate = enddate.addDays(1); 0196 enddate = QDate(date.year(), 4, 13); 0197 if (date >= startdate && date <= enddate) { 0198 return Pisces; 0199 } 0200 0201 startdate = QDate(date.year(), 4, 14); // April 14 0202 enddate = startdate.addDays(30); 0203 if (date >= startdate && date <= enddate) { 0204 return Aries; 0205 } 0206 0207 startdate = enddate.addDays(1); 0208 enddate = startdate.addDays(30); 0209 if (date >= startdate && date <= enddate) { 0210 return Taurus; 0211 } 0212 0213 startdate = enddate.addDays(1); 0214 enddate = startdate.addDays(31); 0215 if (date >= startdate && date <= enddate) { 0216 return Gemini; 0217 } 0218 0219 startdate = enddate.addDays(1); 0220 enddate = startdate.addDays(30); 0221 if (date >= startdate && date <= enddate) { 0222 return Cancer; 0223 } 0224 0225 startdate = enddate.addDays(1); 0226 enddate = startdate.addDays(30); 0227 if (date >= startdate && date <= enddate) { 0228 return Leo; 0229 } 0230 0231 startdate = enddate.addDays(1); 0232 enddate = startdate.addDays(30); 0233 if (date >= startdate && date <= enddate) { 0234 return Virgo; 0235 } 0236 0237 startdate = enddate.addDays(1); 0238 enddate = startdate.addDays(29); 0239 if (date >= startdate && date <= enddate) { 0240 return Libra; 0241 } 0242 0243 startdate = enddate.addDays(1); 0244 enddate = startdate.addDays(28); 0245 if (date >= startdate && date <= enddate) { 0246 return Scorpio; 0247 } 0248 0249 return Sagittarius; 0250 } 0251 return None; 0252 } 0253 0254 QString Zodiac::signSymbol(Zodiac::ZodiacSigns sign) 0255 { 0256 switch (sign) { 0257 case Aries: 0258 return QCoreApplication::translate("HolidayRegion", "ram", "zodiac symbol for Aries"); 0259 case Taurus: 0260 return QCoreApplication::translate("HolidayRegion", "bull", "zodiac symbol for Taurus"); 0261 case Gemini: 0262 return QCoreApplication::translate("HolidayRegion", "twins", "zodiac symbol for Gemini"); 0263 case Cancer: 0264 return QCoreApplication::translate("HolidayRegion", "crab", "zodiac symbol for Cancer"); 0265 case Leo: 0266 return QCoreApplication::translate("HolidayRegion", "lion", "zodiac symbol for Leo"); 0267 case Virgo: 0268 return QCoreApplication::translate("HolidayRegion", "virgin", "zodiac symbol for Virgo"); 0269 case Libra: 0270 return QCoreApplication::translate("HolidayRegion", "scales", "zodiac symbol for Libra"); 0271 case Scorpio: 0272 return QCoreApplication::translate("HolidayRegion", "scorpion", "zodiac symbol for Scorpion"); 0273 case Sagittarius: 0274 return QCoreApplication::translate("HolidayRegion", "archer", "zodiac symbol for Sagittarius"); 0275 case Capricorn: 0276 return QCoreApplication::translate("HolidayRegion", "goat", "zodiac symbol for Capricorn"); 0277 case Aquarius: 0278 return QCoreApplication::translate("HolidayRegion", "water carrier", "zodiac symbol for Aquarius"); 0279 case Pisces: 0280 return QCoreApplication::translate("HolidayRegion", "fish", "zodiac symbol for Pices"); 0281 case None: 0282 return QString(); 0283 } 0284 return QString(); 0285 }