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

Constructor & Destructor Documentation

◆ Date()

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

Definition at line 86 of file oks_utils.hpp.

86{ set(s); } // dd/mm/[yy]yy
void set(const char *)
Definition time.cpp:27

◆ ~Date()

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

Definition at line 88 of file oks_utils.hpp.

88{ ; }

Member Function Documentation

◆ day()

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

Definition at line 94 of file oks_utils.hpp.

94{ return p_tm.tm_mday; }

◆ month()

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

Definition at line 93 of file oks_utils.hpp.

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

◆ str()

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

Reimplemented in dunedaq::oks::Time.

Definition at line 137 of file time.cpp.

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

◆ year()

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

Definition at line 92 of file oks_utils.hpp.

92{ return p_tm.tm_year; }

Member Data Documentation

◆ p_tm

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

Definition at line 99 of file oks_utils.hpp.


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