ESP8266_swiss_army_board/src/app/RtcManager.cpp

38 lines
908 B
C++

#include "RtcManager.h"
RtcManager::RtcManager()
{
}
DateTime RtcManager::getDateTime() const
{
return DateTime(time(nullptr));
}
void RtcManager::setDate(const DateTime dateTime)
{
DateTime timePart = getDateTime();
DateTime toSet(dateTime.year(), dateTime.month(), dateTime.day(), timePart.hour(), timePart.minute(), timePart.second());
timeval tv = {.tv_sec = toSet.unixtime(), .tv_usec = 0};
settimeofday(&tv, nullptr);
}
void RtcManager::setTime(const DateTime dateTime)
{
DateTime datePart = getDateTime();
DateTime toSet(datePart.year(), datePart.month(), datePart.day(), dateTime.hour(), dateTime.minute(), dateTime.second());
timeval tv = {.tv_sec = toSet.unixtime(), .tv_usec = 0};
settimeofday(&tv, nullptr);
}
void RtcManager::setDateTime(const DateTime dateTime)
{
timeval tv = {.tv_sec = dateTime.unixtime(), .tv_usec = 0};
settimeofday(&tv, nullptr);
}