MySQLaux 0.6 is free software from Langensoft written by Thomas Langen.

Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

MySQLaux/Date.h

Go to the documentation of this file.
00001 /* 
00002  * MySQLaux - auxiliary classes for communication with MySQL databases
00003  * Copyright © 2001  Thomas Langen (mailto:langen@langensoft.com)
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  * 
00019  * $Source: Date.h $
00020  * $Id: Date.h 1.3 Fri, 06 Apr 2001 10:30:48 +0200 langen $
00021  * $ProjectHeader: MySQLaux 0.6 Fri, 06 Apr 2001 10:30:48 +0200 langen $
00022  */
00023 
00024 #ifndef __MySQLaux_Date_h__
00025 #define __MySQLaux_Date_h__
00026 
00027 #include "Exception.h"
00028 #include <string>
00029 #include <sstream>
00030 
00031 namespace MySQLaux
00032 {
00036   class InvalidDate
00037     : public Exception
00038   {
00039   public:
00040     inline string asString() const throw() 
00041     {
00042       return "Invalid date";
00043     }
00044   };
00045   
00049   class Date
00050   {
00051   private:
00052     unsigned _year;  // 1000 .. 9999, 0 means invalid date
00053     unsigned _month; // 1 .. 12, 0 means invalid date
00054     unsigned _day;   // 1 .. 31, 0 means invalid date
00055   public:
00062     Date (const char * s) throw (InvalidDate);
00063     
00067     inline Date () throw() { _year = _month = _day = 0; }
00068     
00072     inline unsigned day() const throw (InvalidDate)
00073     {
00074       if (_day == 0 || _day > 31)
00075         throw InvalidDate();
00076       return _day;
00077     }
00078     
00082     inline unsigned month() const throw (InvalidDate)
00083     {
00084       if (_month == 0 || _month > 12)
00085         throw InvalidDate();
00086       return _month;
00087     }
00088     
00092     inline unsigned year() const throw (InvalidDate)
00093     {
00094       if (_year < 1000 | _year > 9999)
00095         throw InvalidDate();
00096       return _year;
00097     }
00098     
00108     string asString(unsigned format) const throw (InvalidDate);
00109     
00114     unsigned long asBCD () const throw (InvalidDate);
00115   };
00116 }
00117 
00122 bool operator<  (MySQLaux::Date const & date1, 
00123                  MySQLaux::Date const & date2) 
00124   throw (MySQLaux::InvalidDate);
00125 
00126 bool operator== (MySQLaux::Date const & date1, 
00127                  MySQLaux::Date const & date2) 
00128   throw (MySQLaux::InvalidDate);
00129 
00130 inline bool operator<= (MySQLaux::Date const & date1, 
00131                         MySQLaux::Date const & date2) 
00132   throw (MySQLaux::InvalidDate)
00133 {
00134   return (date1 < date2 || date1 == date2);
00135 }
00136 
00137 inline bool operator!= (MySQLaux::Date const & date1, 
00138                         MySQLaux::Date const & date2) 
00139   throw (MySQLaux::InvalidDate)
00140 {
00141   return (!(date1 == date2));
00142 }
00143 
00144 inline bool operator>  (MySQLaux::Date const & date1, 
00145                         MySQLaux::Date const & date2) 
00146   throw (MySQLaux::InvalidDate)
00147 {
00148   return (!(date1 < date2) && !(date1 == date2));
00149 }
00150 
00151 inline bool operator>= (MySQLaux::Date const & date1, 
00152                         MySQLaux::Date const & date2) 
00153   throw (MySQLaux::InvalidDate)
00154 {
00155   return (!(date1 < date2));
00156 }
00164 std::ostream & operator<<(std::ostream & os, MySQLaux::Date const & date) throw (MySQLaux::InvalidDate);
00165 
00172 std::istringstream & operator>>(std::istringstream & is, MySQLaux::Date & date)
00173   throw (MySQLaux::InvalidDate);
00174 
00175 #endif // __MySQLaux_Date_h__
00176 
00177 
00178 /*
00179  * Local Variables:
00180  * mode: C++
00181  * fill-column: 80
00182  * c-comment-continuation-stars: " * "
00183  * End:
00184  */

Generated at Fri Apr 6 11:20:02 2001 for MySQLaux by doxygen1.2.5 written by Dimitri van Heesch, © 1997-2001