Skip to content

Commit 34f3054

Browse files
committed
Handle same-day date range edge case in get_date_created()
1 parent 95b2a73 commit 34f3054

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
@@ -327,6 +327,11 @@ protected static function get_date_created( $assoc_args ) {
327327
$end_timestamp = strtotime( $end );
328328
$days_between = (int) ( ( $end_timestamp - $start_timestamp ) / DAY_IN_SECONDS );
329329

330+
// If start and end are the same day, return that date (time will be randomized in generate())
331+
if ( 0 === $days_between ) {
332+
return date( 'Y-m-d', $start_timestamp );
333+
}
334+
330335
// Generate random offset in days and add to start timestamp
331336
$random_days = wp_rand( 0, $days_between );
332337
return date( 'Y-m-d', $start_timestamp + ( $random_days * DAY_IN_SECONDS ) );

0 commit comments

Comments
 (0)