<?php
\date_default_timezone_set('UTC');
$dates = ['2019-01-18', '2019-01-01', '2018-12-01', '2018-12-20', null];
$today = new \DateTimeImmutable('2019-01-01');
$yesterday = $today->modify('-1 day');
$results = [];
foreach ($dates as $iDate) {
$_GET['importDate'] = $iDate;
$results[$iDate] = '';
if (!$start = \date_create(!empty($_GET['importDate']) ? $_GET['importDate'] : $yesterday->format('Y-m-d'))) {
die('Invalid Date Supplied');
}
if ($start > $today) {
$results[$iDate] .= 'Dates set in the future are not permitted' . \PHP_EOL;
continue;
}
//start at the first day of the month
$start->modify('first day of this month')->setTime(0,0,0);
//validate the current month to prevent future dates
if ($start->format('Y-m') === $today->format('Y-m')) {
$end = \date_create($yesterday->format('Y-m-d'))->setTime(23,59,59);
if ($end < $start) {
//yesterday was last month
$end = clone $start;
}
} else {
$end = clone $start;
$end->modify('last day of this month');
}
//end at midnight
$end->setTime(23,59,59);
$importDates = new \DatePeriod($start, new \DateInterval('P1D'), $end);
foreach ($importDates as $date) {
$dateImport = $date->format('Y-m-d');
$results[$iDate] .= $dateImport . \PHP_EOL;
//...
}
}
//display the results
$values = array_reduce(\array_keys($results), function($carry, $item) use ($results) {
if (!in_array($results[$item], $carry)) {
$carry[] = $results[$item];
}
return $carry;
}, []);
echo 'Current Date: ' . $today->format('Y-m-d') . \PHP_EOL . \PHP_EOL;
foreach ($values as $info) {
$dates = '"' . implode('", "', array_keys($results, $info)) . '"';
echo <<<EOL
Import Dates: $dates
$info
EOL;
}
- Output for 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
- Current Date: 2019-01-01
Import Dates: "2019-01-18"
Dates set in the future are not permitted
Import Dates: "2019-01-01"
2019-01-01
Import Dates: "2018-12-01", "2018-12-20", ""
2018-12-01
2018-12-02
2018-12-03
2018-12-04
2018-12-05
2018-12-06
2018-12-07
2018-12-08
2018-12-09
2018-12-10
2018-12-11
2018-12-12
2018-12-13
2018-12-14
2018-12-15
2018-12-16
2018-12-17
2018-12-18
2018-12-19
2018-12-20
2018-12-21
2018-12-22
2018-12-23
2018-12-24
2018-12-25
2018-12-26
2018-12-27
2018-12-28
2018-12-29
2018-12-30
2018-12-31
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Current Date: 2019-01-01
Import Dates: "2019-01-18"
Dates set in the future are not permitted
Import Dates: "2019-01-01"
2019-01-01
Import Dates: "2018-12-01", "2018-12-20", ""
2018-12-01
2018-12-02
2018-12-03
2018-12-04
2018-12-05
2018-12-06
2018-12-07
2018-12-08
2018-12-09
2018-12-10
2018-12-11
2018-12-12
2018-12-13
2018-12-14
2018-12-15
2018-12-16
2018-12-17
2018-12-18
2018-12-19
2018-12-20
2018-12-21
2018-12-22
2018-12-23
2018-12-24
2018-12-25
2018-12-26
2018-12-27
2018-12-28
2018-12-29
2018-12-30
2018-12-31
preferences:
107.44 ms | 403 KiB | 155 Q