Tribe__Date_Utils::get_shifted_start_of_day( string|DateTimeInterface $date, null|string $cutoff = null )

Given a specific DateTime we determine the start of that day based on our Internal End of Day Cut-off.


Parameters #

$date

(string|DateTimeInterface) (Required) Date that we are getting the start of day from.

$cutoff

(null|string) (Optional) Which cutoff to use.

Default value: null


Top ↑

Return #

(DateTimeInterface|false) Returns a DateTimeInterface when a valid date is given or false.


Top ↑

Source #

File: src/Tribe/Date_Utils.php

		public static function get_shifted_start_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 $start_of_day;
			}

			$end_of_day->sub( static::interval( 'P1D' ) );

			if ( $end_of_day > $date_obj ) {
				$start_of_day->sub( static::interval( 'P1D' ) );
			}

			return $start_of_day;
		}

Top ↑

Changelog #

Changelog
Version Description
4.11.2 Introduced.