NTPClient decode also extern epoch time

overloaded function getDay, getHours, getMinutes and getSeconds with extern epoch time as argument added.
This commit is contained in:
Christian Oelschlegel 2022-06-04 12:35:16 +02:00
parent 78d4237b3a
commit a8eab3fc8b
2 changed files with 18 additions and 1 deletions

View File

@ -148,6 +148,19 @@ int NTPClient::getMinutes() const {
int NTPClient::getSeconds() const { int NTPClient::getSeconds() const {
return (this->getEpochTime() % 60); return (this->getEpochTime() % 60);
} }
// functions for decode extern epoch time
int NTPClient::getDay(unsigned long epochTime) const {
return (((epochTime / 86400L) + 4 ) % 7); //0 is Sunday
}
int NTPClient::getHours(unsigned long epochTime) const {
return ((epochTime % 86400L) / 3600);
}
int NTPClient::getMinutes(unsigned long epochTime) const {
return ((epochTime % 3600) / 60);
}
int NTPClient::getSeconds(unsigned long epochTime) const {
return (epochTime % 60);
}
String NTPClient::getFormattedTime() const { String NTPClient::getFormattedTime() const {
unsigned long rawTime = this->getEpochTime(); unsigned long rawTime = this->getEpochTime();

View File

@ -85,7 +85,11 @@ class NTPClient {
int getHours() const; int getHours() const;
int getMinutes() const; int getMinutes() const;
int getSeconds() const; int getSeconds() const;
int getDay(unsigned long epochTime) const;
int getHours(unsigned long epochTime) const;
int getMinutes(unsigned long epochTime) const;
int getSeconds(unsigned long epochTime) const;
/** /**
* Changes the time offset. Useful for changing timezones dynamically * Changes the time offset. Useful for changing timezones dynamically
*/ */