rbroen/datetime-practical

A practical way at looking at datetime events

Maintainers

Package info

github.com/rbroen/datetime-practical

pkg:composer/rbroen/datetime-practical

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-05-06 18:21 UTC

This package is auto-updated.

Last update: 2026-05-06 18:26:28 UTC


README

This library provides a useful object with a start moment and an end moment.

When using start and end in a full day mode, the start and end time should be 00:00:00, with the end date on the day AFTER the last full day. When displaying and/or editing as a full days, the code should present the last full day without the time.

Install

To install with composer:

composer require rbroen/datetime-practical

Requires PHP 8.2 or newer.

Usage

Here's a basic usage example:

<?php

require '/path/to/vendor/autoload.php';

$start = new DateTimeImmutable();

// This creates an event starting now and lasting 4 days and 4 hours.
$event = new \DateTimePractical\DateEvent($start, 'P4DT4H');

// This is an example with full days
$start = (new DateTimeImmutable())->modify('midnight');

$event = new \DateTimePractical\DateEvent($start, 'P4D', true);
$displayStr = (string) $event;