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

PDateTime.h

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // PDateTime 00004 // Copyright (c) 2002 by Nicolas Chapados 00005 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // 00009 // 1. Redistributions of source code must retain the above copyright 00010 // notice, this list of conditions and the following disclaimer. 00011 // 00012 // 2. Redistributions in binary form must reproduce the above copyright 00013 // notice, this list of conditions and the following disclaimer in the 00014 // documentation and/or other materials provided with the distribution. 00015 // 00016 // 3. The name of the authors may not be used to endorse or promote 00017 // products derived from this software without specific prior written 00018 // permission. 00019 // 00020 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00021 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00022 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00023 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00025 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 // 00031 // This file is part of the PLearn library. For more information on the PLearn 00032 // library, go to the PLearn Web site at www.plearn.org 00033 00034 /* ******************************************************* 00035 * $Id: PDateTime.h,v 1.4 2004/02/28 17:53:51 tihocan Exp $ 00036 * This file is part of the PLearn library. 00037 ******************************************************* */ 00038 00039 00042 #ifndef PDateTime_INC 00043 #define PDateTime_INC 00044 00045 //#include <iostream> 00046 #include <string> 00047 00048 namespace PLearn { 00049 using namespace std; 00050 00060 class PDateTime 00061 { 00062 public: 00063 short year; 00064 unsigned char month; 00065 unsigned char day; 00066 unsigned char hour; 00067 unsigned char min; 00068 unsigned char sec; 00069 00071 PDateTime(); 00072 00074 PDateTime(short the_year, unsigned char the_month, unsigned char the_day) 00075 : year(the_year), month(the_month), day(the_day), 00076 hour(0), min(0), sec(0) {} 00077 00078 PDateTime(int the_year, int the_month, int the_day) 00079 : year(the_year), month(int(the_month)), day(int(the_day)), 00080 hour(0), min(0), sec(0) {} 00081 00083 PDateTime(short the_year, unsigned char the_month, unsigned char the_day, 00084 unsigned char the_hour, unsigned char the_min, 00085 unsigned char the_sec) 00086 : year(the_year), month(the_month), day(the_day), 00087 hour(the_hour), min(the_min), sec(the_sec) {} 00088 00089 PDateTime(int the_year, int the_month, int the_day, 00090 int the_hour, int the_min, int the_sec) 00091 : year(the_year), month(the_month), day(the_day), 00092 hour(the_hour), min(the_min), sec(the_sec) {} 00093 00097 PDateTime(double julian_day); 00098 00101 PDateTime(string datetime); 00102 00104 bool isMissing() const; 00105 void setMissing(); 00106 00108 string info() const; 00109 00111 bool operator==(const PDateTime& rhs) const { 00112 return year == rhs.year && month == rhs.month && day == rhs.day 00113 && hour == rhs.hour && min == rhs.min && sec == rhs.sec; 00114 } 00115 00116 bool operator!=(const PDateTime& rhs) const { 00117 return ! (*this == rhs); 00118 } 00119 00120 bool operator<(const PDateTime& rhs) const { 00121 double datetime_to_double(const PDateTime& t); // declare the function 00122 return datetime_to_double(*this) < datetime_to_double(rhs); 00123 } 00124 00125 bool operator<=(const PDateTime& rhs) const { 00126 return *this == rhs || *this < rhs; 00127 } 00128 00129 bool operator>(const PDateTime& rhs) const { 00130 return ! (*this <= rhs); 00131 } 00132 00133 bool operator>=(const PDateTime& rhs) const { 00134 return ! (*this < rhs); 00135 } 00136 00141 double toJulianDay() const; 00142 }; 00143 00145 inline double operator-(const PDateTime& to_date, const PDateTime& from_date) 00146 { 00147 return to_date.toJulianDay() - from_date.toJulianDay(); 00148 } 00149 00150 inline ostream& operator<<(ostream& os, const PDateTime& date) 00151 { 00152 os << date.info(); 00153 return os; 00154 } 00155 00160 double datetime_to_double(const PDateTime& t); 00161 PDateTime double_to_datetime(double f); 00162 00164 double hhmmss_to_double(int hh, int mm, int ss); 00165 00167 void double_to_hhmmss(double fraction, int& hh, int& mm, int& ss); 00168 00169 } // end of namespace PLearn 00170 00171 #endif

Generated on Tue Aug 17 16:01:03 2004 for PLearn by doxygen 1.3.7