MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / set

Method set

src/openms/source/DATASTRUCTURES/DateTime.cpp:94–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92 }
93
94 void DateTime::set(const String& date)
95 {
96 clear();
97
98 if (date.has('.') && !date.has('T'))
99 {
100 *dt_ = (QDateTime::fromString(date.c_str(), "dd.MM.yyyy hh:mm:ss"));
101 }
102 else if (date.has('/'))
103 {
104 *dt_ = (QDateTime::fromString(date.c_str(), "MM/dd/yyyy hh:mm:ss"));
105 }
106 else if (date.has('-'))
107 {
108 if (date.has('T'))
109 {
110 if (date.has('+'))
111 {
112 // remove timezone part, since Qt cannot handle this, check if we also have a millisecond part
113 if (date.has('.'))
114 {
115 *dt_ = (QDateTime::fromString(date.prefix('+').c_str(), "yyyy-MM-ddThh:mm:ss.zzz"));
116 }
117 else
118 {
119 *dt_ = (QDateTime::fromString(date.prefix('+').c_str(), "yyyy-MM-ddThh:mm:ss"));
120 }
121 }
122 else
123 {
124 *dt_ = (QDateTime::fromString(date.c_str(), "yyyy-MM-ddThh:mm:ss"));
125 }
126 }
127 else if (date.has('Z'))
128 {
129 *dt_ = (QDateTime::fromString(date.c_str(), "yyyy-MM-ddZ"));
130 }
131 else if (date.has('+'))
132 {
133 *dt_ = (QDateTime::fromString(date.c_str(), "yyyy-MM-dd+hh:mm"));
134 }
135 else
136 {
137 *dt_ = (QDateTime::fromString(date.c_str(), "yyyy-MM-dd hh:mm:ss"));
138 }
139 }
140
141 if (!dt_->isValid())
142 {
143 *dt_ = QDateTime::fromString(date.c_str()); // ddd MMM d YYYY format as found in (old?) protXML files
144 }
145
146 if (!dt_->isValid())
147 {
148 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, date, "Invalid date time string");
149 }
150 }
151

Callers

nothing calls this directly

Calls 7

prefixMethod · 0.80
setDateMethod · 0.80
setTimeMethod · 0.80
clearFunction · 0.50
StringClass · 0.50
hasMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected