PHP code example of nickjbedford / calendar-timer

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

    

nickjbedford / calendar-timer example snippets


use \YetAnother\DayTimer;

$scheduler = new DayTimer('2021-01-04', 14);

// get next 3 dates from 1st February 2021
$dates = $scheduler->getDates(3, '2021-02-01'); 

// $dates = [
//   '2021-02-03'
//   '2021-02-17'
//   '2021-03-03'
// ]

use \YetAnother\CalendarTimer;

$date = '2020-01-04';

$weekly = CalendarTimer::weekly($date);
$fortnightly = CalendarTimer::fortnightly($date);
$monthly = CalendarTimer::monthly($date);
$biannual = CalendarTimer::sixMonthly($date);
$yearly = CalendarTimer::yearly($date);

use YetAnother\ScheduleFinder;
use YetAnother\Weekday;
use YetAnother\ScheduleAlgorithm;

$schedule = new ScheduleFinder(
    standardWorkdays: [ Weekday::Monday, Weekday::Wednesday, Weekday::Friday ],
    holidays: [ '2024-06-17' ],
    preferredCalendar: ScheduleFinder::createPreferredCalendar([ 5, 15, 25 ]),
    algorithm: ScheduleAlgorithm::ClosestWorkday);

/**
 * '2024-06-05' Tuesday because 5th is a Wednesday so the next
 * available calendar date.
 */
$schedule->nextAsString(from: '2024-06-04');

/**
 * '2024-06-14' Friday because 15th is a Saturday so the "closest workday"
 * (not before 6th June) is the Friday before the 15th.
 */
$schedule->nextAsString(from: '2024-06-06');

/**
 * '2024-06-19' Wednesday because the 17th (Monday) is a holiday. The 15th is
 * a Saturday so the next available workday is the Wednesday after the 17th. 
 */
$schedule->nextAsString(from: '2024-06-15');

/**
 * '2024-06-24' Monday because the 25th (Tuesday) is not a workday so the closest
 * workday (not before 17th June) is the Monday before the 25th.
 */
$schedule->nextAsString(from: '2024-06-17');

/**
 * '2024-06-26' Wednesday because the 25th (Tuesday) is not a workday
 * so the closest workday (not before 25th June) is the Wednesday after the 25th.
 */
$schedule->nextAsString(from: '2024-06-25');