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

KHolidays Library

zodiac.cpp
00001 /*
00002   This file is part of the kholidays library.
00003 
00004   Copyright (c) 2005-2007 Allen Winter <winter@kde.org>
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010 
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Library General Public License for more details.
00015 
00016   You should have received a copy of the GNU Library General Public License
00017   along with this library; see the file COPYING.LIB.  If not, write to
00018   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019   Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "zodiac.h"
00023 
00024 #include <KLocale>
00025 
00026 #include <QtCore/QDateTime>
00027 #include <QtCore/QSharedData>
00028 
00029 using namespace KHolidays;
00030 
00031 class KHolidays::ZodiacPrivate : public QSharedData
00032 {
00033   public:
00034     ZodiacPrivate( Zodiac::ZodiacType type )
00035       : mType( type )
00036     {
00037     }
00038 
00039     ZodiacPrivate( const ZodiacPrivate &other )
00040       : QSharedData( other )
00041     {
00042       mType = other.mType;
00043     }
00044 
00045     Zodiac::ZodiacType mType;
00046 };
00047 
00048 Zodiac::Zodiac( ZodiacType type )
00049   : d( new ZodiacPrivate( type ) )
00050 {
00051 }
00052 
00053 Zodiac::Zodiac( const Zodiac &other )
00054   : d( other.d )
00055 {
00056 }
00057 
00058 Zodiac::~Zodiac()
00059 {
00060 }
00061 
00062 Zodiac &Zodiac::operator=( const Zodiac &other )
00063 {
00064   if ( &other != this ) {
00065     d = other.d;
00066   }
00067 
00068   return *this;
00069 }
00070 
00071 QString Zodiac::signNameAtDate( const QDate &date ) const
00072 {
00073   return signName( signAtDate( date ) );
00074 }
00075 
00076 QString Zodiac::signName( Zodiac::ZodiacSigns sign )
00077 {
00078   switch ( sign ) {
00079   case Aries:
00080     return i18n( "Aries" );
00081   case Taurus:
00082     return i18n( "Taurus" );
00083   case Gemini:
00084     return i18n( "Gemini" );
00085   case Cancer:
00086     return i18n( "Cancer" );
00087   case Leo:
00088     return i18n( "Leo" );
00089   case Virgo:
00090     return i18n( "Virgo" );
00091   case Libra:
00092     return i18n( "Libra" );
00093   case Scorpio:
00094     return i18n( "Scorpio" );
00095   case Sagittarius:
00096     return i18n( "Sagittarius" );
00097   case Capricorn:
00098     return i18n( "Capricorn" );
00099   case Aquarius:
00100     return i18n( "Aquarius" );
00101   case Pisces:
00102     return i18n( "Pisces" );
00103   default:
00104   case None:
00105     return QString();
00106   }
00107 }
00108 
00109 Zodiac::ZodiacSigns Zodiac::signAtDate( const QDate &date ) const
00110 {
00111     QDate startdate, enddate;
00112 
00113     switch( d->mType ) {
00114     case Tropical:
00115         startdate = QDate( date.year(), 1, 1 );
00116         enddate = QDate( date.year(), 1, 19 );
00117         if ( date >= startdate && date <= enddate ) {
00118           return Capricorn;
00119         }
00120 
00121         startdate = enddate.addDays( 1 );
00122         enddate = startdate.addDays( 29 );
00123         if ( date >= startdate && date <= enddate ) {
00124           return Aquarius;
00125         }
00126 
00127         startdate = enddate.addDays( 1 );
00128         enddate = QDate( date.year(), 3, 20 );
00129         if ( date >= startdate && date <= enddate ) {
00130           return Pisces;
00131         }
00132 
00133         startdate = enddate.addDays( 1 );  // March 21
00134         enddate = startdate.addDays( 29 );
00135         if ( date >= startdate && date <= enddate ) {
00136           return Aries;
00137         }
00138 
00139         startdate = enddate.addDays( 1 );
00140         enddate = startdate.addDays( 30 );
00141         if ( date >= startdate && date <= enddate ) {
00142           return Taurus;
00143         }
00144 
00145         startdate = enddate.addDays( 1 );
00146         enddate = startdate.addDays( 30 );
00147         if ( date >= startdate && date <= enddate ) {
00148           return Gemini;
00149         }
00150 
00151         startdate = enddate.addDays( 1 );
00152         enddate = startdate.addDays( 31 );
00153         if ( date >= startdate && date <= enddate ) {
00154           return Cancer;
00155         }
00156 
00157         startdate = enddate.addDays( 1 );
00158         enddate = startdate.addDays( 30 );
00159         if ( date >= startdate && date <= enddate ) {
00160           return Leo;
00161         }
00162 
00163         startdate = enddate.addDays( 1 );
00164         enddate = startdate.addDays( 30 );
00165         if ( date >= startdate && date <= enddate ) {
00166           return Virgo;
00167         }
00168 
00169         startdate = enddate.addDays( 1 );
00170         enddate = startdate.addDays( 29 );
00171         if ( date >= startdate && date <= enddate ) {
00172           return Libra;
00173         }
00174 
00175         startdate = enddate.addDays( 1 );
00176         enddate = startdate.addDays( 29 );
00177         if ( date >= startdate && date <= enddate ) {
00178           return Scorpio;
00179         }
00180 
00181         startdate = enddate.addDays( 1 );
00182         enddate = startdate.addDays( 29 );
00183         if ( date >= startdate && date <= enddate ) {
00184           return Sagittarius;
00185         }
00186 
00187         return Capricorn;
00188         break;
00189 
00190     case Sidereal:
00191         startdate = QDate( date.year(), 1, 1 );
00192         enddate = QDate( date.year(), 1, 14 );
00193         if ( date >= startdate && date <= enddate ) {
00194           return Sagittarius;
00195         }
00196 
00197         startdate = enddate.addDays( 1 );
00198         enddate = startdate.addDays( 28 );
00199         if ( date >= startdate && date <= enddate ) {
00200           return Capricorn;
00201         }
00202 
00203         startdate = enddate.addDays( 1 );
00204         enddate = QDate( date.year(), 3, 14 );
00205         if ( date >= startdate && date <= enddate ) {
00206           return Aquarius;
00207         }
00208 
00209         startdate = enddate.addDays( 1 );
00210         enddate = QDate( date.year(), 4, 13 );
00211         if ( date >= startdate && date <= enddate ) {
00212           return Pisces;
00213         }
00214 
00215         startdate = QDate( date.year(), 4, 14 );  // April 14
00216         enddate = startdate.addDays( 30 );
00217         if ( date >= startdate && date <= enddate ) {
00218           return Aries;
00219         }
00220 
00221         startdate = enddate.addDays( 1 );
00222         enddate = startdate.addDays( 30 );
00223         if ( date >= startdate && date <= enddate ) {
00224           return Taurus;
00225         }
00226 
00227         startdate = enddate.addDays( 1 );
00228         enddate = startdate.addDays( 31 );
00229         if ( date >= startdate && date <= enddate ) {
00230           return Gemini;
00231         }
00232 
00233         startdate = enddate.addDays( 1 );
00234         enddate = startdate.addDays( 30 );
00235         if ( date >= startdate && date <= enddate ) {
00236           return Cancer;
00237         }
00238 
00239         startdate = enddate.addDays( 1 );
00240         enddate = startdate.addDays( 30 );
00241         if ( date >= startdate && date <= enddate ) {
00242           return Leo;
00243         }
00244 
00245         startdate = enddate.addDays( 1 );
00246         enddate = startdate.addDays( 30 );
00247         if ( date >= startdate && date <= enddate ) {
00248           return Virgo;
00249         }
00250 
00251         startdate = enddate.addDays( 1 );
00252         enddate = startdate.addDays( 29 );
00253         if ( date >= startdate && date <= enddate ) {
00254           return Libra;
00255         }
00256 
00257         startdate = enddate.addDays( 1 );
00258         enddate = startdate.addDays( 28 );
00259         if ( date >= startdate && date <= enddate ) {
00260           return Scorpio;
00261         }
00262 
00263         return Sagittarius;
00264         break;
00265     }
00266     return None;
00267 }
00268 
00269 QString Zodiac::signSymbol( Zodiac::ZodiacSigns sign )
00270 {
00271   switch( sign ) {
00272   case Aries:
00273     return i18nc( "zodiac symbol for Aries", "ram" );
00274   case Taurus:
00275     return i18nc( "zodiac symbol for Taurus", "bull" );
00276   case Gemini:
00277     return i18nc( "zodiac symbol for Gemini", "twins" );
00278   case Cancer:
00279     return i18nc( "zodiac symbol for Cancer", "crab" );
00280   case Leo:
00281     return i18nc( "zodiac symbol for Leo", "lion" );
00282   case Virgo:
00283     return i18nc( "zodiac symbol for Virgo", "virgin" );
00284   case Libra:
00285     return i18nc( "zodiac symbol for Libra", "scales" );
00286   case Scorpio:
00287     return i18nc( "zodiac symbol for Scorpion", "scorpion" );
00288   case Sagittarius:
00289     return i18nc( "zodiac symbol for Sagittarius", "archer" );
00290   case Capricorn:
00291     return i18nc( "zodiac symbol for Capricorn", "goat" );
00292   case Aquarius:
00293     return i18nc( "zodiac symbol for Aquarius", "water carrier" );
00294   case Pisces:
00295     return i18nc( "zodiac symbol for Pices", "fish" );
00296   default:
00297   case None:
00298     return QString();
00299   }
00300 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:24:21 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHolidays Library

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

kdepimlibs-4.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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