theoaks / relative-datetime-format-builder
Object Oriented approach to building the different relative date/time formats that the strtotime(), DateTime and date_create() parser understands.
Installs: 1 009
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- webmozart/assert: ^1.10
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-05-28 10:54:24 UTC
README
Object-Oriented approach to building the different relative date/time formats that the strtotime(), DateTime and date_create() parser understands. Check The PHP Documentation for details
How to install
Install using composer
composer require theoaks/relative-datetime-format-builder
How to use
use Oaks\RelativeDatetimeFormatBuilder\RelativeDateTimeFormatBuilder; $first_day_of_january = RelativeDateTimeFormatBuilder::firstDayOf( MonthName::January ); echo $first_day_of_january; $date = $first_day_of_january->toDateTime(); echo $date->format("y-M-d"); /// first day of January this year /// YYYY-01-01 $three_days_from_now = (new RelativeDateTimeFormatBuilder())->addDays(3); echo $three_days_from_now; $date = $three_days_from_now->toDateTime(); $date_immutable = $three_days_from_now->toDateTimeImmutable(); /// +3 day // First day of march 2025 at 11am $format = (new RelativeDateTimeFormatBuilder()) ->firstDay() ->ofMarch() ->year(2025) ->at(hour: 11); echo $format; // first day of March 2025 11:00:00