Month_View::calculate_first_cell_date( string $month, integer $start_of_week = null )

Return the date of the first day in the month view grid.

This is not necessarily the 1st of the specified month, rather it is the date of the first grid cell which could be anything upto 6 days earlier than the 1st of the month.


Parameters

$month

(string) (Required)

$start_of_week

(integer) (Optional)

Default value: null


Top ↑

Return

(bool|string) (Y-m-d)


Top ↑

Source

File: src/Tribe/Views/V2/Views/Month_View.php

	public static function calculate_first_cell_date( $month, $start_of_week = null ) {
		if ( null === $start_of_week ) {
			$start_of_week = (int) get_option( 'start_of_week', 0 );
		}

		$day_1 = Dates::first_day_in_month( $month );
		if ( $day_1 < $start_of_week ) {
			$day_1 += 7;
		}

		$diff = $day_1 - $start_of_week;
		if ( $diff >= 0 ) {
			$diff = "-$diff";
		}

		try {
			$date = new \DateTime( $month );
			$date = new \DateTime( $date->format( 'Y-m-01' ) );
			$date->modify( "$diff days" );

			return $date->format( Dates::DBDATEFORMAT );
		} catch ( \Exception $e ) {
			return false;
		}
	}

Top ↑

Changelog

Changelog
Version Description
6.0.0 Introduced.