setTimezone( wp_timezone() ); $current = ( (int) $local->format( 'G' ) * 60 ) + (int) $local->format( 'i' ); $quiet = $start < $end ? ( $current >= $start && $current < $end ) : ( $current >= $start || $current < $end ); if ( ! $quiet ) { return 0; } // Built as a date rather than by adding minutes, so a timezone whose // offset changes between now and the morning lands on the wall-clock time // the shop asked for rather than a fixed number of seconds later. $opens = $local->setTime( intdiv( $end, 60 ), $end % 60, 0 ); if ( $opens <= $local ) { $opens = $opens->modify( '+1 day' ); } return max( 1, $opens->getTimestamp() - $now ); } /** * Is this moment inside the window? * * @param int $now Timestamp to judge. * @param string $from Window start as `HH:MM`. * @param string $to Window end as `HH:MM`. */ public static function isQuiet( int $now, string $from, string $to ): bool { return self::secondsUntilOpen( $now, $from, $to ) > 0; } /** * `HH:MM` as minutes past midnight, or null when it is not a time. * * @param string $value Stored setting. */ private static function minutes( string $value ): ?int { if ( 1 !== preg_match( '/^([01][0-9]|2[0-3]):([0-5][0-9])$/', trim( $value ), $parts ) ) { return null; } return ( (int) $parts[1] * 60 ) + (int) $parts[2]; } }