Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 11... Línea 11...
11
 * DateTime overrides that make DateTime work more seamlessly as a string,
11
 * DateTime overrides that make DateTime work more seamlessly as a string,
12
 * with JSON documents, and with JMESPath.
12
 * with JSON documents, and with JMESPath.
13
 */
13
 */
14
class DateTimeResult extends \DateTime implements \JsonSerializable
14
class DateTimeResult extends \DateTime implements \JsonSerializable
15
{
15
{
-
 
16
    private const ISO8601_NANOSECOND_REGEX = '/^(.*\.\d{6})(\d{1,3})(Z|[+-]\d{2}:\d{2})?$/';
-
 
17
 
16
    /**
18
    /**
17
     * Create a new DateTimeResult from a unix timestamp.
19
     * Create a new DateTimeResult from a unix timestamp.
18
     * The Unix epoch (or Unix time or POSIX time or Unix
20
     * The Unix epoch (or Unix time or POSIX time or Unix
19
     * timestamp) is the number of seconds that have elapsed since
21
     * timestamp) is the number of seconds that have elapsed since
20
     * January 1, 1970 (midnight UTC/GMT).
22
     * January 1, 1970 (midnight UTC/GMT).
Línea 58... Línea 60...
58
    {
60
    {
59
        if (is_numeric($iso8601Timestamp) || !is_string($iso8601Timestamp)) {
61
        if (is_numeric($iso8601Timestamp) || !is_string($iso8601Timestamp)) {
60
            throw new ParserException('Invalid timestamp value passed to DateTimeResult::fromISO8601');
62
            throw new ParserException('Invalid timestamp value passed to DateTimeResult::fromISO8601');
61
        }
63
        }
Línea -... Línea 64...
-
 
64
 
-
 
65
        // Prior to 8.0.10, nanosecond precision is not supported
-
 
66
        // Reduces to microsecond precision if nanosecond precision is detected
-
 
67
        if (PHP_VERSION_ID < 80010
-
 
68
            && preg_match(self::ISO8601_NANOSECOND_REGEX, $iso8601Timestamp, $matches)
-
 
69
        ) {
-
 
70
            $iso8601Timestamp = $matches[1] . ($matches[3] ?? '');
-
 
71
        }
62
 
72
 
63
        return new DateTimeResult($iso8601Timestamp);
73
        return new DateTimeResult($iso8601Timestamp);
Línea 64... Línea 74...
64
    }
74
    }
65
 
75