danbettles/php-medjool

Like PHP dates, only juicier

Maintainers

Package info

github.com/danbettles/php-medjool

pkg:composer/danbettles/php-medjool

Transparency log

Statistics

Installs: 30

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v4.0.0 2026-07-06 15:50 UTC

This package is auto-updated.

Last update: 2026-08-06 16:11:23 UTC


README

A simple extension of PHP's Date/Time module, to make working with dates and times a little smoother.

In general, I think Date/Time is actually pretty great. In some cases, though, things can feel a little clunky, so that's why Medjool is "like PHP dates, only juicier".

Overview

At Medjool's heart is the Date class, which is a Value Object—like DateTimeImmutable.

Of note:

  • The constructor accepts a date-time string, an integer timestamp, a DateTimeImmutable, or a DateTime, so there's no need to use different methods to create an instance.
  • Provides toIsoDateString(), toIsoDateTimeString(), toMysqlDateString(), and toMysqlDateTimeString() to easily format the date.
  • getComponents() returns all/selected date and time components in an associative array; getComponent() returns a single, specified date/time component.
  • startOf() and its alias, trunc(), returns a copy at the very start of the specified date component; endOf() returns a copy at the very end of the specified date component.
  • addTo() adds to the specified date component; subtractFrom() subtracts from the specified date component.
  • next() and previous() are shortcuts that call addTo() and subtractFrom(), respectively. next() adds 1 to the specified date component, whereas previous() subtracts 1.
  • isInPast() and isInFuture() simply read better.
  • setTimezone() gives you the option to preserve the time.
  • For convenience: ::tryFrom() creates an instance or returns null; ::tryFormat() (re)formats a date-ish or returns null.