📅 Brzuchal\DateTime is a lightweight, dependency-free date handling library for PHP, inspired by java.time.
It provides immutable date objects with clear and type-safe APIs — without relying on PHP’s ext-date.
To install via Composer, run:
composer require brzuchal/datetimeRepresents an ISO-8601 date (proleptic Gregorian) without time or timezone.
use Brzuchal\DateTime\LocalDate;
$date = LocalDate::of(2023, 5, 10);
echo $date->year; // 2023
echo $date->month; // 5
echo $date->day; // 10
echo $date->era; // Brzuchal\DateTime\CalendarSystems\IsoEra::CommonEra
echo (string) $date; // "2023-05-10"$date = LocalDate::of(2023, 5, 10);
$date->plusDays(5); // 2023-05-15
$date->minusDays(3); // 2023-05-07
$date->plusMonths(1); // 2023-06-10
$date->plusYears(2); // 2025-05-10
Use Period to encapsulate year/month/day offsets.
use Brzuchal\DateTime\Period;
$period = Period::of(years: 1, months: 2, days: 10);
$date = LocalDate::of(2023, 5, 10);
$date->plus($period); // 2024-07-20
$date->minus($period); // 2022-03-00 → adjusted to 2022-02-28
The epochDay property (number of days since 1970-01-01) is calculated on demand only:
$date = LocalDate::of(2023, 5, 10);
echo $date->epochDay; // 19182
The constructor checks:
- that month is in range 1–12,
- that day is valid for the given month (including leap years).
LocalDate and friends are intentionally ISO-only, backed by static ISO calendar logic.
No PHP ext-date types are used anywhere.
IsoCalendaris the single source of proleptic Gregorian (ISO-8601) math and exposes static helpers for conversions.- Era information is represented by the
IsoEraenum and surfaced lazily onLocalDateinstances.
LocalTime,LocalDateTimeZonedDateTimewith timezone support- Full
TemporalField/TemporalAccessorsupport - Range types like
DateIntervalorDateRange
MIT License
Copyright (c) 2025 Michał Brzuchalski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.