37static char rcsid[] not_used =
"$Id$";
46#include <libdap/Error.h>
47#include "DODS_Decimal_Year.h"
49#include <libdap/debug.h>
51#define seconds_per_day 86400.0
52#define seconds_per_hour 3600.0
53#define seconds_per_minute 60.0
56extract_argument(BaseType *arg)
59 if (arg->type() != dods_str_c)
60 throw Error(malformed_expr,
61 "The Projection function requires a DODS string-type argument.");
66 arg->buf2val((
void **)&sp);
67 string s = sp->c_str();
70 DBG(cerr <<
"s: " << s << endl);
107 set(y, m, d, hh, mm, ss,
gmt);
113 set(y, yd, hh, mm, ss,
gmt);
137 double d_year_day, d_hr_day, d_min_day, d_sec_day;
138 int i_year, i_year_day, i_hr_day, i_min_day, i_sec_day;
142 double d_year = strtod(dec_year.c_str(), 0);
145 double year_fraction = d_year - i_year;
153 d_year_day = (secs_in_year * year_fraction)/seconds_per_day + 1;
154 i_year_day = d_year_day * 1;
159 d_hr_day = ((d_year_day - i_year_day)*seconds_per_day) / seconds_per_hour;
160 i_hr_day = d_hr_day * 1;
165 d_min_day = ((d_hr_day - i_hr_day)*seconds_per_hour) / seconds_per_minute;
166 i_min_day = d_min_day * 1;
171 d_sec_day = (d_min_day - i_min_day)*seconds_per_minute;
172 i_sec_day = d_sec_day * 1;
178 if ((d_sec_day - i_sec_day) >= .5) i_sec_day++;
180 if ( i_sec_day == 60 ) {
183 if ( i_min_day == 60 ) {
186 if ( i_hr_day == 24 ) {
197 _date.set((
int)i_year, (
int)i_year_day);
198 _time.set((
int)i_hr_day, (
int)i_min_day, (
double)i_sec_day);
206 set(extract_argument(date_time));
213 _time.set(hh, mm, ss,
gmt);
222 _time.set(hh, mm, ss,
gmt);
236 int yr = _date.year();
238 if ( (yr % 4 == 0) && ((yr % 100 != 0) || (yr % 400 == 0)) )
return 366;
246 double day_number, hrs, min, sec, days_in;
248 day_number = (double)_date.day_number();
249 hrs = (double)_time.hours();
250 min = (double)_time.minutes();
251 sec = (double)_time.seconds();
254 decimal_day = (day_number-1+((hrs+((min+(sec/60.0))/60.0))/24.0))/days_in;
271 double decday = (double)_date.year() +
fraction();
281 return _date.julian_day() + _time.seconds_since_midnight()/seconds_per_day;
288 tm_rec.tm_mday = _date.day();
289 tm_rec.tm_mon = _date.month() - 1;
290 tm_rec.tm_year = _date.year() - 1900;
291 tm_rec.tm_hour = _time.hours();
292 tm_rec.tm_min = _time.minutes();
293 tm_rec.tm_sec = (
int)_time.seconds();
294 tm_rec.tm_isdst = -1;
296 return mktime(&tm_rec);
302 return _time.get_epsilon();
308 _time.set_epsilon(eps);
314 return t1._date == t2._date && t1._time == t2._time;
320 return t1._date != t2._date || t1._time != t2._time;
326 return t1._date < t2._date
327 || (t1._date == t2._date && t1._time < t2._time);
333 return t1._date > t2._date
334 || (t1._date == t2._date && t1._time > t2._time);
340 return t1 == t2 || t1 < t2;
346 return t1 == t2 || t1 > t2;
349#ifdef DECIMAL_YEAR_TEST
362main(
int argc,
char *argv[])
377 dt.
set(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]),
378 atoi(argv[4]), atof(argv[5]));
381 dt.
set(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]),
382 atoi(argv[4]), atoi(argv[5]), atof(argv[6]));
385 cerr <<
"Wrong number of arguments!" << endl;
390 cout <<
"True: dt < dt2" << endl;
392 cout <<
"False: dt < dt2" << endl;
395 cout <<
"True: dt > dt2" << endl;
397 cout <<
"False: dt > dt2" << endl;
400 cout <<
"True: dt <= dt2" << endl;
402 cout <<
"False: dt <= dt2" << endl;
405 cout <<
"True: dt >= dt2" << endl;
407 cout <<
"False: dt >= dt2" << endl;
410 cout <<
"True: dt == dt2" << endl;
412 cout <<
"False: dt == dt2" << endl;
415 cout <<
"True: dt != dt2" << endl;
417 cout <<
"False: dt != dt2" << endl;
421 cout <<
"Julian day: " << dt.
julian_day() << endl;
422 cout <<
"Seconds: " << dt.
unix_time() << endl;
friend int operator==(DODS_Decimal_Year &t1, DODS_Decimal_Year &t2)
Equality.
friend int operator<=(DODS_Decimal_Year &t1, DODS_Decimal_Year &t2)
Less-than or Equal-to.
friend int operator!=(DODS_Decimal_Year &t1, DODS_Decimal_Year &t2)
Inequality.
string get(date_format format=ymd, bool gmt=true) const
friend int operator>=(DODS_Decimal_Year &t1, DODS_Decimal_Year &t2)
Greater-than or Equal-to.
double get_epsilon() const
friend int operator<(DODS_Decimal_Year &t1, DODS_Decimal_Year &t2)
Less-than.
friend int operator>(DODS_Decimal_Year &t1, DODS_Decimal_Year &t2)
Greater-than.
void set_epsilon(double eps)
double julian_day() const