Core\Time\Zone
A time zone, such as Europe/Berlin or a fixed offset like +02:00. Every conversion between an Instant and a DateTime needs one, and there is no default zone. Zone::of finds a zone by its name, Zone::fixed makes one from an offset, and offsetAt returns the offset at one instant.
A Zone turns an Instant into a date and a time of day, and back. A zone that is fixed in the code is written as text where a Zone is expected: $instant->in('Europe/Berlin'). The name is checked when the program compiles, and the zone is built once. UTC and an offset such as '+05:30' are written the same way.
Zone::of($name) looks up a name that arrives while the program runs, such as a user's setting. It throws an error for a name the time zone database does not have. Zone::fixed is a constant offset with no daylight saving rules. There is no default zone: Zone::system() returns the zone of the host, and the program passes it on. A zone with daylight saving time has no single offset, so offsetAt needs the instant.
<?nvsvar $berlin = Core\Time\Zone::of('Europe/Berlin');var $jan = Core\Time\Instant::fromIso('2024-01-15T12:00:00Z');var $jul = Core\Time\Instant::fromIso('2024-07-15T12:00:00Z');echo $berlin->offsetAt($jan), "\n";echo $berlin->offsetAt($jul), "\n";echo $jul->in('Europe/Berlin')->format('HH:mm xxx VV'), "\n";
var $india = Core\Time\Zone::fixed(5h30m);echo $jul->in($india)->format('HH:mm xxx'), "\n";echo Core\Time\Zone::UTC->offsetAt($jul)->toSeconds(), "\n";
echo Core\Time\DateTime::fromIso('2024-07-15 14:00', $berlin)->toInstant()->toIso(), "\n";
string $saved = 'Mars/Olympus';try { Core\Time\Zone::of($saved);} catch (RuntimeError $unknown) { echo "not in the database\n";}1h2h14:00 +02:00 Europe/Berlin17:30 +05:3002024-07-15T12:00:00Znot in the databaseReturned by
You get a Core\Time\Zone from these methods:
Members
4 members.
| Member | Signature |
|---|---|
of | of(string $id): Core\Time\Zone |
fixed | fixed(Core\Time\Duration $offset): Core\Time\Zone |
system | system(): Core\Time\Zone |
offsetAt | offsetAt(Core\Time\Instant $i): Core\Time\Duration |
Constants
Core\Time\Zone::UTCThe UTC zone — the only zone that is ever a default, and only where a call site writes it explicitly.
