4#include "facilities/Timestamp.h"
11 const double Timestamp::julian1970 = 2440587.5;
12 const int Timestamp::secPerDay = ( 24 * 60 * 60 );
13 const double Timestamp::inverseNano = 1000 * 1000 * 1000;
14 const int Timestamp::inverseNanoInt = 1000 * 1000 * 1000;
15 const long int Timestamp::maxInt = 0x7fffffff;
17 Timestamp::TZOffset Timestamp::s_tz;
29 if ( ( nano >= inverseNanoInt ) || ( nano < 0 ) || ( seconds < 0 ) )
30 throw BadTimeInput(
"facilities::Timestamp bad nano argument" );
37 secs = ( julian - julian1970 ) * secPerDay;
39 if ( ( fabs( secs ) > maxInt ) || ( secs < 0 ) )
40 throw BadTimeInput(
"Julian time not in range [1970, 2037]" );
65 if ( ( month < 1 ) || ( month > 12 ) || ( day < 1 ) || ( day > 31 ) || ( hour < 0 ) ||
66 ( hour > 23 ) || ( minute < 0 ) || ( minute > 59 ) || ( second < 0 ) ||
67 ( second >= 60 ) || ( year < 1970 ) || ( year > 2037 ) || ( nano < 0 ) ||
68 ( nano >= inverseNanoInt ) )
69 throw BadTimeInput(
"facilities::Timestamp Bad subfield" );
71 fields.tm_year = year - 1900;
72 fields.tm_mon = month - 1;
74 fields.tm_hour = hour;
75 fields.tm_min = minute;
76 fields.tm_sec = (
long int)second;
84 m_time = mktime( &fields ) - Timestamp::s_tz.m_tzseconds;
95 double julian = (
m_time +
m_nano / inverseNano ) / secPerDay;
100 time_t Timestamp::toBinary(
const std::string& strTime ) {
105 unsigned int oldPos = 0;
111 pos = strTime.find( delim, oldPos );
114 if ( pos >= strTime.size() )
return 0;
116 fields.tm_year = atoi( ( strTime.substr( oldPos, pos ) ).c_str() ) - 1900;
117 if ( ( fields.tm_year < 70 ) || ( fields.tm_year > 137 ) )
120 pos = strTime.find( delim, oldPos );
123 if ( pos >= strTime.size() )
124 throw BadTimeInput(
"Bad string format for facilities::Timestamp" );
126 fields.tm_mon = atoi( ( strTime.substr( oldPos, pos ) ).c_str() ) - 1;
127 if ( ( fields.tm_mon < 0 ) || ( fields.tm_mon > 11 ) )
128 throw BadTimeInput(
"facilities::Timestamp bad month" );
135 pos = strTime.find( delim, oldPos );
137 fields.tm_mday = atoi( ( strTime.substr( oldPos, pos ) ).c_str() );
139 if ( ( fields.tm_mday < 1 ) || ( fields.tm_mday > 31 ) )
140 throw BadTimeInput(
"facilities::Timestamp bad day of month" );
143 fields.tm_hour = fields.tm_min = fields.tm_sec = 0;
145 if ( pos < strTime.size() )
150 pos = strTime.find( delim, oldPos );
152 fields.tm_hour = atoi( ( strTime.substr( oldPos, pos ) ).c_str() );
153 if ( ( fields.tm_hour > 23 ) || ( fields.tm_hour < 0 ) )
156 if ( pos < strTime.size() )
159 pos = strTime.find( delim, oldPos );
160 fields.tm_min = atoi( ( strTime.substr( oldPos, pos ) ).c_str() );
161 if ( ( fields.tm_min > 59 ) || ( fields.tm_hour < 0 ) )
162 throw BadTimeInput(
"facilities::Timestamp bad minutes" );
164 if ( pos < strTime.size() )
167 pos = strTime.find( delim, oldPos );
168 fields.tm_sec = atoi( ( strTime.substr( oldPos, pos ) ).c_str() );
169 if ( ( fields.tm_sec > 59 ) || ( fields.tm_hour < 0 ) )
170 throw BadTimeInput(
"facilities::Timestamp bad seconds" );
178 return mktime( &fields ) - Timestamp::s_tz.m_tzseconds;
181 void Timestamp::toString( time_t
bin, std::string& strTime ) {
182 struct tm* fields = gmtime( &
bin );
187 char* bufPtr = &buf[0];
188 sprintf( buf,
"%i", fields->tm_year + 1900 );
191 sprintf( buf,
"%02i", fields->tm_mon + 1 );
194 sprintf( buf,
"%02i", fields->tm_mday );
197 sprintf( buf,
"%02i", fields->tm_hour );
200 sprintf( buf,
"%02i", fields->tm_min );
203 sprintf( buf,
"%02i", fields->tm_sec );
207 Timestamp::TZOffset::TZOffset() {
219 m_tzseconds = mktime( &fields ) - 12 * 60 * 60;
220 m_isDst = fields.tm_isdst;
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
string toString(const T &t)
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
std::string getString() const
Return string representation of time, not including nanoseconds;.
double getJulian() const
Return julian date.
int m_nano
Save fractional seconds separately (associated with m_time).
time_t m_time
internal binary rep of time; count seconds from Jan 1, 1970