get start and end date of select quarter

@param   string $quarter
@return  array
3475
public static function getQuarter($quarter = 'current')
    {

        $response['startDate']  = null;
        $response['endDate']    = null;

        switch ($quarter)
        {
            case 'current': // current quarter
                $currentMonth   = date('m');
                $currentYear    = date('Y');

                if($currentMonth >= 1 && $currentMonth <= 3)
                {
                    $response['startDate']  = strtotime('1-January-' . $currentYear);  // timestamp or 1-Januray 12:00:00 AM
                    $response['endDate']    = strtotime('1-April-' . $currentYear);  // timestamp or 1-April 12:00:00 AM means end of 31 March
                }
                elseif($currentMonth >= 4 && $currentMonth <= 6)
                {
                    $response['startDate']  = strtotime('1-April-' . $currentYear);  // timestamp or 1-April 12:00:00 AM
                    $response['endDate']    = strtotime('1-July-' . $currentYear);  // timestamp or 1-July 12:00:00 AM means end of 30 June
                }
                elseif($currentMonth >= 7 && $currentMonth <= 9)
                {
                    $response['startDate']  = strtotime('1-July-' . $currentYear);  // timestamp or 1-July 12:00:00 AM
                    $response['endDate']    = strtotime('1-October-' . $currentYear);  // timestamp or 1-October 12:00:00 AM means end of 30 September
                }
                elseif($currentMonth >= 10 && $currentMonth <= 12)
                {
                    $response['startDate']  = strtotime('1-October-' . $currentYear);  // timestamp or 1-October 12:00:00 AM
                    $response['endDate']    = strtotime('1-January-' . ($currentYear + 1));  // timestamp or 1-January Next year 12:00:00 AM means end of 31 December this year
                }
                break;

            case 'last': // daily, get values of last day
                $currentMonth = date('m');
                $currentYear = date('Y');

                if($currentMonth >= 1 && $currentMonth <= 3)
                {
                    $response['startDate']  = strtotime('1-October-' . ($currentYear - 1));  // timestamp or 1-October Last Year 12:00:00 AM
                    $response['endDate']    = strtotime('1-January-' . $currentYear);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
                }
                elseif($currentMonth >= 4 && $currentMonth <= 6)
                {
                    $response['startDate']  = strtotime('1-January-' . $currentYear);  // timestamp or 1-Januray 12:00:00 AM
                    $response['endDate']    = strtotime('1-April-' . $currentYear);  // timestamp or 1-April 12:00:00 AM means end of 31 March
                }
                elseif($currentMonth >= 7 && $currentMonth <= 9)
                {
                    $response['startDate']  = strtotime('1-April-' . $currentYear);  // timestamp or 1-April 12:00:00 AM
                    $response['endDate']    = strtotime('1-July-' . $currentYear);  // timestamp or 1-July 12:00:00 AM means end of 30 June
                }
                elseif($currentMonth >= 10 && $currentMonth <= 12)
                {
                    $response['startDate']  = strtotime('1-July-' . $currentYear);  // timestamp or 1-July 12:00:00 AM
                    $response['endDate']    = strtotime('1-October-' . $currentYear);  // timestamp or 1-October 12:00:00 AM means end of 30 September
                }
                break;
        }

        return $response;
    }
1103496
public function getParticipationsByRangeDate($startDate = '', $endDate = '')
    {
        $em = $this->getServiceManager()->get('doctrine.entitymanager.orm_default');

        $startDateTime = \DateTime::createFromFormat('d/m/Y', $startDate);
        $endDateTime = \DateTime::createFromFormat('d/m/Y', $endDate);

        if ($startDate != '' && $endDate != '') {
            $dateRange = "(e.created_at >='" . $startDateTime->format('Y-m-d') . " 0:0:0' AND e.created_at <= '" . $endDateTime->format('Y-m-d') . " 0:0:0')";
        } elseif ($startDate == '' && $endDate != '') {
            $dateRange = "e.created_at <= '" . $endDateTime->format('Y-m-d') . " 0:0:0'";
        } elseif ($startDate != '' && $endDate == '') {
            $dateRange = "e.created_at >='" . $startDateTime->format('Y-m-d') . " 0:0:0'";
        } else {
            $dateRange = "e.created_at IS NOT NULL";
        }

        $query = $em->createQuery('
            SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e
			WHERE ' . $dateRange . '
            AND e.active=0
		');
        $count = $query->getSingleScalarResult();
        return $count;
    }
846882
public function computeValue(array $period = [])
    {
        if (!isset($period[ 'start' ]) || !isset($period[ 'end' ])) {
            $period = $this->nthPreviousPeriod();
        }

        $start = $period[ 'start' ];
        $end = $period[ 'end' ];

        // cache computed values
        if (!isset($this->values[ "$start.$end" ])) {
            $this->values[ "$start.$end" ] = $this->value($start, $end);
        }

        return $this->values[ "$start.$end" ];
    }
1289320
public function getStartDate()
    {
        if (isset($this->_gemsData['gec_startdate']) && $this->_gemsData['gec_startdate']) {
            if (! $this->_gemsData['gec_startdate'] instanceof \MUtil_Date) {
                $this->_gemsData['gec_startdate'] =
                        new \MUtil_Date($this->_gemsData['gec_startdate'], \Gems_Tracker::DB_DATE_FORMAT);
            }
            return $this->_gemsData['gec_startdate'];
        }
    }
599773
public static function getDateTimeRange($start, $end = null, $exact = false)
    {
        return [
            static::buildDateTime($start, !$exact),
            static::buildDateTime($end ?: $start, false, !$exact),
        ];
    }
1136095
public function AllYears()
	{
		$result = array_reduce( $this->contexts, function( $carry, $context ) {

			if ( ! isset( $context['period'] ) ) return $carry;
			// Get the year of the start date
			$parts = explode( "-", $context['period']['startDate'] );
			$carry[ $parts[0] ] = isset( $carry[ $parts[0] ] ) ? $carry[ $parts[0] ] + 1 : 1;
			$parts = explode( "-", $context['period']['endDate'] );
			$carry[ $parts[0] ] = isset( $carry[ $parts[0] ] ) ? $carry[ $parts[0] ] + 1 : 1;
			return $carry;

		}, array() );

		ksort( $result );
		return array_keys( $result );
	}
613675
public function getrange($key, $start, $end) {
        return $this->returnCommand(['GETRANGE'], $key, [$key, $start, $end]);
    }
474647
public function getEventRange(array $options = []): array
    {
        $result = [];

        if (empty($options['period'])) {
            return $result;
        }

        //@NOTE: sqlite doesn't support date_format or month functions
        if (!empty($options['period']['start_date'])) {
            $result['start'] = [
                'MONTH(start_date) >=' => date('m', strtotime($options['period']['start_date']))
            ];
        }

        if (!empty($options['period']['end_date'])) {
            $result['end'] = [
                'MONTH(end_date) <=' => date('m', strtotime($options['period']['end_date']))
            ];
        }

        return $result;
    }
580615
public function between(\DateTime $start, \DateTime $end)
    {
        // Comparing DateTime also looks at the time. So we need to make sure the time is 0,
        // but don't modify the original referenced DateTime parameters
        $start = clone $start;
        $end = clone $end;
        $start->setTime(0, 0, 0);
        $end->setTime(0, 0, 0);

        $startyear = (int) $start->format("Y");
        $endyear   = (int) $end->format("Y");
        $holidays  = array();
        for ($y = $startyear; $y <= $endyear; $y++) {
            $holidays = array_merge($holidays, $this->getHolidays($y));
        }

        return array_filter($holidays,
            function(\DateTime $dt) use ($start, $end) {
                return $dt >= $start && $dt <= $end;
            });
    }
429522
public function getStartDate() : ?string 
    {
        if ( ! $this->hasStartDate()) {
            $this->setStartDate($this->getDefaultStartDate());
        }
        return $this->startDate;
    }
1270167
def previous_quarter(d):
    
    from django_toolkit.datetime_util import quarter as datetime_quarter
    return quarter( (datetime_quarter(datetime(d.year, d.month, d.day))[0] + timedelta(days=-1)).date() )
1071700
def round_to_quarter(start_time, end_time):
    
    # We don't care about the date (only about the time) but Python
    # can substract only datetime objects, not time ones
    today = datetime.date.today()
    start_date = datetime.datetime.combine(today, start_time)
    end_date = datetime.datetime.combine(today, end_time)

    difference_minutes = (end_date - start_date).seconds / 60
    remainder = difference_minutes % 15
    # Round up
    difference_minutes += 15 - remainder if remainder > 0 else 0

    return (
        start_date + datetime.timedelta(minutes=difference_minutes)
    ).time()
499598
public function rangeHours($start, $end, $interval = 1, $select = true)
    {
        $tStart = strtotime($start);
        $tEnd = strtotime($end);
        $tNow = $tStart;

        $hours = [];
        while ($tNow <= $tEnd) {
            $hours[] = date("H:i", $tNow);
            $tNow = strtotime('+'.$interval.' hour', $tNow);
        }

        if ($select) {
            $hours = collect($hours)->map(function ($item) {
                return [
                    $item => $item
                ];
            })->collapse()->all();
        }

        return $hours;
    }
541618
public function getPeriod($date)
    {
        $resultPeriod = null;

        for ($i = count($this->periods) - 1; $i >= 0; $i--) {
            $period = $this->periods[$i];

            if ($period->getEffectiveFrom() <= $date) {
                $resultPeriod = $period;
            }
        }

        return $resultPeriod;
    }
742987
public static function rangeThisWeek()
    {
        $ts = strtotime(date('Y-m-d')) + 86400;
        do {
            $ts -= 86400;
            $startDate = date('N', $ts);
        } while ($startDate != '1');

        return [$ts, $ts + (86400 * 6)];
    }
15312
public static function firstDayOfQuarter($ts = null)
	{
		// default to now
		if ($ts === null) $ts = sfDateTimeToolkit::now();
		
		// variables for computation
		$month = date('m', $ts);
		$quarter = ceil($month / 3) - 1; // zero based quarter
		
		return sfTime::subtractMonth(sfTime::firstDayOfMonth($ts), $month - ($quarter * 3) - 1);
	}
1218578
def last_quarter():
        
        since, until = Date.this_quarter()
        since = since.date - delta(months=3)
        until = until.date - delta(months=3)
        return Date(since), Date(until)