Skip to content

Fix "Next Run" showing 1970 for unscheduled jobs on non-UTC sites - #242

Open
gunjanjaswal wants to merge 1 commit into
wp-media:masterfrom
gunjanjaswal:fix/144-not-scheduled-shows-1970
Open

gunjanjaswal wants to merge 1 commit into
wp-media:masterfrom
gunjanjaswal:fix/144-not-scheduled-shows-1970

Conversation

@gunjanjaswal

Copy link
Copy Markdown

Fixes #144 (the "next backup scheduled for year 1970" part).

The bug

On the Jobs list, the WP-Cron "Next Run" cell adds the site's gmt_offset to wp_next_scheduled() before checking whether anything is actually scheduled:

$nextrun = wp_next_scheduled( 'backwpup_cron', [ 'arg' => $item ] ) + ( get_option( 'gmt_offset' ) * 3600 );
if ( $nextrun ) {
    // ...show the date...
} else {
    $r .= __( 'Not scheduled!', 'backwpup' );
}

When a job has no scheduled event, wp_next_scheduled() returns false. In the arithmetic PHP coerces false to 0, so the value becomes offset * 3600. On any site whose timezone offset isn't zero that's a small non-zero number, so the if ( $nextrun ) passes and the cell renders 1970-01-01 (or 1969-12-31 for negative offsets) instead of "Not scheduled!". It only looks right in the UTC (offset 0) case, which is why it slips through.

That's the "next backup gets scheduled for year 1970" the report describes — it's the display, not the schedule itself.

The fix

Check wp_next_scheduled() for false first, and only add the offset once there's a real timestamp:

$nextrun = wp_next_scheduled( 'backwpup_cron', [ 'arg' => $item ] );
if ( false !== $nextrun ) {
    $nextrun += get_option( 'gmt_offset' ) * 3600;
    // ...show the date...
} else {
    $r .= __( 'Not scheduled!', 'backwpup' );
}

Scheduled jobs render exactly as before; unscheduled ones now correctly say "Not scheduled!" on every timezone.

Verification

Reproducing the exact expression against a false return across a range of offsets:

== No event scheduled (wp_next_scheduled === false) ==
offset     0 | before: Not scheduled!                     | after: Not scheduled!
offset   5.5 | before: shows 1970-01-01 05:30 by WP-Cron  | after: Not scheduled!
offset    -6 | before: shows 1969-12-31 18:00 by WP-Cron  | after: Not scheduled!
offset     1 | before: shows 1970-01-01 01:00 by WP-Cron  | after: Not scheduled!
offset  5.75 | before: shows 1970-01-01 05:45 by WP-Cron  | after: Not scheduled!

== A real future event (must be unchanged) ==
offset   5.5 | before: 2026-06-01 14:30 by WP-Cron        | after: 2026-06-01 14:30 by WP-Cron
offset    -6 | before: 2026-06-01 03:00 by WP-Cron        | after: 2026-06-01 03:00 by WP-Cron

Note on the other half of the report

The issue also mentions scheduled jobs only running while an admin is logged in. That part is standard WP-Cron behavior — WP-Cron fires on site traffic, so a low-traffic site can miss runs until the next visit. The usual remedy is a real server cron hitting wp-cron.php (or ALTERNATE_WP_CRON), and it's separate from this display fix, so I've left it out of scope here. Happy to look at it separately if you'd like.

On the Jobs list, the WP-Cron next-run cell added the site's gmt_offset to
wp_next_scheduled() before testing the result:

    $nextrun = wp_next_scheduled( ... ) + ( get_option( 'gmt_offset' ) * 3600 );
    if ( $nextrun ) { ...show date... } else { 'Not scheduled!' }

When a job has no scheduled event, wp_next_scheduled() returns false. In the
arithmetic PHP coerces false to 0, so on any site whose gmt_offset isn't 0 the
value becomes offset*3600 -- a small non-zero number that passes the if and
renders as 1970-01-01 (or 1969-12-31 for negative offsets) instead of
"Not scheduled!". It only looked correct in the UTC (offset 0) case.

Check wp_next_scheduled() for false first, and add the offset only once there's
a real timestamp. Scheduled jobs render exactly as before.

Fixes wp-media#144.
@gunjanjaswal

Copy link
Copy Markdown
Author

Gentle bump. This fixes the "Next Run" column showing 1970 for unscheduled jobs on non-English locales, a small scoped change, still mergeable. Happy to rebase if it's drifted; just flagging it's ready for review whenever someone has a moment.

@gunjanjaswal

Copy link
Copy Markdown
Author

Gentle nudge here. The Jobs list adds the site's gmt_offset to wp_next_scheduled() before checking whether anything is actually scheduled, so unscheduled jobs show a "Next Run" of 1970 on non-UTC sites (#144). The fix just reorders that check. Small and contained — happy to rebase if needed, and a first review whenever someone has time would be appreciated.

@gunjanjaswal

Copy link
Copy Markdown
Author

Gentle nudge here, this has been open a couple of months without a look. It's a small fix for the "Next Run" column showing year 1970 on unscheduled jobs on non-UTC sites (the gmt_offset was being added before the scheduled-or-not check). Still merges clean. Anything I can do to help get it reviewed?

@gunjanjaswal

Copy link
Copy Markdown
Author

Checking back on this one. It's a contained fix for the "Next Run" column showing 1970 on unscheduled jobs, and it's still clean against the current branch. Happy to adjust if a maintainer wants anything changed, otherwise it's ready whenever someone has a moment to look.

@gunjanjaswal

Copy link
Copy Markdown
Author

Circling back on this one. It's been open a good while, so no hard feelings if it isn't a priority. It's a small fix for the "Next Run" showing 1970 on non-UTC sites. I'm glad to rebase or tweak it if that helps, or to close it if it's not something you'd want to take.

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.

Scheduled backups are not consitent

1 participant