Core/src/TimeTrait.php
private function parseTimeString($timestamp)
    {
        $nanoRegex = '/\d{4}-\d{1,2}-\d{1,2}T\d{1,2}\:\d{1,2}\:\d{1,2}(?:\.(\d{1,}))?/';

        preg_match($nanoRegex, $timestamp, $matches);
        $subSeconds = isset($matches[1])
            ? $matches[1]
            : '0';

        if (strlen($subSeconds) > 6) {
            $timestamp = str_replace('.'. $subSeconds, '.' . substr($subSeconds, 0, 6), $timestamp);
        }

        $dt = new \DateTimeImmutable($timestamp);
        if (!$dt) {
            throw new \InvalidArgumentException(sprintf(
                'Could not create a DateTime instance from given timestamp %s.',
                $timestamp
            ));
        }

        $nanos = (int) str_pad($subSeconds, 9, '0', STR_PAD_RIGHT);

        return [$dt, $nanos];
    }
private function parseTimeString($timestamp)
    {
        $nanoRegex = '/\d{4}-\d{1,2}-\d{1,2}T\d{1,2}\:\d{1,2}\:\d{1,2}(?:\.(\d{1,}))?/';

        preg_match($nanoRegex, $timestamp, $matches);
        $subSeconds = isset($matches[1])
            ? $matches[1]
            : '0';

        if (strlen($subSeconds) > 6) {
            $timestamp = str_replace('.'. $subSeconds, '.' . substr($subSeconds, 0, 6), $timestamp);
        }

        $dt = new \DateTimeImmutable($timestamp);
        if (!$dt) {
            throw new \InvalidArgumentException(sprintf(
                'Could not create a DateTime instance from given timestamp %s.',
                $timestamp
            ));
        }

        $nanos = (int) str_pad($subSeconds, 9, '0', STR_PAD_RIGHT);

        return [$dt, $nanos];
    }
private function parseTimeString ( $ timestamp ) { $ nanoRegex = '/\d{4}-\d{1,2}-\d{1,2}T\d{1,2}\:\d{1,2}\:\d{1,2}(?:\.(\d{1,}))?/' ; preg_match ( $ nanoRegex , $ timestamp , $ matches ) ; $ subSeconds = isset ( $ matches [ 1 ] ) ? $ matches [ 1 ] : '0' ; if ( strlen ( $ subSeconds ) > 6 ) { $ timestamp = str_replace ( '.' . $ subSeconds , '.' . substr ( $ subSeconds , 0 , 6 ) , $ timestamp ) ; } $ dt = new \ DateTimeImmutable ( $ timestamp ) ; if ( ! $ dt ) { throw new \ InvalidArgumentException ( sprintf ( 'Could not create a DateTime instance from given timestamp %s.' , $ timestamp ) ) ; } $ nanos = ( int ) str_pad ( $ subSeconds , 9 , '0' , STR_PAD_RIGHT ) ; return [ $ dt , $ nanos ] ; }
Parse a Timestamp string and return a DateTimeImmutable instance and nanoseconds as an integer.

@param string $timestamp A string representation of a timestamp, encoded
in RFC 3339 format (YYYY-MM-DDTHH:MM:SS.000000[000]TZ).
@return array [\DateTimeImmutable, int]
@throws \InvalidArgumentException If the timestamp string is in an unrecognized format.
Parse a Timestamp string and return a DateTimeImmutable instance and nanoseconds as an integer .