raxos / datetime
Datetime primitives and utilities for Raxos.
Requires
- php: >=8.5
- cakephp/chronos: ^3.3
- jetbrains/phpstorm-attributes: ^1.2
- raxos/foundation: *
Requires (Dev)
- pestphp/pest: ^5.0
- raxos/database: *
- raxos/http: *
Suggests
- raxos/database: to use the built-in casters.
- raxos/http: to use the built-in constraints.
Provides
None
Conflicts
None
Replaces
None
README
Raxos DateTime
Immutable date, time and timestamp objects built on CakePHP Chronos.
Documentation | Packagist | Raxos
Date,TimeandDateTimewith Chronos arithmetic and formatting.- JSON serialization and parsing through
StringParsableInterface. - Month and weekday enums, date utilities and ORM casters.
Installation
Requires PHP 8.5 or later. Composer checks the remaining package and extension dependencies declared in composer.json.
composer require "raxos/datetime:^3.2"
Usage
<?php declare(strict_types=1); use Raxos\DateTime\Date; use Raxos\DateTime\DateTime; use Raxos\DateTime\Time; require __DIR__ . '/vendor/autoload.php'; $date = Date::parse('2026-10-03'); $tomorrow = $date->addDays(1); $time = Time::parse('14:30:00'); $moment = DateTime::parse('2026-10-03 14:30:00', 'UTC'); echo json_encode(['date' => $tomorrow, 'time' => $time, 'moment' => $moment]);
Arithmetic returns new instances. Choose a timezone explicitly for timestamps; Date represents a calendar date and Time a time of day. Use the ORM casters with raxos/database installed.
Documentation
Testing
Run this library's Pest suite from the Raxos workspace:
git clone --recurse-submodules https://github.com/basmilius/raxos.git
cd raxos
composer install
vendor/bin/pest --testsuite=datetime
See Testing Raxos for PHP extensions, integration services and coverage commands. The library's Tests workflow also runs in GitHub Actions.
License
MIT. Copyright (c) 2017 - present Bas Milius.