Make getter methods const

This commit is contained in:
Tamas Karpati 2018-02-20 21:32:17 +01:00 committed by Sandeep Mistry
parent 70d6ec4e90
commit 10125217d9
2 changed files with 12 additions and 12 deletions

View File

@ -101,26 +101,26 @@ bool NTPClient::update() {
return true;
}
unsigned long NTPClient::getEpochTime() {
unsigned long NTPClient::getEpochTime() const {
return this->_timeOffset + // User offset
this->_currentEpoc + // Epoc returned by the NTP server
((millis() - this->_lastUpdate) / 1000); // Time since last update
}
int NTPClient::getDay() {
int NTPClient::getDay() const {
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday
}
int NTPClient::getHours() {
int NTPClient::getHours() const {
return ((this->getEpochTime() % 86400L) / 3600);
}
int NTPClient::getMinutes() {
int NTPClient::getMinutes() const {
return ((this->getEpochTime() % 3600) / 60);
}
int NTPClient::getSeconds() {
int NTPClient::getSeconds() const {
return (this->getEpochTime() % 60);
}
String NTPClient::getFormattedTime() {
String NTPClient::getFormattedTime() const {
unsigned long rawTime = this->getEpochTime();
unsigned long hours = (rawTime % 86400L) / 3600;
String hoursStr = hours < 10 ? "0" + String(hours) : String(hours);

View File

@ -58,10 +58,10 @@ class NTPClient {
*/
bool forceUpdate();
int getDay();
int getHours();
int getMinutes();
int getSeconds();
int getDay() const;
int getHours() const;
int getMinutes() const;
int getSeconds() const;
/**
* Changes the time offset. Useful for changing timezones dynamically
@ -77,12 +77,12 @@ class NTPClient {
/**
* @return time formatted like `hh:mm:ss`
*/
String getFormattedTime();
String getFormattedTime() const;
/**
* @return time in seconds since Jan. 1, 1970
*/
unsigned long getEpochTime();
unsigned long getEpochTime() const;
/**
* Stops the underlying UDP client