ottosmops / antondate
Date which are used for Anton
v0.0.4
2023-01-11 11:29 UTC
Requires
Requires (Dev)
- orchestra/testbench: ^7
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-04 14:46:34 UTC
README
Using Dates in Anton (anton.ch).
Installation
Via Composer
$ composer require ottosmops/antondate
Add date_start
, date_start_ca
, date_end
, date_end_ca
to the database table.
Add the casts to the model:
protected $casts = [ 'anton_date_interval' => AntonDateIntervalCast::class, 'anton_date_start' => AntonDateStartCast::class, 'anton_date_end' => AntonDateEndCast::class, ];
Usage
The package covers two ValueObjects: AntonDate, AntonDateInterval (consisting of two AntonDates).
Create an AntonDate
AntonDate::createFromString('1995-03-01', 1) : AntonDate // ca. 1995-03-01 AntonDate::guessFromString('4. Mai 1905') : AntonDate // 1905-05-04 AntonDate::compose(1973, 12, 3, 1) : AntonDate // ca. 1973-12-03 AntonDate::today() : AntonDate
Validate
AntonDate::isValidString('1997-13-01'); // false AntonDate::isValidString('ca. 1997-11-01'); // true
Get
$antondate->toString(); $antondate->toArray(); $antondate->formatted(); $antondate->toMysqlDate(); $antondate->getCa(); $antondate->getYear(); $antondate->getMonth(); $antondate->getDay();
Compare
$antondate->isEqualTo($antondate2, true); // compare with ca
$antondate->isEqualTo($antondate2); // compare without ca
$antondate->isGreaterThan($antondate2);
$antondate->isLessThan($antondate2);
Rule
There is also a rule. Which you can use for validation: AntonDateRule::class
.
License
MIT. Please see the license file for more information.