All contributions

brick/date-time

brick/date-time

A PHP date and time library based on the java.time model, with separate types for an instant, a date, a time and a zoned date-time.

Language
PHP
GitHub stars
361
Merged changes
1

What we changed

Instant and ZonedDateTime always print the seconds in toISOString(), and so also in JSON and string casts, even when they are zero, as RFC 3339 requires.

What this work shows

  • RFC 3339 and ISO 8601 date formats
  • Serialising dates to JSON in PHP
  • PHPUnit data provider tests
What was broken

Whole minutes printed without seconds

Instant::toISOString() and ZonedDateTime::toISOString() used LocalTime's compact form, which drops zero seconds, so a whole minute came out as 2023-11-14T22:14Z. That is a valid ISO 8601 time but not RFC 3339, which requires seconds, and the same string went into JSON through jsonSerialize().

How we fixed it

Always HH:MM:SS in the interchange types

ZonedDateTime::toISOString() now builds the time itself, with mandatory seconds and the existing fraction handling, and Instant inherits the fix. LocalTime deliberately keeps its compact form, the parser still accepts the short input, and we updated the tests that pinned the old output and added whole-minute and whole-hour cases.

#131

Merged change 1

  1. #131 fix: emit full seconds in Instant and ZonedDateTime toISOString (RFC 3339) Merged 30 September 2026

What it taught us

An almost ISO 8601 format passes one parser and fails a strict RFC 3339 one. We can change the output format only in the types meant for data exchange, keep the compact form where it is intended, and fix the tests that pinned the bug.

More about this technology: PHP

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.