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

Question: Is there a way to set the time offset automatically #40

Open
sansillusion opened this issue Sep 16, 2017 · 5 comments
Open

Question: Is there a way to set the time offset automatically #40

sansillusion opened this issue Sep 16, 2017 · 5 comments

Comments

@sansillusion
Copy link

I live in an area with Daylight Saving and thus the time offset changes twice a year at different dates each years.
I was wondering how one could automatise the changes.

@bvanelli
Copy link

NTP itself can't handle timezones nor daylight saving times. That's normally the job of the operating system.

What you can do, however, since the daylight savings occur in specific period of time (october 15 to february 17 here) you can just validate the output the DD/MM and adjust the offset accordingly.

Or you can just use the Timezone library.

@jagganath69
Copy link

I've tried using the TimeOffset parameter in both Constructor and setTimeOffset(). Both does NOT work :(
It still outputs the same time (GMT-2, I think)

@PeterSek
Copy link

PeterSek commented Jun 24, 2018 via email

@paai
Copy link

paai commented Apr 14, 2020

This may help. This function looks for the last sunday of a month and returns the utc. You may refine it for the correct hour that the change occurs.
E.g. here the change is on the last sunday of march and the last sunday of october. Call the function twice for march and october and if the real time falls between the two, it is summer.
BTW: dow() returns day of week as an integer between 0 and 6 inclusive, for the array 'sun','mon', 'tue' etc... weekday() would probably also work, but starts from 1.
Disclaimer: I took this from my code, but cobbled a bit to make it understandable, YMMV.

t=now();
time_t llz=laatstezondag(3,31,year());
time_t hlz=laatstezondag(10,31,year());
if ((t>llz) && (t<hlz)) zomer=1; else zomer=0;

...
time_t laatstezondag(int maand,int dag,int jaar)
{ time_t nu,lz;
char w_dag[4]="xxx";
nu=now();
while ((strcmp(w_dag,"sun")) && (dag>24))
{
setTime(2, 0, 0, dag--, maand, jaar);
strcpy(w_dag,weekdag[dow(now())]);
lz=now();
}
setTime(nu);
return lz;
}

@WhymustIhaveaname
Copy link

Windows 10 cannot do it either. So, fix it yourself and good luck.

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

No branches or pull requests

6 participants