PHP code example of ottosmops / antondate

1. Go to this page and download the library: Download ottosmops/antondate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ottosmops / antondate example snippets


use Ottosmops\Antondate\Lang;

Lang::setLocale('de');

protected $casts = [
    'anton_date_interval' => AntonDateIntervalCast::class,
    'anton_date_start' => AntonDateStartCast::class,
    'anton_date_end' => AntonDateEndCast::class,
];

AntonDate::createFromString('1995-03-01', 1) : AntonDate
// ca. 1995-03-01

AntonDate::guessFromString('4. Mai 1905') : AntonDate
// 1905-05-04, also '4.5.1905' and '4. Mai. 1905'
// throws an InvalidArgumentException for a date that does not exist ('31.02.1900')

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->intervalIsAfter($antondate2); // '1923-05-15' is not after '1923', but after '1922'
$antondate->isGreaterThan($antondate2); // compares YYYYMMDD with missing parts as 00
$antondate->isLessThan($antondate2);

use Ottosmops\Antondate\DateHelper;

DateHelper::renderDate('0958-00-00', 1, '1050-03-01', 0); // 'ca. 958 – 1. Mär 1050'
DateHelper::formatDate('0000-06-16');                    // '16. Juni' (no year)
DateHelper::parseDateString('2. April 2014');            // '2014-04-02'
DateHelper::cleanDate('1923-05-00');                     // '1923-05'
DateHelper::composeDate(1923, 5, 0);                     // '1923-05-00'
DateHelper::joinNormalDate('1893', '0000');              // '1893' (apeEAD unitdate normal)
DateHelper::unpadYears('3. Mai 0958');                   // '3. Mai 958'

use Ottosmops\Antondate\Rules\AntonDateRule;

// Strict mode (default) - uses AntonDate::createFromString()
new AntonDateRule()
new AntonDateRule(strict: true)

// Non-strict mode - uses AntonDate::guessFromString()
new AntonDateRule(strict: false)