From: Christian P. <cp...@us...> - 2004-12-26 17:03:04
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31213/include/pclasses Added Files: Date.h Log Message: Added Date class --- NEW FILE: Date.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Date_h #define P_Date_h #include <pclasses/Exception.h> #include <iostream> namespace P { //! Invalid date error class InvalidDate: public RuntimeError { public: InvalidDate(const char* _what, const SourceInfo& si) : RuntimeError(_what, si) {} }; //! Date class class Date { public: //! Enumeration of weekdays enum weekDay_t { Saturday = 0, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday }; //! Enumeration of months enum month_t { January = 1, February, March, April, May, June, July, August, September, October, November, December }; Date(unsigned int year = 1970, unsigned int month = 1, unsigned int day = 1) throw(InvalidDate); ~Date() throw(); double julianDayNumber() const throw(); void setYear(unsigned int year); unsigned int year() const throw(); void setMonth(unsigned int month) throw(InvalidDate); unsigned int month() const throw(); //! Returns the number of days in stored month unsigned int daysInMonth() throw(); void setDay(unsigned int day) throw(InvalidDate); unsigned int day() const throw(); unsigned int dayOfYear() const throw(); unsigned int dayOfWeek() const throw(); //! Test if date is in a leap year bool isInLeapYear() const throw(); bool operator>(const Date& d) const throw(); bool operator<(const Date& d) const throw(); bool operator>=(const Date& d) const throw(); bool operator<=(const Date& d) const throw(); bool operator==(const Date& d) const throw(); bool operator!=(const Date& d) const throw(); //! Returns the number of days in month static unsigned int daysInMonth(unsigned int month, unsigned int year) throw(InvalidDate); //! Test if the given year is a leap year static bool isLeapYear(unsigned int year) throw(); friend std::ostream& operator << (std::ostream& os, const Date& d); private: unsigned short _year; unsigned char _month; unsigned char _day; }; } // !namespace P #endif |