protected function getStartAndEndDate($date)
    {
        $year = $month = $day = null;

        //Sets the start date
        if (in_array($date, ['today', 'yesterday'])) {
            $start = Time::parse($date);
        } else {
            list($year, $month, $day) = array_replace([null, null, null], explode('/', $date));
            $start = Time::now()->setDate($year, $month ?: 1, $day ?: 1);
        }

        $start = $start->setTime(0, 0, 0);
        $end = Time::parse($start);

        if (($year && $month && $day) || in_array($date, ['today', 'yesterday'])) {
            $end = $end->addDay(1);
        } else {
            $end = $year && $month ? $end->addMonth(1) : $end->addYear(1);
        }

        return [$start, $end];
    }
protected function getStartAndEndDate($date)
    {
        $year = $month = $day = null;

        //Sets the start date
        if (in_array($date, ['today', 'yesterday'])) {
            $start = Time::parse($date);
        } else {
            list($year, $month, $day) = array_replace([null, null, null], explode('/', $date));
            $start = Time::now()->setDate($year, $month ?: 1, $day ?: 1);
        }

        $start = $start->setTime(0, 0, 0);
        $end = Time::parse($start);

        if (($year && $month && $day) || in_array($date, ['today', 'yesterday'])) {
            $end = $end->addDay(1);
        } else {
            $end = $year && $month ? $end->addMonth(1) : $end->addYear(1);
        }

        return [$start, $end];
    }
protected function getStartAndEndDate ( $ date ) { $ year = $ month = $ day = null ; //Sets the start date if ( in_array ( $ date , [ 'today' , 'yesterday' ] ) ) { $ start = Time :: parse ( $ date ) ; } else { list ( $ year , $ month , $ day ) = array_replace ( [ null , null , null ] , explode ( '/' , $ date ) ) ; $ start = Time :: now ( ) -> setDate ( $ year , $ month ? : 1 , $ day ? : 1 ) ; } $ start = $ start -> setTime ( 0 , 0 , 0 ) ; $ end = Time :: parse ( $ start ) ; if ( ( $ year && $ month && $ day ) || in_array ( $ date , [ 'today' , 'yesterday' ] ) ) { $ end = $ end -> addDay ( 1 ) ; } else { $ end = $ year && $ month ? $ end -> addMonth ( 1 ) : $ end -> addYear ( 1 ) ; } return [ $ start , $ end ] ; }
Gets start and end date as `Time` instances starting from a string.
These can be used for a `where` condition to search for records based on
a date.
@param string $date Date as `today`, `yesterday`, `YYYY/MM/dd`,
`YYYY/MM` or `YYYY`
@return array Array with start and end date as `Time` instances
Gets start and end date as Time instances starting from a string . These can be used for a where condition to search for records based on a date .