Skip to content

Commit

Permalink
Merge pull request #1810 from Expensify/jasper-addSTimestampToEpoch
Browse files Browse the repository at this point in the history
Add `STimestampToEpoch`
  • Loading branch information
jasperhuangg authored Jul 15, 2024
2 parents a830615 + 2c27945 commit 7aac1e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libstuff/STime.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "libstuff.h"

#include <cstring>
#include <sys/time.h>

uint64_t STimeNow() {
Expand All @@ -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) {
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 7aac1e6

Please sign in to comment.