apie/date-value-objects

Composer package of the apie library: date value objects

dev-main 2022-09-07 14:00 UTC

This package is auto-updated.

Last update: 2024-04-20 20:05:58 UTC


README

apie-logo.svg

date-value-objects

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require Code coverage

PHP Composer

This package is part of the Apie library. The code is maintained in a monorepo, so PR's need to be sent to the monorepo

Documentation

This package contains many Date-related value objects. Why do you want to use these value objects over DateTimeImmutable in PHP? The thing is that DateTime always contains days, months, years, minutes, seconds, hours, a timezone and microseconds. But in most cases we only use some.

By using these value objects over the PHP datetime objects we can tell if the date format we expect is actually using all these properties.

Available classes

DateWithTimezone: contains years, months, days, hours, seconds and also timezones. They should be in the format as DateTime::ATOM as a standard.

HourAndMinutes: contains a timestamp with only hours and minutes. It's still possible to call nextMinute 60 time or nextSecond 3600 time to advance an hour here.

LocalDate: contains a date with the format in a local date format, for example '2002-12-31' for 31 december 2002.

Time: contains a timestamp with only hours, minutes and seconds.

UnixTimestamp: contains a Unix timestamp.

Interfaces

WorksWithDays: contains a list of methods to work with days.

WorksWithMonths: contains a list of methods to work with months. Internally it stores a un-normalized day value in case someone uses nextMonth() or previousMonth() too many times in a row.

WorksWithTimeIntervals: contains a list of methods to work with time periods.

WorksWithYears: contains a list of methods to work with year counting.