1 #ifndef __JSYSTEM__JDATEANDTIME__
2 #define __JSYSTEM__JDATEANDTIME__
22 namespace JPP {
using namespace JSYSTEM; }
39 static const size_t MAX_SIZE = 256;
40 static char buffer[MAX_SIZE];
44 strftime(buffer, MAX_SIZE,
"%F", localtime(&ts));
58 static const size_t MAX_SIZE = 256;
59 static char buffer[MAX_SIZE];
63 strftime(buffer, MAX_SIZE,
"%T%z", localtime(&ts));
124 std::istringstream
is(buffer);
168 int getHour()
const {
return get()->tm_hour; }
169 int getDay()
const {
return get()->tm_mday; }
171 int getYear()
const {
return get()->tm_year + 1900; }
172 int getDST()
const {
return get()->tm_isdst; }
182 operator std::string()
const
204 catch(
const std::exception& error) {
219 static const size_t MAX_SIZE = 256;
220 static char buffer[MAX_SIZE];
222 const size_t pos = strftime(buffer, MAX_SIZE, (
isUTC() ?
"%FT%TZ" :
"%FT%T%z"), this->
get());
224 return string(buffer, pos);
262 void set(
const time_t t1,
const bool utc =
false)
276 void set(
const time_t t1,
const float f1,
const bool utc =
false)
314 return difftime(
object.
ts, this->ts) + (
object.fs - this->
fs);
329 const size_t LENGTH = 10;
333 for (
int c; (
c = in.peek()) != EOF && isspace((
char) in.peek()); ) {
337 for (
int c; (
c = in.get()) != EOF && (
c !=
' ' || buffer.length() == LENGTH); ) {
338 buffer.push_back((
char)
c);
347 size_t pos = string::npos;
349 if (pos == string::npos) { pos = buffer.find(
'Z', LENGTH); }
350 if (pos == string::npos) { pos = buffer.find(
'+', LENGTH); }
351 if (pos == string::npos) { pos = buffer.find(
'-', LENGTH); }
357 const string td = buffer.substr(0, pos);
358 const char* pd = NULL;
360 switch (td.length()) {
371 pd = strptime(td.c_str(),
"%Y-%m-%d %H:%M:%S", &tx); sscanf(pd,
"%f%n", &
object.
fs, &nd); pd += nd;
375 pd = strptime(td.c_str(),
"%Y-%m-%dT%H:%M:%S", &tx);
379 pd = strptime(td.c_str(),
"%Y%m%dT%H%M%s", &tx);
383 pd = strptime(td.c_str(),
"%Y-%m-%d", &tx);
387 if (pd == NULL || *pd !=
'\0') {
396 if (pos != string::npos && (buffer[pos] ==
'+' ||
397 buffer[pos] ==
'-')) {
399 const string tz = buffer.substr(pos + 1);
400 const char* pz = tz.c_str();
402 switch (tz.length()) {
405 pz = strptime(tz.c_str(),
"%H", &ty);
409 pz = strptime(tz.c_str(),
"%H%M", &ty);
413 pz = strptime(tz.c_str(),
"%H:%M", &ty);
417 if (pz == NULL || *pz !=
'\0') {
424 time_t t1 = mktime(&tx);
426 t1 -= (ty.tm_hour * 60 + ty.tm_min) * 60;
427 t1 += mktime(localtime(&t1)) - mktime(gmtime(&t1));
429 object.set(t1, buffer[pos] ==
'Z');
444 return out <<
object.toString();
455 return (this->
tp = (
utc ? gmtime(&
ts) : localtime(&
ts)));
void set(const time_t t1, const bool utc=false)
Set to given time.
const JDateAndTime & operator()()
Set date and time.
float getFS() const
fraction of second
const tm * operator->() const
Smart pointer.
time_t getTime() const
time
friend std::ostream & operator<<(std::ostream &out, const JDateAndTime &object)
Write date and time to output stream.
std::string toString() const
Get ASCII formatted date and time.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
JDateAndTime(const time_t t1, const bool utc=false)
Constructor.
void set(const bool utc=false)
Set to current local time.
int getSeconds() const
seconds after the minute [0-59]
double getTime(const Hit &hit)
Get true time of hit.
void sub(const time_t t1)
Subtract given time.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
static JDateAndTime getDateAndTime
Function object to get current date and time.
bool isUTC() const
Check if UTC time.
friend std::istream & operator>>(std::istream &in, JDateAndTime &object)
Read date and time from input stream.
static bool isISO8601(const std::string &buffer)
Function to check ISO-8601 conformity.
JDateAndTime(const time_t t1, const float f1, const bool utc=false)
Constructor.
JDateAndTime(const std::string &buffer)
Constructor.
int getMonth() const
month of the year [1-12]
void add(const time_t t1)
Add given time.
int getDay() const
day of the month [1-31]
Template definition of auxiliary base class for comparison of data structures.
double getElapsedTime(const JDateAndTime &object) const
Get elapsed time to given date and time.
const char * getDate()
Get current local date conform ISO-8601 standard.
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
JDateAndTime(const bool utc=false)
Constructor.
bool less(const JDateAndTime &object) const
Less than method.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Auxiliary class for date and time.
Exception for parsing value.
int getHour() const
hours after midnight [0-23]
int getMinutes() const
minutes after the hour [0-59]
void set(const time_t t1, const float f1, const bool utc=false)
Set to given time.
float fs
fraction of second
int getDST() const
daylight saving time
int getYear() const
year a.d.