PHP code example of nuxia / business-day-manipulator

1. Go to this page and download the library: Download nuxia/business-day-manipulator 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/ */

    

nuxia / business-day-manipulator example snippets


use Nuxia\BusinessDayManipulator\Manipulator;

$holidays = [
    new DatePeriod(new \DateTime('2015-02-02'), new \DateTime('2015-02-06')),
    new \DateTime('2015-02-20')
];

$freeDays = [
    new DatePeriod(new \DateTime('2015-02-24'), new \DateTime('2015-02-27'))
];

$freeWeekDays = [
    Manipulator::SATURDAY,
    Manipulator::SUNDAY
];

$manipulator = new Manipulator($freeDays, $freeWeekDays, $holidays);

use Nuxia\BusinessDayManipulator\LocalizedManipulator;

$holidays = [
    new DatePeriod(new \DateTime('2015-02-02'), new \DateTime('2015-02-06')),
    new \DateTime('2015-02-20')
];

$freeDays = [
    new DatePeriod(new \DateTime('2015-02-24'), new \DateTime('2015-02-27'))
];

$freeWeekDays = null; //If null, we will automatically set free week days from the locale.

//Guess automatically free week days.
$localizedManipulator = new LocalizedManipulator('Europe/Paris', 'fr', $freeDays, $freeWeekDay, $holidays);

$manipulator->setStartDate(new \DateTime('2015-02-01'));
$manipulator->addBusinessDays(15);
$manipulator->getDate()->format('Y-m-d'); //2015-03-06

$manipulator->setStartDate(new \DateTime('2015-03-06'));
$manipulator->subBusinessDays(15);
$manipulator->getDate()->format('Y-m-d'); //2015-02-01

$manipulator->setStartDate(new \DateTime('2015-02-01'));
$manipulator->setEndDate(new \DateTime('2015-03-02'));

$manipulator->getBusinessDays(); //12
$manipulator->getBusinessDaysDate()); //Array of DateTime instance

$manipulator->isBusinessDay(new \DateTime('2015-02-08')); //false

$manipulator->getTypeOfDay(new \DateTime('2015-02-08')); // free_week_day