Skip to content

Commit

Permalink
add STimestampToEpoch
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperhuangg committed Jul 12, 2024
1 parent a830615 commit c143b05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libstuff/STime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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) {
Expand Down
1 change: 1 addition & 0 deletions libstuff/libstuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit c143b05

Please sign in to comment.