account for time change when calculating next day start (https://github.com/woocommerce/woocommerce-admin/pull/3333)

This commit is contained in:
Ron Rennick 2019-12-04 19:44:20 -04:00 committed by GitHub
parent 4e4d6b265a
commit cd6c81ae22
1 changed files with 9 additions and 5 deletions

View File

@ -304,14 +304,18 @@ class TimeInterval {
* @return DateTime * @return DateTime
*/ */
public static function next_day_start( $datetime, $reversed = false ) { public static function next_day_start( $datetime, $reversed = false ) {
$day_increment = $reversed ? 0 : 1;
$timestamp = (int) $datetime->format( 'U' );
$seconds_into_day = (int) $datetime->format( 'H' ) * HOUR_IN_SECONDS + (int) $datetime->format( 'i' ) * MINUTE_IN_SECONDS + (int) $datetime->format( 's' ); $seconds_into_day = (int) $datetime->format( 'H' ) * HOUR_IN_SECONDS + (int) $datetime->format( 'i' ) * MINUTE_IN_SECONDS + (int) $datetime->format( 's' );
$next_day_timestamp = $timestamp + ( $day_increment * DAY_IN_SECONDS - $seconds_into_day );
// The day boundary is actually next midnight when going in reverse, so set it to day -1 at 23:59:59. // The day boundary is actually next midnight when going in reverse, so set it to day -1 at 23:59:59.
if ( $reversed ) { if ( $reversed ) {
$next_day_timestamp --; $timestamp = (int) $datetime->format( 'U' );
$next_day_timestamp = $timestamp - ( $seconds_into_day + 1 );
} else {
$day_increment = new \DateInterval( 'P1D' ); // Plus 1 Day.
$next_datetime = clone $datetime;
$next_datetime->add( $day_increment );
$timestamp = (int) $next_datetime->format( 'U' );
$next_day_timestamp = $timestamp - $seconds_into_day;
} }
$next_day = new \DateTime(); $next_day = new \DateTime();