Make getter methods const
This commit is contained in:
parent
70d6ec4e90
commit
10125217d9
@ -101,26 +101,26 @@ bool NTPClient::update() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long NTPClient::getEpochTime() {
|
unsigned long NTPClient::getEpochTime() const {
|
||||||
return this->_timeOffset + // User offset
|
return this->_timeOffset + // User offset
|
||||||
this->_currentEpoc + // Epoc returned by the NTP server
|
this->_currentEpoc + // Epoc returned by the NTP server
|
||||||
((millis() - this->_lastUpdate) / 1000); // Time since last update
|
((millis() - this->_lastUpdate) / 1000); // Time since last update
|
||||||
}
|
}
|
||||||
|
|
||||||
int NTPClient::getDay() {
|
int NTPClient::getDay() const {
|
||||||
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday
|
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday
|
||||||
}
|
}
|
||||||
int NTPClient::getHours() {
|
int NTPClient::getHours() const {
|
||||||
return ((this->getEpochTime() % 86400L) / 3600);
|
return ((this->getEpochTime() % 86400L) / 3600);
|
||||||
}
|
}
|
||||||
int NTPClient::getMinutes() {
|
int NTPClient::getMinutes() const {
|
||||||
return ((this->getEpochTime() % 3600) / 60);
|
return ((this->getEpochTime() % 3600) / 60);
|
||||||
}
|
}
|
||||||
int NTPClient::getSeconds() {
|
int NTPClient::getSeconds() const {
|
||||||
return (this->getEpochTime() % 60);
|
return (this->getEpochTime() % 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
String NTPClient::getFormattedTime() {
|
String NTPClient::getFormattedTime() const {
|
||||||
unsigned long rawTime = this->getEpochTime();
|
unsigned long rawTime = this->getEpochTime();
|
||||||
unsigned long hours = (rawTime % 86400L) / 3600;
|
unsigned long hours = (rawTime % 86400L) / 3600;
|
||||||
String hoursStr = hours < 10 ? "0" + String(hours) : String(hours);
|
String hoursStr = hours < 10 ? "0" + String(hours) : String(hours);
|
||||||
|
12
NTPClient.h
12
NTPClient.h
@ -58,10 +58,10 @@ class NTPClient {
|
|||||||
*/
|
*/
|
||||||
bool forceUpdate();
|
bool forceUpdate();
|
||||||
|
|
||||||
int getDay();
|
int getDay() const;
|
||||||
int getHours();
|
int getHours() const;
|
||||||
int getMinutes();
|
int getMinutes() const;
|
||||||
int getSeconds();
|
int getSeconds() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the time offset. Useful for changing timezones dynamically
|
* Changes the time offset. Useful for changing timezones dynamically
|
||||||
@ -77,12 +77,12 @@ class NTPClient {
|
|||||||
/**
|
/**
|
||||||
* @return time formatted like `hh:mm:ss`
|
* @return time formatted like `hh:mm:ss`
|
||||||
*/
|
*/
|
||||||
String getFormattedTime();
|
String getFormattedTime() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return time in seconds since Jan. 1, 1970
|
* @return time in seconds since Jan. 1, 1970
|
||||||
*/
|
*/
|
||||||
unsigned long getEpochTime();
|
unsigned long getEpochTime() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the underlying UDP client
|
* Stops the underlying UDP client
|
||||||
|
Loading…
Reference in New Issue
Block a user