Tribe__Date_Utils::get_shifted_end_of_day( string|DateTimeInterface $date, null|string $cutoff = null )
Given a specific DateTime we determine the end of that day based on our Internal End of Day Cut-off.
Contents
Parameters
- $date
-
(string|DateTimeInterface) (Required) Date that we are getting the end of day from.
- $cutoff
-
(null|string) (Optional) Which cutoff to use.
Default value: null
Return
(DateTimeInterface|false) Returns a DateTimeInterface when a valid date is given or false.
Source
File: src/Tribe/Date_Utils.php
public static function get_shifted_end_of_day( $date, $cutoff = null ) { $date_obj = static::build_date_object( $date ); if ( ! $date_obj ) { return false; } $start_of_day = clone $date_obj; $end_of_day = clone $date_obj; if ( empty( $cutoff ) || ! is_string( $cutoff ) || false === strpos( $cutoff, ':' ) ) { $cutoff = tribe_get_option( 'multiDayCutoff', '00:00' ); } list( $hours_to_add, $minutes_to_add ) = array_map( 'absint', explode( ':', $cutoff ) ); $seconds_to_add = ( $hours_to_add * HOUR_IN_SECONDS ) + ( $minutes_to_add * MINUTE_IN_SECONDS ); if ( 0 !== $seconds_to_add ) { $interval = static::interval( "PT{$seconds_to_add}S" ); } $start_of_day->setTime( '0', '0', '0' ); $end_of_day->setTime( '23', '59', '59' ); if ( 0 !== $seconds_to_add ) { $start_of_day->add( $interval ); $end_of_day->add( $interval ); } if ( $end_of_day >= $date_obj && $date_obj >= $start_of_day ) { return $end_of_day; } $start_of_day->sub( static::interval( 'P1D' ) ); if ( $start_of_day < $date_obj ) { $end_of_day->sub( static::interval( 'P1D' ) ); } return $end_of_day; }
Changelog
Version | Description |
---|---|
4.11.2 | Introduced. |