PHP code example of mic2100 / fuzzy-time

1. Go to this page and download the library: Download mic2100/fuzzy-time 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/ */

    

mic2100 / fuzzy-time example snippets

lang=php
use Mic2100\FuzzyTime\GeneratorAwareTrait;
use Mic2100\FuzzyTime\GeneratorFactory;
use Mic2100\FuzzyTime\Language\Dictionaries\English;
use Mic2100\FuzzyTime\Language\Dictionaries\German;
use Mic2100\FuzzyTime\Language\LanguageFactory;

date_default_timezone_set('Europe/London');

$factory = new GeneratorFactory();
$english = $factory->get(); //or $factory->get(LanguageFactory::get(English::HANDLE);  
$german = $factory->get(LanguageFactory::get(German::HANDLE));

class SampleClass
{
    use GeneratorAwareTrait;
}

$traitClass = new SampleClass();

while (true) {
    echo $english->getFuzzyTime() . PHP_EOL;
    echo $german->getFuzzyTime() . PHP_EOL;
    echo $traitClass->getFuzzyTime((new DateTime('-25 MINS'))) . PHP_EOL;
    sleep(30);
}

/*----------------------------------------------
 * Example Output
 *
 * five to one //$english->getFuzzyTime()
 * fünf vor ein //$german->getFuzzyTime()
 * half to twelve //$traitClass->getFuzzyTime((new DateTime('-25 MINS')), LanguageFactory::get(English::HANDLE))
 *
 * or
 *
 * three o'clock //$english->getFuzzyTime()
 * drei uhr //$german->getFuzzyTime()
 * twenty five to three //$traitClass->getFuzzyTime((new DateTime('-25 MINS')), LanguageFactory::get(English::HANDLE))
 */