Tribe__Tickets__Ticket_Object::date_in_range( string|int|null $datetime = null )

Determines if the given date is within the ticket’s start/end date range


Parameters

$datetime

(string|int|null) (Optional) The date/time that we want to determine if it falls within the start/end date range.

Default value: null


Top ↑

Return

(boolean) Whether or not the provided date/time falls within the start/end date range


Top ↑

Source

File: src/Tribe/Ticket_Object.php

		public function date_in_range( $datetime = 'now' ) {
			$timestamp = is_numeric( $datetime ) ? $datetime : strtotime( $datetime );
			// Attempt to convert the timestamp to a Date object.
			try {
				$timezone = $this->get_event_timezone();
				if ( 'now' === $datetime ) {
					$now = new DateTime( 'now', $timezone  );
				} else {
					$now = new DateTime( '@' . $timestamp );
					if ( $timezone instanceof DateTimeZone ) {
						$now->setTimezone( $timezone );
					}
				}
			} catch ( Exception $exception ) {
				return false;
			}

			$start = $this->start_date( false );
			$end   = $this->end_date( false );

			if ( ! $start instanceof DateTime || ! $end instanceof DateTime || ! $now instanceof DateTime ) {
				$now   = $timestamp;
				$start = $this->start_date();
				$end   = $this->end_date();
			}

			// Bail if we don't have an end date and the event has passed
			// Check if the event has passed in case we're using TEC
			$is_past_event = function_exists( 'tribe_is_past_event' )
				? tribe_is_past_event( tribe_events_get_event( $this->event_id ) )
				: false;

			if ( empty( $end ) && $is_past_event ) {
				return false;
			}

			return ( empty( $start ) || $now >= $start ) && ( empty( $end ) || $now <= $end );
		}