PHP code example of kosmosafive / production-calendar

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

    

kosmosafive / production-calendar example snippets


use MyCalendar\ProductionCalendar;
use MyCalendar\Providers\XmlCalendarProvider;
use MyCalendar\Providers\CachedHolidayProvider;

// 1. Настройка провайдера (с использованием вашего HTTP-клиента)
$apiProvider = new XmlCalendarProvider($httpClient, $requestFactory);

// 2. Добавляем кеширование (любой PSR-16 драйвер)
$provider = new CachedHolidayProvider($apiProvider, $cache);

// 3. Инициализация календаря
$calendar = new ProductionCalendar($provider, 'ru');

// Проверка дня
$calendar->isWorkday(new DateTime('2026-01-01')); // false (Новый год)

// Расчет количества рабочих дней
$workdaysCount = $calendar->countWorkdays(
    new DateTime('2026-05-01'),
    new DateTime('2026-05-31')
);

// Прибавление 10 рабочих дней
$deadline = $calendar->addWorkdays(new DateTime('now'), 10);

use MyCalendar\Providers\CompositeProvider;
use MyCalendar\Providers\JsonFileProvider;

$composite = new CompositeProvider(
    new JsonFileProvider(__DIR__ . '/config/holidays'), // Сначала ищем тут
    new XmlCalendarProvider($client, $factory)          // Если файла нет, идем в API
);

foreach ($calendar->getWorkdaysIterator($start, $end) as $date) {
    echo $date->format('Y-m-d');
}
json
{
  "months": [
    {
      "month": 1,
      "days": "1,2,3,4,5,6,7,8,9+,10,11,17,18,24,25,31"
    }
  ],
  "transitions": [
    {"from": "01.03", "to": "01.09"}
  ]
}