Update WC_Queue_Interface::get_next()

To more closely align return value with other date APIs in WC, namely
WC_Data. Includes changing return value to:

1. a WC_DateTime instead of a timestamp when a scheduled occurrence is found
2. null instead of false, similar to the default of WC_Data::set_date_prop()
This commit is contained in:
Brent Shepherd 2018-07-31 12:08:31 +10:00
parent d9158a8c0e
commit ab78e65af9
2 changed files with 17 additions and 3 deletions

View File

@ -86,10 +86,14 @@ interface WC_Queue_Interface {
public function cancel( $hook, $args = array(), $group = '' );
/**
* Get the date and time for the next scheduled occurence of an action with a given hook
* (an optionally that matches certain args and group), if any.
*
* @param string $hook
* @param array $args
* @param string $group
* @return int|bool The timestamp for the next occurrence, or false if nothing was found
* @return WC_DateTime|null The date and time for the next occurrence, or null if there is no pending, scheduled action for the given hook
*/
public function get_next( $hook, $args = null, $group = '' );

View File

@ -101,14 +101,24 @@ class WC_Action_Queue implements WC_Queue_Interface {
}
/**
* Get the date and time for the next scheduled occurence of an action with a given hook
* (an optionally that matches certain args and group), if any.
*
* @param string $hook
* @param array $args
* @param string $group
*
* @return int|bool The timestamp for the next occurrence, or false if nothing was found
* @return WC_DateTime|null The date and time for the next occurrence, or null if there is no pending, scheduled action for the given hook
*/
public function get_next( $hook, $args = NULL, $group = '' ) {
return wc_next_scheduled_action( $hook, $args, $group );
public function get_next( $hook, $args = null, $group = '' ) {
$next_timestamp = wc_next_scheduled_action( $hook, $args, $group );
if ( $next_timestamp ) {
return wc_string_to_datetime( $next_timestamp );
}
return null;
}
/**