arokettu/date

Date class for PHP (without time)

2.2.2 2024-07-28 19:08 UTC

This package is auto-updated.

Last update: 2024-11-13 00:47:09 UTC


README

PHP License GitLab CI Codecov

A class for php to work with pure dates (without time).

Installation

composer require arokettu/date

Usage

The library:

<?php

use Arokettu\Date\Calendar;
use Arokettu\Date\Date;
use Arokettu\Date\JulianCalendar;
use Arokettu\Date\Month;

// creation
$date = Date::today(); // example: 2024-02-27
// or
$date = Calendar::create(2024, Month::February, 27);
// or
$date = Calendar::fromDateTime(new DateTime('Feb 27, 2024')); // truncates time
// or
$date = Calendar::parse('2024-02-27'); // Y-m-d is expected, years can be negative
// or
$date = Calendar::parseDateTimeString('Feb 27, 2024');

// alternative calendars
$date = JulianCalendar::parse('2024-02-14');

// getters
$date->getDay(); // 27
$date->getMonth(); // Month::February
$date->getMonthNumber(); // 2
$date->getYear(); // 2024
$date->getWeekDay(); // WeekDay::Tuesday
$date->getJulianDay(); // 2460368
$date->toDateTime(); // DateTimeImmutable('2024-02-27') // midnight in a default timezone
$date->toString(); // "2024-02-27"

// alternative calendar getters
$date->julian()->getDay(); // 14
$date->julian()->toString(); // "2024-02-14"

Documentation

Read full documentation here: https://sandfox.dev/php/date.html

Also on Read the Docs: https://php-date.readthedocs.io/

Support

Please file issues on our main repo at GitLab: https://gitlab.com/sandfox/php-uuid/-/issues

Feel free to ask any questions in our room on Gitter: https://gitter.im/arokettu/community

License

The library is available as open source under the terms of the MIT License.