Skip to content

Instantly share code, notes, and snippets.

@summersab
Created September 11, 2018 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save summersab/c3c1849e44621660e71ded797f73a335 to your computer and use it in GitHub Desktop.
Save summersab/c3c1849e44621660e71ded797f73a335 to your computer and use it in GitHub Desktop.
PHP script to return a JSON object of observed UPS holidays (i.e. days they don't pick up or deliver) using https://github.com/azuyalabs/yasumi.
<?php
require 'vendor/autoload.php';
$UPS = array(
"New Year's Day",
"New Year's Day observed",
"Memorial Day",
"Independence Day observed",
"Independence Day",
"Labour Day",
"Thanksgiving Day",
"Christmas",
"Christmas observed",
);
$holidays = Yasumi\Yasumi::create('USA', date('Y'));
$official = new Yasumi\Filters\OfficialHolidaysFilter($holidays->getIterator());
$json = "[";
$i = 0;
foreach ($official as $day) {
if (in_array($day->getName(), $UPS)) {
if ($i) $json = $json . ",";
$json = $json . json_encode($day);
$i = 1;
}
}
$NYE_check = Yasumi\Yasumi::create('USA', date('Y', strtotime('+1 years')));
if ($NYE_check->getHoliday('substituteHoliday:newYearsDay')) {
$json = $json . "," . json_encode($NYE_check->getHoliday('substituteHoliday:newYearsDay'));
}
$json = $json . "]";
echo $json;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment