Skip to content

fix: improve daylight saving time handling in updateSWChange method, …#80

Merged
techniccontroller merged 3 commits into
mainfrom
fix_dst
Apr 4, 2026
Merged

fix: improve daylight saving time handling in updateSWChange method, …#80
techniccontroller merged 3 commits into
mainfrom
fix_dst

Conversation

@techniccontroller
Copy link
Copy Markdown
Owner

fix #79

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves EU daylight saving time (summer/winter) switching in NTPClientPlus::updateSWChange() to trigger at the correct transition hour (rather than at the start of the transition date), addressing issue #79.

Changes:

  • Compute a “standard-time hour” (without DST) to evaluate the DST transition moment more precisely.
  • Update the last-Sunday-in-March rule to switch to DST only at/after 02:00 standard time.
  • Update the last-Sunday-in-October rule to switch back to winter time only at/after 02:00 standard time (== 03:00 summer time).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ntp_client_plus.cpp Outdated
Comment thread ntp_client_plus.cpp
Comment on lines +622 to +631
if (hourNoDST >= 2)
{
this->setSummertime(1);
summertimeActive = true;
}
else
{
this->setSummertime(0);
summertimeActive = false;
}
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Sunday switch blocks duplicate the same state-setting logic (set _summertime + summertimeActive) in both branches. This can be simplified by computing a single boolean (e.g., shouldBeSummer = hourNoDST >= 2 for March, inverse for October) and then applying it once, which reduces branching and makes future rule changes less error-prone.

Suggested change
if (hourNoDST >= 2)
{
this->setSummertime(1);
summertimeActive = true;
}
else
{
this->setSummertime(0);
summertimeActive = false;
}
bool shouldBeSummer = (hourNoDST >= 2);
this->setSummertime(shouldBeSummer ? 1 : 0);
summertimeActive = shouldBeSummer;

Copilot uses AI. Check for mistakes.
Comment thread ntp_client_plus.cpp
Comment on lines +677 to +686
if (hourNoDST >= 2)
{
this->setSummertime(0);
summertimeActive = false;
}
else
{
this->setSummertime(1);
summertimeActive = true;
}
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the March block: the last-Sunday-in-October branch repeats the same setSummertime(...) + summertimeActive = ... assignments in both paths. Consider computing the desired DST state once from hourNoDST and applying it once to avoid duplicated logic.

Suggested change
if (hourNoDST >= 2)
{
this->setSummertime(0);
summertimeActive = false;
}
else
{
this->setSummertime(1);
summertimeActive = true;
}
bool dstActive = (hourNoDST < 2);
this->setSummertime(dstActive ? 1 : 0);
summertimeActive = dstActive;

Copilot uses AI. Check for mistakes.
techniccontroller and others added 2 commits April 4, 2026 12:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ntp_client_plus.cpp
this->_summertime * this->secondperhour + // Summer time offset
this->_secsSince1900 + // seconds returned by the NTP server
((millis() - this->_lastUpdate) / 1000); // Time since last update
{
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line has trailing whitespace after the opening brace. Please remove it to keep formatting consistent with the rest of the file (e.g., other function bodies start with a clean {).

Suggested change
{
{

Copilot uses AI. Check for mistakes.
Comment thread ntp_client_plus.cpp
// If today is Sunday (dayOfWeek == 7) then this is already the last sunday in march -> set summer time
// If today is Sunday (dayOfWeek == 7) then this is the last Sunday in March.
// Switch to summer time at 02:00 standard time (clock jumps to 03:00).
if(dayOfWeek == 7){
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is inconsistent with the rest of this file (most conditionals use if ( and put a space before {). Please update to the prevailing style (e.g., if (dayOfWeek == 7) {).

Suggested change
if(dayOfWeek == 7){
if (dayOfWeek == 7) {

Copilot uses AI. Check for mistakes.
Comment thread ntp_client_plus.cpp
// If today is Sunday (dayOfWeek == 7) then this is the last Sunday in October.
// Switch back to winter time at 02:00 standard time
// (which corresponds to 03:00 local summer time).
if(dayOfWeek == 7){
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is inconsistent with the rest of this file (most conditionals use if ( and put a space before {). Please update to the prevailing style (e.g., if (dayOfWeek == 7) {).

Suggested change
if(dayOfWeek == 7){
if (dayOfWeek == 7) {

Copilot uses AI. Check for mistakes.
@techniccontroller techniccontroller merged commit 3c71cbd into main Apr 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DST switches too early because transition time is checked only by date

2 participants