Skip to content

Commit 0c83439

Browse files
committed
remove strptime
1 parent b13c2eb commit 0c83439

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/netlicensing.cc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,19 @@ namespace netlicensing {
174174
Json::Reader reader;
175175
bool parsingSuccessful = reader.parse(res.c_str(), root);
176176
if (parsingSuccessful) {
177-
Json::FastWriter fastWriter;
178-
std::string ttl = fastWriter.write(root["ttl"]);
179-
const char *time_details = ttl.c_str();
180-
181-
struct tm tm;
182-
strptime(time_details, "%Y-%m-%d %H:%M:%S", &tm);
183-
time_t rawtime = mktime(&tm);
184-
177+
Json::FastWriter fastWriter;
178+
//ttl returns with new line character ("\n") is appended at the end of the string and "\" at the begin of string.
179+
std::string ttl = fastWriter.write(root["ttl"]);
180+
181+
struct tm tm = {0};
182+
tm.tm_year = atoi(ttl.substr(1,4).c_str()) - 1900; /* years since 1900 */
183+
tm.tm_mon = atoi(ttl.substr(6, 2).c_str()) - 1;
184+
tm.tm_mday = atoi(ttl.substr(9, 2).c_str());
185+
tm.tm_hour = atoi(ttl.substr(12, 2).c_str());
186+
tm.tm_min = atoi(ttl.substr(15, 2).c_str());
187+
tm.tm_sec = atoi(ttl.substr(18, 2).c_str());
188+
189+
time_t rawtime = mktime(&tm);
185190
validationResult.setTtl(rawtime);
186191
}
187192

0 commit comments

Comments
 (0)