PDateTime.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00042
#ifndef PDateTime_INC
00043
#define PDateTime_INC
00044
00045
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);
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 }
00170
00171
#endif
Generated on Tue Aug 17 16:01:03 2004 for PLearn by
1.3.7