@@ -127,26 +127,29 @@ bool NTPClient::update() {
127127}
128128
129129unsigned long NTPClient::getEpochTime () const {
130- return this ->_timeOffset + // User offset
131- this ->_currentEpoc + // Epoc returned by the NTP server
130+ return this ->_currentEpoc + // Epoc returned by the NTP server
132131 ((millis () - this ->_lastUpdate ) / 1000 ); // Time since last update
133132}
134133
135134int NTPClient::getDay () const {
136- return (((this ->getEpochTime () / 86400L ) + 4 ) % 7 ); // 0 is Sunday
135+ unsigned long timeWithOffset = this ->getEpochTime () + this ->_timeOffset ; // User offset
136+ return (((timeWithOffset / 86400L ) + 4 ) % 7 ); // 0 is Sunday
137137}
138138int NTPClient::getHours () const {
139- return ((this ->getEpochTime () % 86400L ) / 3600 );
139+ unsigned long timeWithOffset = this ->getEpochTime () + this ->_timeOffset ; // User offset
140+ return ((timeWithOffset % 86400L ) / 3600 );
140141}
141142int NTPClient::getMinutes () const {
142- return ((this ->getEpochTime () % 3600 ) / 60 );
143+ unsigned long timeWithOffset = this ->getEpochTime () + this ->_timeOffset ; // User offset
144+ return ((timeWithOffset % 3600 ) / 60 );
143145}
144146int NTPClient::getSeconds () const {
145- return (this ->getEpochTime () % 60 );
147+ unsigned long timeWithOffset = this ->getEpochTime () + this ->_timeOffset ; // User offset
148+ return (timeWithOffset % 60 );
146149}
147150
148151String NTPClient::getFormattedTime () const {
149- unsigned long rawTime = this ->getEpochTime ();
152+ unsigned long rawTime = this ->getEpochTime () + this -> _timeOffset ; // User offset
150153 unsigned long hours = (rawTime % 86400L ) / 3600 ;
151154 String hoursStr = hours < 10 ? " 0" + String (hours) : String (hours);
152155
@@ -207,4 +210,4 @@ void NTPClient::sendNTPPacket() {
207210void NTPClient::setRandomPort (unsigned int minValue, unsigned int maxValue) {
208211 randomSeed (analogRead (0 ));
209212 this ->_port = random (minValue, maxValue);
210- }
213+ }
0 commit comments