Merhaba,
Bir konuda fikrinizi almak istiyorum. 15 dakika aralıklarla bir işlem yaptıracağım bir jobum olacak.
Job işlendiğinde de belirlenen bir saat listesindeki en yakın 2 tarihi belirleyip bu liste excel olarak gönderilmemişse excel göndereceğim.
Örneklemek gerekirse:
Saat listesi = ["13:00" , "17:30", "14:45","00:00"]
Job çalışma saati = "13:45" => seçilen tarihler başlangıç => 00:00 bitiş => 13:00
Job çalışma saati = "17:45" => seçilen tarihler başlangıç => 14:45 bitiş => 17:00
Job çalışma saati = "18:45" => seçilen tarihler başlangıç => 14:45 bitiş => 17:00
Bitiş tarihini de her zaman bir yere kaydedeceğim. "Yıll-ay-gün saat olarak".
Bunu yazdığım bir kod var ve aslında çalışıyor. Sadece daha iyisi olabilir mi diye merak ettim.
AddOrder class:
$this->options["excelPrintoutShouldAlsoBeGiven"] = true; // Excel çıktısı ilave verilmesi istenirse
$this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"] = ["23:45", "00:00", "22:45", "19:00", "13:30"];
if ($this->options["excelPrintoutShouldAlsoBeGiven"]) {
usort($this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"], array(AddOrder::class, "date_sort"));
if (count($this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"]) == 1) {
$this->options["endDate"] = date("Y-m-d" . " " . $this->options["whenShouldTheExcelPrintoutBeGiven"][0] . ":00");
$this->options["startDate"] = date("Y-m-d H:i:s", strtotime($this->options["endDate"] . "-1 days"));
} else {
$hoursList = [];
foreach ($this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"] as $key => $hour) {
if (strtotime(date("H:i:s")) > strtotime(date($hour . ":s"))) {
$hoursList[] = $key;
}
}
if (!empty($hoursList)) {
if (count($hoursList) == 1) {
$this->options["startDate"] = date("Y-m-d H:i:s", strtotime(
date("Y-m-d " .
end($this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"]) . ":00") . "-1 Days"));
$this->options["endDate"] = date("Y-m-d " .
$this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"][$hoursList[0]] . ":00");
} else {
$hoursList = array_reverse($hoursList);
$this->options["startDate"] = date("Y-m-d " .
$this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"][$hoursList[1]] . ":00");
$this->options["endDate"] = date("Y-m-d " .
$this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"][$hoursList[0]] . ":00");
}
} else {
$hoursList = array_reverse($this->optionsExtra["whenShouldTheExcelPrintoutBeGiven"]);
$this->options["startDate"] = date("Y-m-d H:i:s", strtotime(
date("Y-m-d " . $hoursList[1] . ":00") . "-1 Days"
));
$this->options["endDate"] = date("Y-m-d H:i:s", strtotime(
date("Y-m-d " . $hoursList[0] . ":00") . "-1 Days"
));
}
}
dd($this->options);
}
Sıralamayı aynı sınıf içerisine ekledim
private static function date_sort($a, $b)
{
return strtotime($a) - strtotime($b);
}