PHP code example of cobaltgrid / airac-calculator

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

    

cobaltgrid / airac-calculator example snippets




// Include the composer autoloader
Calculator\AIRACCycle;

// Getting the AIRAC cycle effective at a specific date
AIRACCycle::forDate(new DateTime('2023-07-29'));

// Getting the AIRAC cycle from an **exact** effective date
AIRACCycle::fromEffectiveDate(new DateTime('2023-07-13'));

// Getting the AIRAC cycle from a cycle code
AIRACCycle::fromCycleCode('2308');

// Getting from a serial (a serial is the number of cycles since the AIRAC epoch)
AIRACCycle::fromSerial(1619);

// Getting the current effective AIRAC
AIRACCycle::current();

// Getting the next AIRAC to become effective
AIRACCycle::next();

// Getting the previous AIRAC
AIRACCycle::previous();

$cycle = AIRACCycle::current();

// Get the 4-digit AIRAC cycle code (string)
$cycle->getCycleCode(); // 2308

// Gets the number of the cycle in it's year, starting at 1 (i.e. the first cycle is ordinal 1, second is 2, etc.) (int)
$cycle->getOrdinal(); // 1

// Returns the date the cycle became/becomes effective (DateTime)
$cycle->getEffectiveDate(); // DateTime Instance

// Returns the serial (number of cycles since AIRAC epoch) (int)
$cycle->getSerial(); // 1619

// Returns the next cycle from this one (AIRACCycle)
$cycle->nextCycle(); // AIRACCycle Instance

// Returns the previous cycle from this one (AIRACCycle)
$cycle->previousCycle(); // AIRACCycle Instance