Skip to content

Commit 1012521

Browse files
Tamas Karpatisandeepmistry
Tamas Karpati
authored andcommitted
Make getter methods const
1 parent 70d6ec4 commit 1012521

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

NTPClient.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,26 @@ bool NTPClient::update() {
101101
return true;
102102
}
103103

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

110-
int NTPClient::getDay() {
110+
int NTPClient::getDay() const {
111111
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday
112112
}
113-
int NTPClient::getHours() {
113+
int NTPClient::getHours() const {
114114
return ((this->getEpochTime() % 86400L) / 3600);
115115
}
116-
int NTPClient::getMinutes() {
116+
int NTPClient::getMinutes() const {
117117
return ((this->getEpochTime() % 3600) / 60);
118118
}
119-
int NTPClient::getSeconds() {
119+
int NTPClient::getSeconds() const {
120120
return (this->getEpochTime() % 60);
121121
}
122122

123-
String NTPClient::getFormattedTime() {
123+
String NTPClient::getFormattedTime() const {
124124
unsigned long rawTime = this->getEpochTime();
125125
unsigned long hours = (rawTime % 86400L) / 3600;
126126
String hoursStr = hours < 10 ? "0" + String(hours) : String(hours);

NTPClient.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class NTPClient {
5858
*/
5959
bool forceUpdate();
6060

61-
int getDay();
62-
int getHours();
63-
int getMinutes();
64-
int getSeconds();
61+
int getDay() const;
62+
int getHours() const;
63+
int getMinutes() const;
64+
int getSeconds() const;
6565

6666
/**
6767
* Changes the time offset. Useful for changing timezones dynamically
@@ -77,12 +77,12 @@ class NTPClient {
7777
/**
7878
* @return time formatted like `hh:mm:ss`
7979
*/
80-
String getFormattedTime();
80+
String getFormattedTime() const;
8181

8282
/**
8383
* @return time in seconds since Jan. 1, 1970
8484
*/
85-
unsigned long getEpochTime();
85+
unsigned long getEpochTime() const;
8686

8787
/**
8888
* Stops the underlying UDP client

0 commit comments

Comments
 (0)