PHP code example of caronc / dateblock

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

    

caronc / dateblock example snippets



// Returns the moment it will unblock at (a DateTimeImmutable)
$result = dateblock('* /20', block: false);
echo 'Blocking until ', $result->format('Y-m-d H:i:s'), "\n";
dateblock('* /20');

// Work it out from another moment (a DateTime, DateTimeImmutable or
// seconds since the epoch)
$result = dateblock('* /20', false, new DateTimeImmutable('-4 days'));
$result = dateblock('/5', false, 13424236);

// A regular crontab entry: the start of each minute
$result = dateblock('* * * * *', isc: true);

// A negative drift wakes up early: 6 days before 9:00 on December 25th
$result = dateblock('0 0 9 25 12 * -518400', block: false);

// Timezones: the cron is read in the timezone of the reference, and the
// result comes back in that same timezone.  This waits for 9:00 in Tokyo.
$tokyo = new DateTimeImmutable('now', new DateTimeZone('Asia/Tokyo'));
$result = dateblock('0 0 9', ref: $tokyo);


foreach (dateblock_upcoming('0 9 * * Mon-Fri', 3, isc: true) as $when) {
    echo $when->format('D Y-m-d H:i'), "\n";
}