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]

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 74 of file oks_utils.hpp.

Constructor & Destructor Documentation

◆ Date()

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

Definition at line 78 of file oks_utils.hpp.

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

◆ ~Date()

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

Definition at line 80 of file oks_utils.hpp.

80{ ; }

Member Function Documentation

◆ day()

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

Definition at line 86 of file oks_utils.hpp.

86{return p_tm.tm_mday;}

◆ month()

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

Definition at line 85 of file oks_utils.hpp.

85{return p_tm.tm_mon;}

◆ set()

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

Definition at line 27 of file time.cpp.

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

◆ str()

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

Reimplemented in dunedaq::oks::Time.

Definition at line 141 of file time.cpp.

142{
143 std::ostringstream s;
144
145 s << p_tm.tm_mday << '/' << (p_tm.tm_mon + 1) << '/' << std::setfill('0') << std::setw(2)
146 << ((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)));
147
148 return s.str();
149}

◆ year()

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

Definition at line 84 of file oks_utils.hpp.

84{return p_tm.tm_year;}

Member Data Documentation

◆ p_tm

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

Definition at line 93 of file oks_utils.hpp.


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