PHP library for retrieving regional sales periods.
composer require handelsgids/sales-periods
<?php
require 'vendor/autoload.php';
use Handelsgids\SalesPeriods\SalesPeriods;
$belgianSalesPeriods = new SalesPeriods('Belgium', 2018);
$salesPeriods = $belgianSalesPeriods->getSalesPeriods();
foreach ($salesPeriods as $salesPeriod) {
$output = sprintf(
'%s running from %s untill %s.',
$salesPeriod->getName(),
$salesPeriod->getStartDate(),
$salesPeriod->getEndDate()
);
echo $output . PHP_EOL;
}
The above example will output:
Summer sales running from 2018-06-30 untill 2018-07-31.
Winter sales running from 2018-01-03 untill 2018-01-31.
$date = new \DateTime('2018-06-19');
$result = $belgianSalesPeriods->inSalesPeriod($date);
Feel free to add more sales period regulations for your region via a pull request.
Checkout the files for the default region in /src/Region/Belgium/
or follow these steps:
-
Create a folder for the region you want to add sales periods for in
/src/Region/
-
For each sales period in the region create a class extending
AbstractSalesPeriod
-
Create the
init
function and set a name, start date, end date and source to the region regulations
composer test
Handelsgids sales periods is open-sourced software licensed under the MIT license.