private function parseRequestDate($date)
    {
        $timezone = new \DateTimeZone("UTC");
        $granularity = null;

        if (preg_match('#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$#', $date)) {
            $parsedDate = date_create_from_format('Y-m-d\TH:i:s\Z', $date, $timezone);
            $granularity = Identity::GRANULARITY_YYYY_MM_DDTHH_MM_SSZ;
        } elseif (preg_match('#^\d{4}-\d{2}-\d{2}$#', $date)) {
            // Add ! to format to set time to 00:00:00
            $parsedDate = date_create_from_format('!Y-m-d', $date, $timezone);
            $granularity = Identity::GRANULARITY_YYYY_MM_DD;
        } else {
            throw new BadArgumentException("Expected a data in one of the following formats: " .
                Identity::GRANULARITY_YYYY_MM_DDTHH_MM_SSZ . " OR " .
                Identity::GRANULARITY_YYYY_MM_DD ." FOUND " . $date);
        }

        $parseResult = date_get_last_errors();
        if (!$parsedDate || ($parseResult['error_count'] > 0) || ($parseResult['warning_count'] > 0)) {
            throw new BadArgumentException("$date is not a valid date");
        }

        return [$parsedDate, $granularity];
    }
private function parseRequestDate($date)
    {
        $timezone = new \DateTimeZone("UTC");
        $granularity = null;

        if (preg_match('#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$#', $date)) {
            $parsedDate = date_create_from_format('Y-m-d\TH:i:s\Z', $date, $timezone);
            $granularity = Identity::GRANULARITY_YYYY_MM_DDTHH_MM_SSZ;
        } elseif (preg_match('#^\d{4}-\d{2}-\d{2}$#', $date)) {
            // Add ! to format to set time to 00:00:00
            $parsedDate = date_create_from_format('!Y-m-d', $date, $timezone);
            $granularity = Identity::GRANULARITY_YYYY_MM_DD;
        } else {
            throw new BadArgumentException("Expected a data in one of the following formats: " .
                Identity::GRANULARITY_YYYY_MM_DDTHH_MM_SSZ . " OR " .
                Identity::GRANULARITY_YYYY_MM_DD ." FOUND " . $date);
        }

        $parseResult = date_get_last_errors();
        if (!$parsedDate || ($parseResult['error_count'] > 0) || ($parseResult['warning_count'] > 0)) {
            throw new BadArgumentException("$date is not a valid date");
        }

        return [$parsedDate, $granularity];
    }
private function parseRequestDate ( $ date ) { $ timezone = new \ DateTimeZone ( "UTC" ) ; $ granularity = null ; if ( preg_match ( '#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$#' , $ date ) ) { $ parsedDate = date_create_from_format ( 'Y-m-d\TH:i:s\Z' , $ date , $ timezone ) ; $ granularity = Identity :: GRANULARITY_YYYY_MM_DDTHH_MM_SSZ ; } elseif ( preg_match ( '#^\d{4}-\d{2}-\d{2}$#' , $ date ) ) { // Add ! to format to set time to 00:00:00 $ parsedDate = date_create_from_format ( '!Y-m-d' , $ date , $ timezone ) ; $ granularity = Identity :: GRANULARITY_YYYY_MM_DD ; } else { throw new BadArgumentException ( "Expected a data in one of the following formats: " . Identity :: GRANULARITY_YYYY_MM_DDTHH_MM_SSZ . " OR " . Identity :: GRANULARITY_YYYY_MM_DD . " FOUND " . $ date ) ; } $ parseResult = date_get_last_errors ( ) ; if ( ! $ parsedDate || ( $ parseResult [ 'error_count' ] > 0 ) || ( $ parseResult [ 'warning_count' ] > 0 ) ) { throw new BadArgumentException ( "$date is not a valid date" ) ; } return [ $ parsedDate , $ granularity ] ; }
Converts a date coming from a request param and converts it to a \DateTime
@param string $date
@return [\DateTime, string]
@throws BadArgumentException when the date is invalid or not supplied in the right format
Converts a date coming from a request param and converts it to a \ DateTime