ECE 4180 Project for Spring 2020
Dependencies: mbed mbed-rtos SDFileSystem PinDetect ESP8266NodeMCUInterface
HistoryCache.h
- Committer:
- kimberlylie99
- Date:
- 2020-05-01
- Revision:
- 1:5ae291085f75
- Parent:
- 0:b97c07227845
File content as of revision 1:5ae291085f75:
#include <iostream>
#include <string>
#include <cstring>
#include <ctime>
class HistoryCache
{
public:
static char *strptime(const char * __restrict, const char * __restrict, struct tm * __restrict);
static std::string getTimeStamp(time_t epochTime, const char* format = "%Y-%m-%d %H:%M:%S")
{
char timestamp[64] = {0};
strftime(timestamp, sizeof(timestamp), format, localtime(&epochTime));
return timestamp;
}
static time_t convertTimeToEpoch(const char* theTime, const char* format = "%Y-%m-%d %H:%M:%S")
{
std::tm tmTime;
memset(&tmTime, 0, sizeof(tmTime));
HistoryCache::strptime(theTime, format, &tmTime);
return mktime(&tmTime);
}
};