-
-
Couldn't load subscription status.
- Fork 48
Closed
Description
In loggerBase.cpp the useage of Epoch time is confusing.
I've clarified it by adding T0 for true Epoch Time, and Tz for when corrected for local time.
The following is actually using Tz ...
uint32_t Logger::getNowEpoch(void)
{
uint32_t currentEpochTime = zero_sleep_rtc.getEpoch();
// Do NOT apply an offset if the timestamp is obviously bad
if (isRTCSane(currentEpochTime))
currentEpochTime += ((uint32_t)_loggerRTCOffset) * 3600;
return currentEpochTime;
}I've updated to the following and could do a PR if of interest.
uint32_t Logger::getNowEpoch(void)
{
//Depreciated in 0.23.4, left in for compatiblity
return getNowEpochTz();
}
uint32_t Logger::getNowEpochT0(void)
{
uint32_t currentEpochTime = zero_sleep_rtc.getEpoch();
if (!isRTCSane(currentEpochTime)) {
PRINTOUT(F("Bad time, resetting clock."),currentEpochTime);
setNowEpochT0(currentEpochTime);
currentEpochTime=EPOCH_TIME_20200101_SECS;
}
return currentEpochTime;
}
uint32_t Logger::getNowEpochTz(void)
{
return getNowEpochT0() + ((uint32_t)_loggerRTCOffset)*3600;
}Possibly also for the following to use an "Ep2k" if it really is from 2000Jan01 - though I haven't worked through this yet.
// from January 1, 1970 00:00:00 UTC) into a DateTime object
DateTime Logger::dtFromEpoch(uint32_t epochTime)
{
//Depreciated
return dtFromEpochTz(epochTime);
}
DateTime Logger::dtFromEpochT0(uint32_t epochTimeT0)
{
DateTime dt(epochTimeT0);
return dt;
}
// This gets the current epoch time (unix time, ie, the number of seconds
// from January 1, 1970 00:00:00 UTC) and corrects it for the specified time zone
DateTime Logger::dtFromEpochTz(uint32_t epochTimeTz)
{
// The DateTime object constructor requires the number of seconds from
// January 1, 2000 (NOT 1970) as input, so we need to subtract.
DateTime dtTz(epochTimeTz - EPOCH_TIME_OFF);
return dtTz;
}Metadata
Metadata
Assignees
Labels
No labels