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

Daylight savings issue #24

Open
gbohrn opened this issue Apr 7, 2022 · 6 comments
Open

Daylight savings issue #24

gbohrn opened this issue Apr 7, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@gbohrn
Copy link

gbohrn commented Apr 7, 2022

There is definitely a problem with this code having to do with daylight savings transition. Simple example

time_t now = 1647084600;    // Mar 12, 2022 4:30am
string e = "0 30 4 * * *";
cron::cronexpr exp = cron::make_cron(e);
time_t next= cron::cron_next(exp, now);

"now" and "next" come out identical. Expectation is next would be a day ahead. Works the rest of the year

@gbohrn
Copy link
Author

gbohrn commented Apr 10, 2022

For a quick reference. mktime can and does modify the input to your tm2time function. This is just broken. Before using mktime or localtime_s you need to make a copy as these functions can and do screw up your calculations. localtime is allocated statically and mktime as per:
https://www.cplusplus.com/reference/ctime/mktime/
specifically says it may actually change your input.

@mariusbancila mariusbancila self-assigned this May 2, 2022
@mariusbancila mariusbancila added the bug Something isn't working label May 2, 2022
@mariusbancila
Copy link
Owner

I can't reproduce this. When I run your code, next has the value 1647138600, which is Sun Mar 13 04:30:00 2022.

@mariusbancila
Copy link
Owner

That's because in the US the DST occurred on March 13, but only on March 27 in Romania.

@ShunzDai
Copy link

ShunzDai commented Apr 2, 2024

setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1);
tzset();
auto now = cron::cron_next(cron::make_cron("0 30 2 * * ?"), 1711825200);// 1711762200
1711762200 < 1711825200

@ShunzDai
Copy link

ShunzDai commented Apr 2, 2024

setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1); tzset(); auto now = cron::cron_next(cron::make_cron("0 30 2 * * ?"), 1711825200);// 1711762200 1711762200 < 1711825200

This can be solved by moving each
date.tm_isdst = -1;
outside the switch (field)

@phmaurel
Copy link

phmaurel commented Apr 3, 2024

Hello i encountered the same issue with the last daylight saving time in France which occurred the 31 march 2024.

check_next("0 0 8 * * ?", "2024-03-30 08:00:00", "2024-03-31 08:00:00");
or
check_next("0 0 8 * * ?", "2024-03-30 09:00:00", "2024-03-31 08:00:00");
FAILED:
  REQUIRE( value == expected )
with expansion:
  "2024-03-30 08:00:00"
  ==
  2024-03-31 08:00:00

the date.tm_isdst = -1; trick solve the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants