Using Dates in Anton (anton.ch).
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,
];
The package covers two ValueObjects: AntonDate, AntonDateInterval (consisting of two AntonDates).
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
AntonDate::isValidString('1997-13-01'); // false
AntonDate::isValidString('ca. 1997-11-01'); // true
$antondate->toString();
$antondate->toArray();
$antondate->formatted();
$antondate->toMysqlDate();
$antondate->getCa();
$antondate->getYear();
$antondate->getMonth();
$antondate->getDay();
$antondate->isEqualTo($antondate2, true); // compare with ca
$antondate->isEqualTo($antondate2); // compare without ca
$antondate->isGreaterThan($antondate2);
$antondate->isLessThan($antondate2);
There is also a rule. Which you can use for validation: AntonDateRule::class
.
MIT. Please see the license file for more information.