• Resolved Franky

    (@liedekef)


    In wordpress, a day is defined as having 24 hours:

    wp-includes/default-constants.php: define( 'DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS );

    but that doesn’t take summer/winter time into account of course.
    While it is being stated above the definition that these values are approximate and are provided for convenience, the DAY_IN_SECONDS is being used in the “daily” cron definition. This means if you plan something to happen at midnight (say membership status recalc, half of the year it will happen one hour later/earlier (depending on the day you planned it initially).
    So, in order to be sure something happens “as soon as the new day starts”, you need to plan it at 01:00 at the earliest …
    Since the fixed wp schedules are in fact “fixed”, why not have them calculate “daily” as the DateTime function “+1 day”? The same goes for weekly, monthly, yearly.

    I know WP cron doesn’t run exactly the moment you want it (unless you use system cron), if running something “daily” at around midnight and it causes it to be ran at 23:00 instead, you might be giving people an extra free day entrance (again for memberships).

    • This topic was modified 2 years, 7 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • …but that doesn’t take summer/winter time into account of course.

    DAY_IN_SECONDS is always the same fixed number. It’s physics.
    Also, there are parts of the world where there are no DST to begin with.

    Since the fixed wp schedules are in fact “fixed”, why not have them calculate “daily” as the DateTime function “+1 day”? The same goes for weekly, monthly, yearly.

    This question shall be asked on Core trac, as it deals with how the behavior of Core should be modified.
    https://core.trac.www.ads-software.com

    if running something “daily” at around midnight and it causes it to be ran at 23:00 instead, you might be giving people an extra free day entrance (again for memberships).

    I.) Is there a reason in which you can’t run it at 2:00 AM for example? It’s close enough to the “turn of the day” and won’t get affected by whether or not DST is on or off.
    II.) If I.) is not possible, the other way is to develop your own plug-in that runs on its own schedule that takes into account DST.

    Thread Starter Franky

    (@liedekef)

    DAY_IN_SECONDS is always the same fixed number. It’s physics.

    When you’re in a timezone with DST, once a year a day has 23 hours and once a year a day has 25 hours. The definition of a “day” should take DST-issues into account, as does the datetime lib in php.

    II.) If I.) is not possible, the other way is to develop your own plug-in that runs on its own schedule that takes into account DST.

    When planning something daily at midnight using the regular wordpress functions, one expects that it indeed happens once a day. In the case of DST, 2 times a year this would not be the case … while I can (and will) indeed adapt my logic, I don’t think it is up to every developer to start creating own schedules in case of DST, but in fact WP that should adapt the flawed logic. I will open a trac-issue for this.

    DAY_IN_SECONDS is always the same fixed number. It’s physics.

    When you’re in a timezone with DST, once a year a day has 23 hours and once a year a day has 25 hours. The definition of a “day” should take DST-issues into account, as does the datetime lib in php.

    That’s not the issue of the DAY_IN_SECONDS , which is always the same constant number.
    https://www.quora.com/How-many-seconds-are-in-a-day
    (every answer listed is or nearly 86,400 seconds)

    Yes, on the day of DST on/off, there is one less or extra hour (23 hr. or 25 hr.).
    https://www.timeanddate.com/time/dst/transition.html

    If you want DST, you need to take that into account on your own end.

    Thread Starter Franky

    (@liedekef)

    If you want DST, you need to take that into account on your own end.

    I’m sorry, but in linux cron, when I plan something daily at 00:00, it happens daily at 00:00 (with or without DST). The server is changing time, but I don’t need to be aware of it. The same should be in wordpress cron. Daily must mean “daily”, not “almost all the time daily but not in some cases”.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP cron daily issue’ is closed to new replies.