public static function parseDate($string, $direction = null, $equal_to = false)
    {
        $parts = array(
            'start' => null,
            'end' => null
        );

        // Year
        if (preg_match('/^\d{1,4}$/', $string, $matches)) {
            $year = current($matches);

            $parts['start'] = "$year-01-01 00:00:00";
            $parts['end'] = "$year-12-31 23:59:59";

            $parts = self::isEqualTo($parts, $direction, $equal_to);

            // Year/Month/Day/Time
        } elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}\s\d{1,2}:\d{2}/', $string, $matches)) {
            // Handles the case of `to` filters
            if ($equal_to || is_null($direction)) {
                $parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
            } else {
                $parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
                $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
            }

            // Year/Month/Day
        } elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}$/', $string, $matches)) {
            $year_month_day = current($matches);

            $parts['start'] = "$year_month_day 00:00:00";
            $parts['end'] = "$year_month_day 23:59:59";

            $parts = self::isEqualTo($parts, $direction, $equal_to);

            // Year/Month
        } elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}$/', $string, $matches)) {
            $year_month = current($matches);

            $parts['start'] = "$year_month-01 00:00:00";
            $parts['end'] = DateTimeObj::get('Y-m-t', $parts['start']) . " 23:59:59";

            $parts = self::isEqualTo($parts, $direction, $equal_to);

            // Relative date, aka '+ 3 weeks'
        } else {
            // Handles the case of `to` filters

            if ($equal_to || is_null($direction)) {
                $parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
            } else {
                $parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
                $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
            }
        }

        return $parts;
    }
public static function parseDate($string, $direction = null, $equal_to = false)
    {
        $parts = array(
            'start' => null,
            'end' => null
        );

        // Year
        if (preg_match('/^\d{1,4}$/', $string, $matches)) {
            $year = current($matches);

            $parts['start'] = "$year-01-01 00:00:00";
            $parts['end'] = "$year-12-31 23:59:59";

            $parts = self::isEqualTo($parts, $direction, $equal_to);

            // Year/Month/Day/Time
        } elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}\s\d{1,2}:\d{2}/', $string, $matches)) {
            // Handles the case of `to` filters
            if ($equal_to || is_null($direction)) {
                $parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
            } else {
                $parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
                $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
            }

            // Year/Month/Day
        } elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}$/', $string, $matches)) {
            $year_month_day = current($matches);

            $parts['start'] = "$year_month_day 00:00:00";
            $parts['end'] = "$year_month_day 23:59:59";

            $parts = self::isEqualTo($parts, $direction, $equal_to);

            // Year/Month
        } elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}$/', $string, $matches)) {
            $year_month = current($matches);

            $parts['start'] = "$year_month-01 00:00:00";
            $parts['end'] = DateTimeObj::get('Y-m-t', $parts['start']) . " 23:59:59";

            $parts = self::isEqualTo($parts, $direction, $equal_to);

            // Relative date, aka '+ 3 weeks'
        } else {
            // Handles the case of `to` filters

            if ($equal_to || is_null($direction)) {
                $parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
            } else {
                $parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
                $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
            }
        }

        return $parts;
    }
public static function parseDate ( $ string , $ direction = null , $ equal_to = false ) { $ parts = array ( 'start' => null , 'end' => null ) ; // Year if ( preg_match ( '/^\d{1,4}$/' , $ string , $ matches ) ) { $ year = current ( $ matches ) ; $ parts [ 'start' ] = "$year-01-01 00:00:00" ; $ parts [ 'end' ] = "$year-12-31 23:59:59" ; $ parts = self :: isEqualTo ( $ parts , $ direction , $ equal_to ) ; // Year/Month/Day/Time } elseif ( preg_match ( '/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}\s\d{1,2}:\d{2}/' , $ string , $ matches ) ) { // Handles the case of `to` filters if ( $ equal_to || is_null ( $ direction ) ) { $ parts [ 'start' ] = $ parts [ 'end' ] = DateTimeObj :: get ( 'Y-m-d H:i:s' , $ string ) ; } else { $ parts [ 'start' ] = DateTimeObj :: get ( 'Y-m-d H:i:s' , $ string . ' - 1 second' ) ; $ parts [ 'end' ] = DateTimeObj :: get ( 'Y-m-d H:i:s' , $ string . ' + 1 second' ) ; } // Year/Month/Day } elseif ( preg_match ( '/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}$/' , $ string , $ matches ) ) { $ year_month_day = current ( $ matches ) ; $ parts [ 'start' ] = "$year_month_day 00:00:00" ; $ parts [ 'end' ] = "$year_month_day 23:59:59" ; $ parts = self :: isEqualTo ( $ parts , $ direction , $ equal_to ) ; // Year/Month } elseif ( preg_match ( '/^\d{1,4}[-\/]\d{1,2}$/' , $ string , $ matches ) ) { $ year_month = current ( $ matches ) ; $ parts [ 'start' ] = "$year_month-01 00:00:00" ; $ parts [ 'end' ] = DateTimeObj :: get ( 'Y-m-t' , $ parts [ 'start' ] ) . " 23:59:59" ; $ parts = self :: isEqualTo ( $ parts , $ direction , $ equal_to ) ; // Relative date, aka '+ 3 weeks' } else { // Handles the case of `to` filters if ( $ equal_to || is_null ( $ direction ) ) { $ parts [ 'start' ] = $ parts [ 'end' ] = DateTimeObj :: get ( 'Y-m-d H:i:s' , $ string ) ; } else { $ parts [ 'start' ] = DateTimeObj :: get ( 'Y-m-d H:i:s' , $ string . ' - 1 second' ) ; $ parts [ 'end' ] = DateTimeObj :: get ( 'Y-m-d H:i:s' , $ string . ' + 1 second' ) ; } } return $ parts ; }
Given a string, this function builds the range of dates that match it.
The strings should be in ISO8601 style format, or a natural date, such
as 'last week' etc.

@since Symphony 2.2.2
@param array $string
The date string to be parsed
@param string $direction
Either later or earlier, defaults to null.
@param boolean $equal_to
If the filter is equal_to or not, defaults to false.
@return array
An associative array containing a date in ISO8601 format (or natural)
with two keys, start and end.
Given a string this function builds the range of dates that match it . The strings should be in ISO8601 style format or a natural date such as last week etc .