PHP code example of michaeldrennen / natural-date

1. Go to this page and download the library: Download michaeldrennen/natural-date 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/ */

    

michaeldrennen / natural-date example snippets

  
$naturalDate = NaturalDate::parse( "Early 2016", 'America/Phoenix' );  
echo $naturalDate->toJson();

$naturalDate = NaturalDate::parse( "between thanksgiving and christmas 2017", 'America/Phoenix' );

// $localStartDateTime will be a Carbon object.
$localStartDateTime = $naturalDate->getLocalStart();
echo $localStartDateTime; // '2017-11-23 00:00:00'


// $utcStartDateTime will be a Carbon object.
$utcStartDateTime = $naturalDate->getUtcStart();
echo $utcStartDateTime; // '2017-11-23 07:00:00'


// $localEndDateTime will be a Carbon object as well.
$localEndDateTime = $naturalDate->getLocalEnd();
echo $localEndDateTime; // '2017-12-31 23:59:59'


// $utcEndDateTime will be a Carbon object.
$utcEndDateTime = $naturalDate->getUtcEnd();
echo $utcEndDateTime; // '2018-01-01 06:59:59'

echo $naturalDate->getType(); // 'range'



use MichaelDrennen\NaturalDate\PatternModifiers\PatternModifier;
use MichaelDrennen\NaturalDate\NaturalDate;


class JohnMcClanesBirthday extends PatternModifier {

    protected $patterns = [
        "/john mcclane\'s birthday/i",
        "/john mcclanes birthday/i",
        "/john mcclane birthday/i",
    ];


    public function modify( NaturalDate $naturalDate ): NaturalDate {
        $naturalDate->setStartYear( 1955 );
        $naturalDate->setStartMonth( 11 );
        $naturalDate->setStartDay( 2 );
        $naturalDate->setStartHour( 0 );
        $naturalDate->setStartMinute( 0 );
        $naturalDate->setStartSecond( 0 );

        $naturalDate->setEndYear( 1955 );
        $naturalDate->setEndMonth( 11 );
        $naturalDate->setEndDay( 2 );
        $naturalDate->setEndHour( 23 );
        $naturalDate->setEndMinute( 59 );
        $naturalDate->setEndSecond( 59 );

        $naturalDate->setType( NaturalDate::date );

        return $naturalDate;
    }
}