Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conecpt for Daylightsavingtime #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

holgerlembke
Copy link

Just and idea for a somehow flexible daylightsavingtime implementation.

works for my German case.

@Apollon77
Copy link

Hey, I use the "Timezone" library additionally to Time (https://github.com/JChristensen/Timezone) and it works great. Just some lines of code

@timo-keller
Copy link

Hey,

I think there might be a problem with the DST provider in your example code:
TimeLib defines sunday as dow 1: uint8_t Wday; // day of week, sunday is day 1,
whereas your example code expects sunday to be weekday 0: #define FIRSTDAY 6 // 0 = Sunday according to the referenced source.

@terryjmyers
Copy link

terryjmyers commented Mar 21, 2017

I've successfully implemented DST in this routine. I did this recently with a direct fork from a few weeks ago:
https://github.com/terryjmyers/TimeLib

EDIT: OMG!! I've tried to paste some code snippets here like 100 times...I friggin give up, here is the meat and potatoes routine(completely unformatted because the <> button doesn't seem to like it...(just go to my git above and look at the changes...sheesh
bool isDST(tmElements_t &tm){ //adapted from http://stackoverflow.com/questions/5590429/calculating-daylight-saving-time-from-only-date if (dstRule == 0) return false; int previousSunday = tm.Day - tm.Wday; if (dstRule == 1) { //January, february, and december are out. if (tm.Month < 3 || tm.Month > 11) { return false; } //April to October are in if (tm.Month > 3 && tm.Month < 11) { return true; } //In march, we are DST if our previous sunday was on or after the 8th. if (tm.Month == 3) { return previousSunday >= 8; } //In november we must be before the first sunday to be dst. //That means the previous sunday must be before the 1st. return previousSunday <= 0; } else if (dstRule == 2) { if (tm.Month < 3 || tm.Month > 10) return false; if (tm.Month > 3 && tm.Month < 10) return true; if (tm.Month == 3) return previousSunday >= 25; if (tm.Month == 10) return previousSunday < 25; return false; // this line never gonna happend } }

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.

None yet

4 participants