PHP code example of max13 / conditional-period

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

    

max13 / conditional-period example snippets


use Carbon\CarbonInterval;
use MX\ConditionalCollection;
use MX\ConditionalPeriod;
...
$prior_notices = [
    new ConditionalPeriod(
        ConditionalType::CATEGORY,
        1,
        5,
        CarbonInterval::make('1 month')
    ),
    new ConditionalPeriod(
        ConditionalType::CATEGORY,
        6,
        7,
        CarbonInterval::make('2 months')
    ),
    new ConditionalPeriod(
        ConditionalType::CATEGORY,
        8,
        12,
        CarbonInterval::make('3 months')
    ),
];

$prior_notices = ConditionalCollection::fromArray($prior_notices);


$trial_periods = [
    new ConditionalPeriod(
        ConditionalType::DURATION,
        CarbonInterval::make(0),
        CarbonInterval::make('6 months'),
        CarbonInterval::make('15 days')
    ),
    new ConditionalPeriod(
        ConditionalType::DURATION,
        CarbonInterval::make('6 months'),
        CarbonInterval::make('99 years'), // Equivalent to +∞
        CarbonInterval::make('1 month')
    ),
];

$trial_periods = ConditionalCollection::fromArray($trial_periods);

use MX\ConditionalCollection;
use MX\ConditionalPeriod;
...
$prior_notices = [
    new ConditionalPeriod('C1-5P1M'),
    new ConditionalPeriod('C6-7P2M'),
    new ConditionalPeriod('C8-12P3M'),
];

// OR
$prior_notices = new ConditionalCollection;
$prior_notices[] = new ConditionalPeriod('C1-5P1M');
$prior_notices[] = 'C6-7P2M';
$prior_notices[] = new ConditionalPeriod('C8-12P3M');

$trial_periods = [
    new ConditionalPeriod('DP0DP6MP15D'),
    new ConditionalPeriod('DP6MP99YP1M')
];

// OR
$trial_periods = ConditionalCollection::parse('DP0DP6MP15D,DP6MP99YP1M');