Skip to content

Commit

Permalink
Action scheduler utc vs local time fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Dec 22, 2023
1 parent 90b8c55 commit abb3aa2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,15 +692,20 @@ public static function setup_recurring_actions() {
}

if ( self::enable_tax_rate_observer() ) {
// Schedule once per day at 0:00
// Schedule once per day at 0:00 in local timezone
if ( null === $queue->get_next( 'oss_woocommerce_tax_rate_observer', array(), 'oss_woocommerce' ) ) {
$timestamp = strtotime( 'tomorrow midnight' );
$date = new \WC_DateTime();

$date->setTimestamp( $timestamp );
/**
* Use WC helper method which calculates the date in current
* local timezone.
*/
$date = wc_string_to_datetime( 'tomorrow midnight' );
$date->modify( '+1 second' );

$queue->cancel_all( 'oss_woocommerce_tax_rate_observer', array(), 'oss_woocommerce' );

/**
* Action scheduler expects the time in UTC.
*/
$queue->schedule_recurring( $date->getTimestamp(), DAY_IN_SECONDS, 'oss_woocommerce_tax_rate_observer', array(), 'oss_woocommerce' );
}
} else {
Expand Down

0 comments on commit abb3aa2

Please sign in to comment.