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

DST issue with getNextRunDate #196

Open
raftx24 opened this issue Nov 8, 2024 · 1 comment
Open

DST issue with getNextRunDate #196

raftx24 opened this issue Nov 8, 2024 · 1 comment

Comments

@raftx24
Copy link

raftx24 commented Nov 8, 2024

We encountered an issue with the getNextRunDate method when using the America/Los_Angeles timezone during the Daylight Saving Time (DST) transition. The method returns the wrong next run date after DST ends.

Details: In the example below, we expect getNextRunDate to correctly account for the DST transition occurring on November 3, 2024, but it returns an unexpected date and time.

Code Example:

(new CronExpression('00 01 * * *'))
    ->getNextRunDate(
        '2024-11-03 01:15:00',
        timeZone: 'America/Los_Angeles'
    );

// Actual result:   2024-11-03 01:00:00.000000
// Expected result: 2024-11-04 01:00:00.000000

Environment:

  • PHP Version: 8.3.9
  • Package: dragonmantank/cron-expression v3.4.0
  • Timezone: America/Los_Angeles

Expected Behavior: The getNextRunDate method should return 2024-11-04 01:00:00.000000, accounting for the DST change.

Observed Behavior: The method incorrectly returns 2024-11-03 01:00:00.000000.

@dam1r89
Copy link

dam1r89 commented Nov 8, 2024

As a quick fix, maybe use nth parameter. If the result is before the input date, increase nth to 2 for example:

$res = (new CronExpression('00 01 * * *'))
    ->getNextRunDate(
        '2024-11-03 01:15:00',
        timeZone: 'America/Los_Angeles'
    ); // 2024-11-03 01:00:00
if ($res->isBefore('2024-11-03 01:15:00')) {
    $fixedRes = (new CronExpression('00 01 * * *'))
        ->getNextRunDate(
            '2024-11-03 01:15:00',
            nth: 2, // <-------------
            timeZone: 'America/Los_Angeles'
        ); // 2024-11-04 01:00:00"
}

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

2 participants