Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/tntdb/include/tntdb/date.h

00001 /*
00002  * Copyright (C) 2005 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 
00029 #ifndef TNTDB_DATE_H
00030 #define TNTDB_DATE_H
00031 
00032 #include <string>
00033 
00034 namespace tntdb
00035 {
00039   class Date
00040   {
00041       unsigned short year;
00042       unsigned short month;
00043       unsigned short day;
00044 
00045     public:
00047       Date()
00048         : year(0), month(0), day(0)
00049         { }
00050 
00053       Date(unsigned short year_,
00054            unsigned short month_,
00055            unsigned short day_)
00056         : year(year_),
00057           month(month_),
00058           day(day_)
00059           { }
00060 
00061       static Date localtime();
00062       static Date gmtime();
00063 
00065       unsigned short getYear() const     { return year; }
00067       unsigned short getMonth() const    { return month; }
00069       unsigned short getDay() const      { return day; }
00071       unsigned short getWDay() const;
00072 
00073       bool isNull() const  { return month == 0; }
00074 
00076       void set(unsigned short year_,
00077                unsigned short month_,
00078                unsigned short day_)
00079       {
00080         year = year_;
00081         month = month_;
00082         day = day_;
00083       }
00084 
00086       std::string getIso() const;
00089       static Date fromIso(const std::string& s);
00090 
00091       bool operator== (const Date& dt) const
00092       { return year == dt.year
00093             && month == dt.month
00094             && day == dt.day; }
00095 
00096       bool operator!= (const Date& dt) const
00097         { return !operator==(dt); }
00098 
00099       bool operator< (const Date& dt) const
00100       {
00101         return year   < dt.year   ? true
00102              : year   > dt.year   ? false
00103              : month  < dt.month  ? true
00104              : month  > dt.month  ? false
00105              : day    < dt.day;
00106       }
00107 
00108       bool operator> (const Date& dt) const
00109         { return dt < *this; }
00110 
00111       bool operator<= (const Date& dt) const
00112         { return !(*this > dt); }
00113 
00114       bool operator>= (const Date& dt) const
00115         { return !(*this < dt); }
00116   };
00117 }
00118 
00119 #endif // TNTDB_DATE_H
00120 
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6