2 #include <boost/format.hpp>
3 #include <utl/AugerException.h>
4 #include <utl/ErrorLogger.h>
5 #include <utl/UTCDate.h>
12 const char*
const UTCDate::fgMonthNames[] = {
13 "JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
14 "JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC"
19 UTCDate::Set(
const int year,
const int month,
const int day)
21 if (year < 1980 || (year == 1980 && month == 1 && day < 6)) {
22 const char*
const err =
"Date before GPS epoch";
26 if (month < 1 || month > 12) {
28 err <<
"month " << month <<
" not in range 1-12";
32 if (day < 1 || day > NumberOfDaysInMonth(year, month)) {
34 err <<
"day " << day <<
" not in range 1-"
35 << NumberOfDaysInMonth(year, month);
46 UTCDate::GetUnixSecond(
const int year,
const int month,
const int day,
61 const time_t t1 = mktime(&breakdown);
62 const time_t dgm = mktime(gmtime(&t1));
65 return t1 - (dgm - t1);
70 UTCDate::GetInAugerFormat()
74 (format(
"%|1$02| %2% %|3$4|")
76 % fgMonthNames[fMonth - eJan]
83 UTCDate::GetInXMLFormatZone(
const char*
const zone)
87 (format(
"%1%-%|2$02|-%|3$02|%4%")
97 UTCDate::Parse(istream&
is,
const bool zone)
105 if ((is >> year >> minus >> month >> minus2 >> day) &&
106 minus ==
'-' && minus2 ==
'-' &&
107 (!zone || is.eof() || ((is >> tz) && tz ==
'Z'))) {
108 Set(year, month, day);
112 err <<
"Initializing UTCDate variable failed:"
113 " year=" << year <<
" month=" << month <<
" day=" << day
114 <<
" minus=" << minus <<
" minus2=" << minus2 <<
" tz=" << tz;
bool is(const double a, const double b)
Exception for reporting variable out of valid range.
#define ERROR(message)
Macro for logging error messages.