36static char rcsid[] not_used =
"$Id$";
42#include <libdap/BaseType.h>
44#include <libdap/debug.h>
45#include <libdap/Error.h>
49double DODS_Time::_eps = 1.0e-6;
51static string time_syntax_string = \
52"Invalid time: times must be given as hh:mm or hh:mm:ss with an optional\n\
53suffix of GMT or UTC. In addition, 0 <= hh <=23, 0 <= mm <= 59 and\n\
57compute_ssm(
int hh,
int mm,
double ss)
59 return ((hh * 60 + mm) * 60) + ss;
63extract_argument(BaseType *arg)
66 if (arg->type() != dods_str_c)
67 throw Error(malformed_expr,
"A DODS string argument is required.");
72 arg->buf2val((
void **)&sp);
73 string s = sp->c_str();
76 DBG(cerr <<
"s: " << s << endl);
90 && _seconds >= 0.0 && _seconds < 60.0;
96 return ((_hours + ((_minutes + (_seconds / 60.0)) / 60.0)) / 24.0);
105 _sec_since_midnight(-1), _gmt(false)
116 set(extract_argument(arg));
120 _hours(hh), _minutes(mm), _seconds(0), _gmt(
gmt)
122 _sec_since_midnight = compute_ssm(hh, mm, 0);
125 throw Error(malformed_expr, time_syntax_string);
130 _hours(hh), _minutes(mm), _seconds(ss), _gmt(
gmt)
132 _sec_since_midnight = compute_ssm(hh, mm, ss);
135 throw Error(malformed_expr, time_syntax_string);
143 istringstream iss(time.c_str());
148 pos1 = time.find(
":");
150 if (pos1 != time.npos) {
155 pos2 = time.rfind(
":");
156 if ((pos2 != time.npos) && (pos1 != pos2)) {
167 _sec_since_midnight = compute_ssm(_hours, _minutes, _seconds);
171 if (
gmt ==
"GMT" ||
gmt ==
"gmt" ||
gmt ==
"UTC"
179 throw Error(malformed_expr, time_syntax_string);
186 set(extract_argument(arg));
202 _sec_since_midnight = compute_ssm(hh, mm, ss);
206 throw Error(malformed_expr, time_syntax_string);
248 return t1 > t2 || t1 == t2;
260 return t1 < t2 || t1 == t2;
266 return _sec_since_midnight;
300 oss << setfill(
'0') << setw(2) << _hours <<
":"
301 << setfill(
'0') << setw(2) << _minutes <<
":"
302 << setfill(
'0') << setw(2) << setprecision(6) << _seconds;
friend int operator<(DODS_Time &t1, DODS_Time &t2)
Less-than.
double seconds_since_midnight() const
string get(bool gmt=true) const
friend int operator!=(DODS_Time &t1, DODS_Time &t2)
Inequality.
friend int operator>(DODS_Time &t1, DODS_Time &t2)
Greater-than.
void set_epsilon(double eps)
friend int operator<=(DODS_Time &t1, DODS_Time &t2)
Less-than or Equal-to.
friend int operator==(DODS_Time &t1, DODS_Time &t2)
Equality.
double get_epsilon() const
friend int operator>=(DODS_Time &t1, DODS_Time &t2)
Greater-than or Equal-to.