Skip to content

Commit 09500f2

Browse files
committed
Handle same-day date range edge case in generate_batch_dates()
1 parent 34f3054 commit 09500f2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

includes/Generator/Order.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,11 @@ protected static function generate_batch_dates( $count, $args ) {
846846
$end_timestamp = strtotime( $end );
847847
$days_between = (int) ( ( $end_timestamp - $start_timestamp ) / DAY_IN_SECONDS );
848848

849+
// If start and end dates are the same, return array of that date
850+
if ( 0 === $days_between ) {
851+
return array_fill( 0, $count, date( 'Y-m-d', $start_timestamp ) );
852+
}
853+
849854
$dates = array();
850855
for ( $i = 0; $i < $count; $i++ ) {
851856
$random_days = wp_rand( 0, $days_between );

0 commit comments

Comments
 (0)