• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KHolidays Library

  • sources
  • kde-4.14
  • kdepimlibs
  • kholidays
zodiac.cpp
1 /*
2  This file is part of the kholidays library.
3 
4  Copyright (c) 2005-2007 Allen Winter <winter@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "zodiac.h"
23 
24 #include <KLocalizedString>
25 
26 #include <QtCore/QDateTime>
27 #include <QtCore/QSharedData>
28 
29 using namespace KHolidays;
30 
31 class KHolidays::ZodiacPrivate : public QSharedData
32 {
33  public:
34  ZodiacPrivate( Zodiac::ZodiacType type )
35  : mType( type )
36  {
37  }
38 
39  ZodiacPrivate( const ZodiacPrivate &other )
40  : QSharedData( other )
41  {
42  mType = other.mType;
43  }
44 
45  Zodiac::ZodiacType mType;
46 };
47 
48 Zodiac::Zodiac( ZodiacType type )
49  : d( new ZodiacPrivate( type ) )
50 {
51 }
52 
53 Zodiac::Zodiac( const Zodiac &other )
54  : d( other.d )
55 {
56 }
57 
58 Zodiac::~Zodiac()
59 {
60 }
61 
62 Zodiac &Zodiac::operator=( const Zodiac &other )
63 {
64  if ( &other != this ) {
65  d = other.d;
66  }
67 
68  return *this;
69 }
70 
71 QString Zodiac::signNameAtDate( const QDate &date ) const
72 {
73  return signName( signAtDate( date ) );
74 }
75 
76 QString Zodiac::signName( Zodiac::ZodiacSigns sign )
77 {
78  switch ( sign ) {
79  case Aries:
80  return i18n( "Aries" );
81  case Taurus:
82  return i18n( "Taurus" );
83  case Gemini:
84  return i18n( "Gemini" );
85  case Cancer:
86  return i18n( "Cancer" );
87  case Leo:
88  return i18n( "Leo" );
89  case Virgo:
90  return i18n( "Virgo" );
91  case Libra:
92  return i18n( "Libra" );
93  case Scorpio:
94  return i18n( "Scorpio" );
95  case Sagittarius:
96  return i18n( "Sagittarius" );
97  case Capricorn:
98  return i18n( "Capricorn" );
99  case Aquarius:
100  return i18n( "Aquarius" );
101  case Pisces:
102  return i18n( "Pisces" );
103  default:
104  case None:
105  return QString();
106  }
107 }
108 
109 Zodiac::ZodiacSigns Zodiac::signAtDate( const QDate &date ) const
110 {
111  QDate startdate, enddate;
112 
113  switch ( d->mType ) {
114  case Tropical:
115  startdate = QDate( date.year(), 1, 1 );
116  enddate = QDate( date.year(), 1, 19 );
117  if ( date >= startdate && date <= enddate ) {
118  return Capricorn;
119  }
120 
121  startdate = enddate.addDays( 1 );
122  enddate = startdate.addDays( 29 );
123  if ( date >= startdate && date <= enddate ) {
124  return Aquarius;
125  }
126 
127  startdate = enddate.addDays( 1 );
128  enddate = QDate( date.year(), 3, 20 );
129  if ( date >= startdate && date <= enddate ) {
130  return Pisces;
131  }
132 
133  startdate = enddate.addDays( 1 ); // March 21
134  enddate = startdate.addDays( 29 );
135  if ( date >= startdate && date <= enddate ) {
136  return Aries;
137  }
138 
139  startdate = enddate.addDays( 1 );
140  enddate = startdate.addDays( 30 );
141  if ( date >= startdate && date <= enddate ) {
142  return Taurus;
143  }
144 
145  startdate = enddate.addDays( 1 );
146  enddate = startdate.addDays( 30 );
147  if ( date >= startdate && date <= enddate ) {
148  return Gemini;
149  }
150 
151  startdate = enddate.addDays( 1 );
152  enddate = startdate.addDays( 31 );
153  if ( date >= startdate && date <= enddate ) {
154  return Cancer;
155  }
156 
157  startdate = enddate.addDays( 1 );
158  enddate = startdate.addDays( 30 );
159  if ( date >= startdate && date <= enddate ) {
160  return Leo;
161  }
162 
163  startdate = enddate.addDays( 1 );
164  enddate = startdate.addDays( 30 );
165  if ( date >= startdate && date <= enddate ) {
166  return Virgo;
167  }
168 
169  startdate = enddate.addDays( 1 );
170  enddate = startdate.addDays( 29 );
171  if ( date >= startdate && date <= enddate ) {
172  return Libra;
173  }
174 
175  startdate = enddate.addDays( 1 );
176  enddate = startdate.addDays( 29 );
177  if ( date >= startdate && date <= enddate ) {
178  return Scorpio;
179  }
180 
181  startdate = enddate.addDays( 1 );
182  enddate = startdate.addDays( 29 );
183  if ( date >= startdate && date <= enddate ) {
184  return Sagittarius;
185  }
186 
187  return Capricorn;
188  break;
189 
190  case Sidereal:
191  startdate = QDate( date.year(), 1, 1 );
192  enddate = QDate( date.year(), 1, 14 );
193  if ( date >= startdate && date <= enddate ) {
194  return Sagittarius;
195  }
196 
197  startdate = enddate.addDays( 1 );
198  enddate = startdate.addDays( 28 );
199  if ( date >= startdate && date <= enddate ) {
200  return Capricorn;
201  }
202 
203  startdate = enddate.addDays( 1 );
204  enddate = QDate( date.year(), 3, 14 );
205  if ( date >= startdate && date <= enddate ) {
206  return Aquarius;
207  }
208 
209  startdate = enddate.addDays( 1 );
210  enddate = QDate( date.year(), 4, 13 );
211  if ( date >= startdate && date <= enddate ) {
212  return Pisces;
213  }
214 
215  startdate = QDate( date.year(), 4, 14 ); // April 14
216  enddate = startdate.addDays( 30 );
217  if ( date >= startdate && date <= enddate ) {
218  return Aries;
219  }
220 
221  startdate = enddate.addDays( 1 );
222  enddate = startdate.addDays( 30 );
223  if ( date >= startdate && date <= enddate ) {
224  return Taurus;
225  }
226 
227  startdate = enddate.addDays( 1 );
228  enddate = startdate.addDays( 31 );
229  if ( date >= startdate && date <= enddate ) {
230  return Gemini;
231  }
232 
233  startdate = enddate.addDays( 1 );
234  enddate = startdate.addDays( 30 );
235  if ( date >= startdate && date <= enddate ) {
236  return Cancer;
237  }
238 
239  startdate = enddate.addDays( 1 );
240  enddate = startdate.addDays( 30 );
241  if ( date >= startdate && date <= enddate ) {
242  return Leo;
243  }
244 
245  startdate = enddate.addDays( 1 );
246  enddate = startdate.addDays( 30 );
247  if ( date >= startdate && date <= enddate ) {
248  return Virgo;
249  }
250 
251  startdate = enddate.addDays( 1 );
252  enddate = startdate.addDays( 29 );
253  if ( date >= startdate && date <= enddate ) {
254  return Libra;
255  }
256 
257  startdate = enddate.addDays( 1 );
258  enddate = startdate.addDays( 28 );
259  if ( date >= startdate && date <= enddate ) {
260  return Scorpio;
261  }
262 
263  return Sagittarius;
264  break;
265  }
266  return None;
267 }
268 
269 QString Zodiac::signSymbol( Zodiac::ZodiacSigns sign )
270 {
271  switch ( sign ) {
272  case Aries:
273  return i18nc( "zodiac symbol for Aries", "ram" );
274  case Taurus:
275  return i18nc( "zodiac symbol for Taurus", "bull" );
276  case Gemini:
277  return i18nc( "zodiac symbol for Gemini", "twins" );
278  case Cancer:
279  return i18nc( "zodiac symbol for Cancer", "crab" );
280  case Leo:
281  return i18nc( "zodiac symbol for Leo", "lion" );
282  case Virgo:
283  return i18nc( "zodiac symbol for Virgo", "virgin" );
284  case Libra:
285  return i18nc( "zodiac symbol for Libra", "scales" );
286  case Scorpio:
287  return i18nc( "zodiac symbol for Scorpion", "scorpion" );
288  case Sagittarius:
289  return i18nc( "zodiac symbol for Sagittarius", "archer" );
290  case Capricorn:
291  return i18nc( "zodiac symbol for Capricorn", "goat" );
292  case Aquarius:
293  return i18nc( "zodiac symbol for Aquarius", "water carrier" );
294  case Pisces:
295  return i18nc( "zodiac symbol for Pices", "fish" );
296  default:
297  case None:
298  return QString();
299  }
300 }
QSharedData
QDate
QDate::year
int year() const
QString
QDate::addDays
QDate addDays(int ndays) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHolidays Library

Skip menu "KHolidays Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal