36 static char rcsid[]
not_used =
"$Id$";
49 double DODS_Time::_eps = 1.0e-6;
51 static string time_syntax_string = \
52 "Invalid time: times must be given as hh:mm or hh:mm:ss with an optional\n\
53 suffix of GMT or UTC. In addition, 0 <= hh <=23, 0 <= mm <= 59 and\n\
54 0 <= ss <= 59.999999";
57 compute_ssm(
int hh,
int mm,
double ss)
59 return ((hh * 60 + mm) * 60) + ss;
63 extract_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;
string get(bool gmt=true) const
Get the string representation of time.
int operator>=(DODS_Time &t1, DODS_Time &t2)
int operator==(DODS_Time &t1, DODS_Time &t2)
double seconds_since_midnight() const
Get the number of seconds since midnight.
int operator!=(DODS_Time &t1, DODS_Time &t2)
int operator<=(DODS_Time &t1, DODS_Time &t2)
double get_epsilon() const
Get the value of epsilon used for equality tests.
double fraction() const
Get the time as a fraction of a day.
int operator>(DODS_Time &t1, DODS_Time &t2)
int operator<(DODS_Time &t1, DODS_Time &t2)
DODS_Time()
Build an empty DODS_Time.
void set(string time)
Set the value by parsing the string #time#.
void set_epsilon(double eps)
Set the value of epsilon used for equality tests.
bool OK() const
Class invariant.