Fixed time format conversion to be static
This commit is contained in:
@@ -164,7 +164,7 @@ namespace drivers
|
|||||||
return datetime2str(dt);
|
return datetime2str(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
PCF85063::datetime_t PCF85063::fromEpoch(time_t currentTime)
|
const PCF85063::datetime_t PCF85063::fromEpoch(const time_t currentTime)
|
||||||
{
|
{
|
||||||
PCF85063::datetime_t tm;
|
PCF85063::datetime_t tm;
|
||||||
struct tm *localTime = std::localtime(¤tTime);
|
struct tm *localTime = std::localtime(¤tTime);
|
||||||
@@ -178,7 +178,7 @@ namespace drivers
|
|||||||
return tm;
|
return tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string PCF85063::datetime2str(datetime_t &datetime)
|
const std::string PCF85063::datetime2str(const datetime_t &datetime)
|
||||||
{
|
{
|
||||||
tm dtime;
|
tm dtime;
|
||||||
dtime.tm_sec = datetime.second;
|
dtime.tm_sec = datetime.second;
|
||||||
@@ -188,7 +188,8 @@ namespace drivers
|
|||||||
dtime.tm_mday = datetime.day;
|
dtime.tm_mday = datetime.day;
|
||||||
dtime.tm_mon = datetime.month - 1;
|
dtime.tm_mon = datetime.month - 1;
|
||||||
dtime.tm_year = datetime.year - 1900; // time offset in structure according cpp reference
|
dtime.tm_year = datetime.year - 1900; // time offset in structure according cpp reference
|
||||||
return std::string(std::asctime(&dtime));
|
const std::string buf(std::asctime(&dtime));
|
||||||
|
return buf.substr(0, std::min(buf.find('\n'),buf.find('\r')));
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t PCF85063::decToBcd(const int val)
|
const uint8_t PCF85063::decToBcd(const int val)
|
||||||
|
|||||||
@@ -133,10 +133,10 @@ namespace drivers
|
|||||||
const bool readAlarm(datetime_t &time);
|
const bool readAlarm(datetime_t &time);
|
||||||
const bool getAlarmFlag(uint8_t &flags);
|
const bool getAlarmFlag(uint8_t &flags);
|
||||||
|
|
||||||
const std::string datetime2str(datetime_t &datetime);
|
|
||||||
const std::string getTimeStr();
|
const std::string getTimeStr();
|
||||||
|
|
||||||
static PCF85063::datetime_t fromEpoch(time_t currentTime);
|
static const std::string datetime2str(const datetime_t &datetime);
|
||||||
|
static const PCF85063::datetime_t fromEpoch(const time_t currentTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint8_t decToBcd(const int val);
|
const uint8_t decToBcd(const int val);
|
||||||
|
|||||||
Reference in New Issue
Block a user