DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::Date Class Reference

#include <oks_utils.hpp>

Inheritance diagram for dunedaq::oks::Date:
[legend]
Collaboration diagram for dunedaq::oks::Date:
[legend]

Public Member Functions

 Date (const char *s)
 
virtual ~Date ()
 
void set (const char *)
 
long year () const
 
unsigned short month () const
 
unsigned short day () const
 
virtual std::string str () const
 

Protected Attributes

struct tm p_tm
 

Detailed Description

Definition at line 69 of file oks_utils.hpp.

Constructor & Destructor Documentation

◆ Date()

dunedaq::oks::Date::Date ( const char * s)
inline

Definition at line 73 of file oks_utils.hpp.

73{set(s);} // dd/mm/[yy]yy
Monitoring thread not set

◆ ~Date()

virtual dunedaq::oks::Date::~Date ( )
inlinevirtual

Definition at line 75 of file oks_utils.hpp.

75{ ; }

Member Function Documentation

◆ day()

unsigned short dunedaq::oks::Date::day ( ) const
inline

Definition at line 81 of file oks_utils.hpp.

81{return p_tm.tm_mday;}

◆ month()

unsigned short dunedaq::oks::Date::month ( ) const
inline

Definition at line 80 of file oks_utils.hpp.

80{return p_tm.tm_mon;}

◆ set()

void dunedaq::oks::Date::set ( const char * s)

Definition at line 22 of file time.cpp.

23{
24 p_tm.tm_sec = p_tm.tm_min = p_tm.tm_hour = p_tm.tm_mday = p_tm.tm_mon = p_tm.tm_year = 0;
25
26 if(s == 0) return;
27
28 // skip leading spaces
29
30 while(*s == ' ') ++s;
31
32
33 const char * s2 = s; // original time used in error reports
34 char * nds = 0; // non-digit symbol returned by strtol
35
36
37 // find the day
38
39 p_tm.tm_mday = strtol(s, &nds, 10);
40
41 if(*nds != '/') {
42 Oks::error_msg("oks::Time::Time()") << "failed to find the day in \'" << s2 << "\'\n";
43 return;
44 }
45 else
46 s = nds + 1;
47
48 if(p_tm.tm_mday > 31 || p_tm.tm_mday == 0) {
49 Oks::error_msg("oks::Time::Time()") << "bad day " << p_tm.tm_mday << " in \'" << s2 << "\'\n";
50 return;
51 }
52
53
54 // find the month
55
56 p_tm.tm_mon = strtol(s, &nds, 10);
57
58 if(*nds != '/') {
59 Oks::error_msg("oks::Time::Time()") << "failed to find the month in \'" << s2 << "\'\n";
60 return;
61 }
62 else
63 s = nds + 1;
64
65 if(p_tm.tm_mon > 12 || p_tm.tm_mon == 0) {
66 Oks::error_msg("oks::Time::Time()") << "bad month " << p_tm.tm_mon << " in \'" << s2 << "\'\n";
67 return;
68 }
69
70 p_tm.tm_mon--;
71
72
73 // find the year
74
75 p_tm.tm_year = strtol(s, &nds, 10);
76
77 if(p_tm.tm_year >= 0) {
78 if(p_tm.tm_year < 70) p_tm.tm_year += 2000;
79 else if(p_tm.tm_year < 100) p_tm.tm_year += 1900;
80 }
81
82 // check if there is no data anymore
83
84 if(*nds == 0) return;
85
86 s = nds;
87
88
89 // skip spaces
90
91 while(*s == ' ') ++s;
92 if(*s == 0) return;
93
94
95 // find the hour
96
97 p_tm.tm_hour = strtol(s, &nds, 10);
98
99 if(*nds != ':') {
100 Oks::error_msg("oks::Time::Time()") << "failed to find the hour in \'" << s2 << "\'\n";
101 return;
102 }
103 else
104 s = nds + 1;
105
106 if(p_tm.tm_hour > 23) {
107 Oks::error_msg("oks::Time::Time()") << "bad hour " << p_tm.tm_hour << " in \'" << s2 << "\'\n";
108 return;
109 }
110
111
112 // find the minute
113
114 p_tm.tm_min = strtol(s, &nds, 10);
115
116 if(p_tm.tm_min > 59) {
117 Oks::error_msg("oks::Time::Time()") << "bad minute " << p_tm.tm_min << " in \'" << s2 << "\'\n";
118 return;
119 }
120
121 if(*nds != ':') return;
122
123
124 // find the second
125
126 p_tm.tm_sec = strtol(nds + 1, &nds, 10);
127
128 if(p_tm.tm_sec > 59) {
129 Oks::error_msg("oks::Time::Time()") << "bad second " << p_tm.tm_sec << " in \'" << s2 << "\'\n";
130 return;
131 }
132}
static std::ostream & error_msg(const char *)
Definition kernel.cpp:556

◆ str()

std::string dunedaq::oks::Date::str ( ) const
virtual

Reimplemented in dunedaq::oks::Time.

Definition at line 136 of file time.cpp.

137{
138 std::ostringstream s;
139
140 s << p_tm.tm_mday << '/' << (p_tm.tm_mon + 1) << '/' << std::setfill('0') << std::setw(2)
141 << ((p_tm.tm_year < 1970 || p_tm.tm_year >= 2070) ? p_tm.tm_year : (p_tm.tm_year < 2000 ? (p_tm.tm_year - 1900) : (p_tm.tm_year - 2000)));
142
143 return s.str();
144}

◆ year()

long dunedaq::oks::Date::year ( ) const
inline

Definition at line 79 of file oks_utils.hpp.

79{return p_tm.tm_year;}

Member Data Documentation

◆ p_tm

struct tm dunedaq::oks::Date::p_tm
protected

Definition at line 88 of file oks_utils.hpp.


The documentation for this class was generated from the following files: