1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace FG\ASN1\Universal;
- use FG\ASN1\AbstractTime;
- use FG\ASN1\Parsable;
- use FG\ASN1\Identifier;
- use FG\ASN1\Exception\ParserException;
- class UTCTime extends AbstractTime implements Parsable
- {
- public function getType()
- {
- return Identifier::UTC_TIME;
- }
- protected function calculateContentLength()
- {
- return 13;
- }
- protected function getEncodedValue()
- {
- return $this->value->format('ymdHis').'Z';
- }
- public static function fromBinary(&$binaryData, &$offsetIndex = 0)
- {
- self::parseIdentifier($binaryData[$offsetIndex], Identifier::UTC_TIME, $offsetIndex++);
- $contentLength = self::parseContentLength($binaryData, $offsetIndex, 11);
- $format = 'ymdGi';
- $dateTimeString = substr($binaryData, $offsetIndex, 10);
- $offsetIndex += 10;
-
- if ($binaryData[$offsetIndex] != 'Z'
- && $binaryData[$offsetIndex] != '+'
- && $binaryData[$offsetIndex] != '-') {
- $dateTimeString .= substr($binaryData, $offsetIndex, 2);
- $offsetIndex += 2;
- $format .= 's';
- }
- $dateTime = \DateTime::createFromFormat($format, $dateTimeString, new \DateTimeZone('UTC'));
-
- if ($binaryData[$offsetIndex] == '+'
- || $binaryData[$offsetIndex] == '-') {
- $dateTime = static::extractTimeZoneData($binaryData, $offsetIndex, $dateTime);
- } elseif ($binaryData[$offsetIndex++] != 'Z') {
- throw new ParserException('Invalid UTC String', $offsetIndex);
- }
- $parsedObject = new self($dateTime);
- $parsedObject->setContentLength($contentLength);
- return $parsedObject;
- }
- }
|