Kimberly Lie / Mbed 2 deprecated ECE4180_MasterCode

Dependencies:   mbed mbed-rtos SDFileSystem PinDetect ESP8266NodeMCUInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HistoryCache.h Source File

HistoryCache.h

00001 #include <iostream>
00002 #include <string>
00003 #include <cstring>
00004 #include <ctime>
00005 
00006 class HistoryCache
00007 {
00008 
00009 public:
00010     static char *strptime(const char * __restrict, const char * __restrict, struct tm * __restrict);
00011    
00012    static std::string getTimeStamp(time_t epochTime, const char* format = "%Y-%m-%d %H:%M:%S")
00013    {
00014       char timestamp[64] = {0};
00015       strftime(timestamp, sizeof(timestamp), format, localtime(&epochTime));
00016       return timestamp;
00017    }
00018 
00019    static time_t convertTimeToEpoch(const char* theTime, const char* format = "%Y-%m-%d %H:%M:%S")
00020    {
00021       std::tm tmTime;
00022       memset(&tmTime, 0, sizeof(tmTime));
00023       HistoryCache::strptime(theTime, format, &tmTime);
00024       return mktime(&tmTime);
00025    }
00026 };