diff --git a/libstuff/STime.cpp b/libstuff/STime.cpp index f88a4edef..224ae6846 100644 --- a/libstuff/STime.cpp +++ b/libstuff/STime.cpp @@ -1,5 +1,6 @@ #include "libstuff.h" +#include #include uint64_t STimeNow() { @@ -19,6 +20,13 @@ string SComposeTime(const string& format, uint64_t when) { return string(buf, length); } +uint64_t STimestampToEpoch(const string& format, const string& timestamp) { + struct tm time; + memset(&time, 0, sizeof(struct tm)); + strptime(timestamp.c_str(), format.c_str(), &time); + return mktime(&time); +} + int SDaysInMonth(int year, int month) { // 30 days hath September... if (month == 4 || month == 6 || month == 9 || month == 11) { diff --git a/libstuff/libstuff.h b/libstuff/libstuff.h index 5a3cd5af2..ad32c2a03 100644 --- a/libstuff/libstuff.h +++ b/libstuff/libstuff.h @@ -161,6 +161,7 @@ uint64_t STimeNow(); uint64_t STimeThisMorning(); // Timestamp for this morning at midnight GMT int SDaysInMonth(int year, int month); string SComposeTime(const string& format, uint64_t when); +uint64_t STimestampToEpoch(const string& format, const string& timestamp); timeval SToTimeval(uint64_t when); string SFirstOfMonth(const string& timeStamp, const int64_t& offset = 0);