Return month calendar of specified date, with optional setting for
first day of week (0 for Sunday)
@return array
@param $date string|int
@param $first int
974454
function calendar($date='now',$first=0) {
		$out=FALSE;
		if (extension_loaded('calendar')) {
			if (is_string($date))
				$date=strtotime($date);
			$parts=getdate($date);
			$days=cal_days_in_month(CAL_GREGORIAN,$parts['mon'],$parts['year']);
			$ref=date('w',strtotime(date('Y-m',$parts[0]).'-01'))+(7-$first)%7;
			$out=[];
			for ($i=0;$i<$days;$i++)
				$out[floor(($ref+$i)/7)][($ref+$i)%7]=$i+1;
		}
		return $out;
	}
702575
public static function getPurMonth($date)
    {
        $time = strtotime($date);
        $firstDay = date('Y-m-01', strtotime(date('Y', $time) . '-' . (date('m', $time) - 1) . '-01'));
        $lastDay = date('Y-m-d', strtotime("$firstDay +1 month -1 day"));

        return array($firstDay, $lastDay);
    }
502388
public static function date($date)
    {
        $d = explode('/', date('j/n/Y', strtotime($date)));
        if ($d[0] == '1') {
            $d[0] .= 'º';
        }
        $d[1] = self::MONTHS[$d[1] - 1];
        return implode(' de ', $d);
    }
1322892
public static function displayDateTime($date)
    {
        $namaBulan  = $this->monthList();
        $dateInt    = $this->splitDate($date);
        $dateString = $this->splitDate($date, 'string');

        return $namaBulan[$dateInt['month']] . ' ' . $dateInt['date'] . ', ' . $dateInt['year'] . ' ' . $dateString['hour'] . ':' . $dateString['minute'] . ':' . $dateString['second'];
    }
668630
public static int getMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.MONTH);
    }
128931
public static int getDayOfWeek(@NotNull final Date date) {
		int result = getWithMondayFirst(date, Calendar.DAY_OF_WEEK);
		return result == 1 ? 7 : result - 1;
	}
1169114
public static int getDayOfWeek(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_WEEK);
    }
481593
public static function weekNumber($date)
    {
        /**
         * fungsi ini untuk mendapatkan nilai minggu ke berapa tanggal tersebut.
         * Week dimulai pada hari senin
         * $date = YYYY-mm-dd
         * returned type: integer
         */
        $x = $this->splitDate($date, 'int');
        //print_r($x);
        $weekNo = date("W", mktime(1, 0, 0, $x['month'], $x['date'], $x['year']));

        return $weekNo;
    }
818353
public Date getFirstDateInCalendar(Date dateTarget)
    {
        // Now get the first box on the calendar
        int iFirstDayOfWeek = calendar.getFirstDayOfWeek();
        calendar.setTime(dateTarget);
        int iTargetDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        int iOffset = -Math.abs(iTargetDayOfWeek - iFirstDayOfWeek);
        calendar.add(Calendar.DATE, iOffset);

        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        return calendar.getTime();
    }
1036568
protected function _date($date = null) {
		$timeAgoInWords = $date ? $this->Time->timeAgoInWords($date, array('format' => Configure::read('Task.dateFormat'))) : $this->_none();
		return $this->_isCli ? $timeAgoInWords : $this->Html->tag('span', $timeAgoInWords, array('title' => $date instanceof DateTime ? $date->format(Configure::read('Task.dateFormat')) : $date));
	}
680803
public function dateTo(string $date): Date
    {
        $dates = explode('-', $date);
        if (count($dates) != 3) {
            throw new \InvalidArgumentException(
                    'Given date "' . $date . '" does not follow required format YYYY-MM-DD'
            );
        }

        list($year, $month, $day) = $dates;
        if (!ctype_digit($year)) {
            throw new \InvalidArgumentException(
                    'Given value ' . $year . ' for year not suitable for changing the date.'
            );
        }

        if (!ctype_digit($month) || 1 > $month || 12 < $month) {
            throw new \InvalidArgumentException(
                    'Given value ' . $month . ' for month not suitable for changing the date.'
            );
        }

        if (!ctype_digit($day) || 1 > $day || 31 < $day) {
            throw new \InvalidArgumentException(
                    'Given value ' . $day . ' for day not suitable for changing the date.'
            );
        }

        return $this->createNewDateWithExistingTime((int) $year, (int) $month, (int) $day);
    }
241906
public function set_date($date = null)
    {
        if (is_null($date)) {
            return $this->set_timestamp(time());
        }
        elseif (is_numeric($date)) {
            return $this->set_timestamp($date);
        }
        elseif (is_a($date, self::class)) {
            /** @var Datetime $date */
            return $this->set_date($date->format());
        }
        elseif (preg_match(self::REGEX_SQL, $date, $dateSplitted)) {
            if (\checkdate($dateSplitted['M'], $dateSplitted['D'], $dateSplitted['Y'])) {
                $h = (array_key_exists('h', $dateSplitted) && is_numeric($dateSplitted['h'])) ? $dateSplitted['h'] : 0;
                $m = (array_key_exists('m', $dateSplitted) && is_numeric($dateSplitted['m'])) ? $dateSplitted['m'] : 0;
                $s = (array_key_exists('s', $dateSplitted) && is_numeric($dateSplitted['s'])) ? $dateSplitted['s'] : 0;
    
                $mkt = mktime($h, $m, $s, $dateSplitted['M'], $dateSplitted['D'], $dateSplitted['Y']);
                $this->set_date($mkt);
                return $this;
            }
            else {
                return false;
            }
        }
        elseif (preg_match(self::REGEX_STR, $date, $dateSplitted)) {
            if (\checkdate($dateSplitted['M'], $dateSplitted['D'], $dateSplitted['Y'])) {
                $h = (array_key_exists('h', $dateSplitted) && is_numeric($dateSplitted['h'])) ? $dateSplitted['h'] : 0;
                $m = (array_key_exists('m', $dateSplitted) && is_numeric($dateSplitted['m'])) ? $dateSplitted['m'] : 0;
                $s = (array_key_exists('s', $dateSplitted) && is_numeric($dateSplitted['s'])) ? $dateSplitted['s'] : 0;
                
                $mkt = mktime($h, $m, $s, $dateSplitted['M'], $dateSplitted['D'], $dateSplitted['Y']);
                $this->set_date($mkt);
                
                return $this;
            }
            else {
                return false;
            }
        }
        elseif (preg_match(self::REGEX_SEM, $date, $dateSplitted)) {
            $baseDt = new \DateTime();
            $baseDt->setISOdate($dateSplitted['Y'], $dateSplitted['S']);
            return $this->set_date($baseDt->getTimestamp());
        }
        
        return false;
    }
523271
def __get_first_tuesday(this_date):
    ''''''
    month_range = calendar.monthrange(this_date.year, this_date.month)
    first_of_month = datetime.datetime(this_date.year, this_date.month, 1)
    first_tuesday_day = (calendar.TUESDAY - month_range[0]) % 7
    first_tuesday = first_of_month + datetime.timedelta(days=first_tuesday_day)
    return first_tuesday
1181067
public function date($date)
    {
        $events = $this->repository->findEventsByDate($date);

        if (empty($events)) {
            abort(404);
        }

        return view('cms-frontend::events.date')->with('events', $events);
    }
479644
public function getDayOfWeek(AnDate $date = null)
    {
        $year = isset($date) ? $date->year  : $this->year;
        $month = isset($date) ? $date->month : $this->month;
        $day = isset($date) ? $date->day   : $this->day;

        if ($month > 2) {
            $month -= 2;
        } else {
            $month += 10;
            $year--;
        }

        $day = (floor((13 * $month - 1) / 5) +
                $day + ($year % 100) +
                floor(($year % 100) / 4) +
                floor(($year / 100) / 4) - 2 *
                floor($year / 100) + 77);

        $weekday_number = $day - 7 * floor($day / 7);
        return $weekday_number;
    }
635335
private static Calendar getCalendar(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }
761497
public function setStartDate($date)
    {
        $date = AnDomainAttributeDate::getInstance()->setDate($date);
        $this->set('startDate', $date);

        return $this;
    }