Oihana PHP

hasLiteralZulu.php

Table of Contents

Functions

hasLiteralZulu()  : bool
Tells whether a date format pattern carries a **literal** `Z`, the ISO-8601 designator for UTC.

Functions

hasLiteralZulu()

Tells whether a date format pattern carries a **literal** `Z`, the ISO-8601 designator for UTC.

hasLiteralZulu(string $format) : bool

A pattern ending on an escaped Z'Y-m-d\TH:i:s.v\Z', the default of formatDateTime() — asserts that the moment it renders is expressed in UTC. That is what lets formatDateTime() convert the moment before formatting it, rather than stamping a wall clock with a suffix that lies about it.

The distinction the naive str_contains( $format , '\Z' ) misses is the escaped backslash : in '\\\\Z' the backslash escapes a backslash, leaving Z as the native token for the timezone offset in seconds — not a Zulu designator. Walking the pattern and stepping over whatever follows an escape tells the two apart.

Parameters
$format : string

A format string compatible with DateTime::format().

Tags
example
use function oihana\core\date\hasLiteralZulu;

var_dump( hasLiteralZulu( 'Y-m-d\TH:i:s.v\Z' ) ) ; // true  — Zulu designator
var_dump( hasLiteralZulu( 'Y-m-d\TH:i:sP'    ) ) ; // false — a real offset token
var_dump( hasLiteralZulu( 'Y-m-d\TH:i:s'     ) ) ; // false — no timezone at all
var_dump( hasLiteralZulu( 'Z'                ) ) ; // false — the native offset token
var_dump( hasLiteralZulu( '\\\\Z'            ) ) ; // false — escaped backslash, then the token
author

Marc Alcaraz (ekameleon)

since
1.2.0
Return values
bool

True when the pattern contains an escaped Z, false otherwise.

On this page

Search results