Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions NTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,35 @@ bool NTPClient::update() {
}

unsigned long NTPClient::getEpochTime() {
return this->_timeOffset + // User offset
this->_currentEpoc + // Epoc returned by the NTP server
return this->_currentEpoc + // Epoc returned by the NTP server
((millis() - this->_lastUpdate) / 1000); // Time since last update
}

int NTPClient::getDay() {
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday
unsigned long time = this->getEpochTime();
time += this->_timeOffset; // User offset
return (((time / 86400L) + 4 ) % 7); //0 is Sunday
}
int NTPClient::getHours() {
return ((this->getEpochTime() % 86400L) / 3600);
unsigned long time = this->getEpochTime();
time += this->_timeOffset; // User offset
return ((time % 86400L) / 3600);
}
int NTPClient::getMinutes() {
return ((this->getEpochTime() % 3600) / 60);
unsigned long time = this->getEpochTime();
time += this->_timeOffset; // User offset
return ((time % 3600) / 60);
}
int NTPClient::getSeconds() {
return (this->getEpochTime() % 60);
unsigned long time = this->getEpochTime();
time += this->_timeOffset; // User offset
return (time % 60);
}

String NTPClient::getFormattedTime() {
unsigned long rawTime = this->getEpochTime();
rawTime += this->_timeOffset; // User offset

unsigned long hours = (rawTime % 86400L) / 3600;
String hoursStr = hours < 10 ? "0" + String(hours) : String(hours);

Expand Down