저는 현재 기본적인 작업이 무엇인지 고심하고 있습니다. 나는 시작 날짜, 종료 날짜 및 카운트를 가지고있다. 두 번째 날짜 사이에 세 번째 매개 변수 (개수)가 몇 시간으로 감소해야하는지 계산해야합니다. 예 : 매시간 .PHP 날짜 사이의 숫자 감소
그 조금, 나는 우리가 OK를 포함했다고 생각한다. 문제는 지금 온다.
웹 사이트가 일 때 일 때만 계산되기를 원합니다. 이 시간은 배열에 저장되며 0
색인은 열려 있고 1
은 닫습니다. 또한 날짜는 동적으로 now
으로 업데이트됩니다.
Array
(
[mon] => Array
(
[0] => 2012-04-03 9:00
[1] => 2012-04-03 21:30
)
[tue] => Array
(
[0] => 2012-04-03 9:00
[1] => 2012-04-03 21:30
)
[wed] => Array
(
[0] => 2012-04-03 9:00
[1] => 2012-04-03 21:30
)
[thu] => Array
(
[0] => 2012-04-03 9:00
[1] => 2012-04-03 21.30
)
[fri] => Array
(
[0] => 2012-04-03 9:00
[1] => 2012-04-03 19:00
)
[sat] => Array
(
[0] => 2012-04-03 9:00
[1] => 2012-04-03 18:00
)
[sun] => Array
(
[0] => 2012-04-03 10:30
[1] => 2012-04-03 19:00
)
)
그래서 매 시간마다 카운터가 줄어들고 개장 시간 사이에 있습니다. 그러나 우리가 닫히면 카운터 이이 오늘 닫는 시간까지 올라갈 곳을 계산해야합니다.
openTimes
에는 areWeOpen
이라는 변수가 있습니다.이 변수를 사용하여 현재 열려 있는지 또는 닫혀 있는지 확인할 수 있습니다. 우리는 몇 가지 코드 그러나 항상 작동하지 않는 것 같습니다
function countOffers($start, $end, $deals) {
global $openTimes;
if(strtotime($end) < time()) return 1;
define('ONEHOUR', 1);
$totalDays = unixtojd(strtotime($end)) - unixtojd(strtotime($start));
$daysBefore = unixtojd(time()) - unixtojd(strtotime($start));
$daysAfter = unixtojd(strtotime($end)) - unixtojd(time());
$startDay = strtolower(date("D", strtotime(date("Y-m-d", strtotime($start)))));
$totalHours = 0;
$hoursBefore = 0;
/* TOTAL HOURS */
for($i = 0; $i <= $totalDays; $i++) {
$dayName = strtolower(date("D", strtotime(date("Y-m-d", strtotime($start)) . " +$i days")));
$day = $openTimes->openDays[$dayName];
if($i === 0) {
$startHour = explode(" ", $start);
$startHour = str_replace(array(":","3"), array(".","5"), $startHour[1]);
$endHour = explode(" ", $day[1]);
$endHour = str_replace(array(":","3"), array(".","5"), $endHour[1]);
$totalHours += $endHour - $startHour;
} else {
$tempHour = (strtotime($day[1]) - strtotime($day[0]))/3600;
$totalHours += (strtotime($day[1]) - strtotime($day[0]))/3600;
}
}
$perHour = round($deals/$totalHours, 1);
$today = 0;
if($openTimes->areWeOpen === FALSE && $openTimes->morning === FALSE) {
/* HOURS UP TO TODAY */
for($i = 0; $i < $daysBefore; $i++) {
$day = $openTimes->openDays[strtolower(date("D", strtotime(date("Y-m-d", strtotime($start)) . " +$i days")))];
$hoursBefore += (strtotime($day[1]) - strtotime($day[0]))/3600;
}
} elseif (strtotime($start) <= time()) {
/* HOURS UP TO YESTERDAY */
for($i = 0; $i < ($daysBefore-1); $i++) {
$day = $openTimes->openDays[strtolower(date("D", strtotime(date("Y-m-d", strtotime($start)) . " +$i days")))];
$hoursBefore += (strtotime($day[1]) - strtotime($day[0]))/3600;
}
if(strstr($start, date("Y-m-d", time()))) {
$today = ceil((time() - strtotime($start))/3600) - ONEHOUR;
} else {
$today = ceil((time() - strtotime($openTimes->openDays[strtolower(date("D", time()))][0]))/3600) - ONEHOUR;
}
}
$alreadyGone = $hoursBefore*$perHour;
$dealsLeft = $deals - (($hoursBefore*$perHour) + ($today*$perHour));
if($dealsLeft < 0.5) $dealsLeft = 1;
return round($dealsLeft);
}
그것은 계산합니다 제대로, 그러나 우리가 닫혀있을 때, 그것은 계속 감소 것이다 투쟁 할 것 같다. 나는 이것을하기위한 더 좋은 방법이 있어야한다는 것을 안다, 나는 단지 그것을 이해할 수 없다. 너무 머리가 아파서 문제가 복잡해집니다.
* 편집 : 개방 시간 동안
(배열에서 제공) 나는 동안 배의 값 x
양을 감소해야합니다 * 좋아, 여기에 내가 달성하기 위해 노력하고있어의 아래 휴식입니다 그 날. 닫힌 경우 마지막 종료 시간까지만 값을 줄이고 싶습니다.
카운터의 시작 날짜, 종료 날짜 및 시작 번호가 제공됩니다. 매일 오전 9시에서 오후 9시 사이에 값이 감소 할 수 있습니다. 그 시간이 지난 경우 또는 현재 닫혀있는 경우 마지막 종료 시간 (어제)까지만 줄이기를 원합니다.
주제에서 벗어나지 만 웹 사이트에 개장 시간이있는 이유는 정말로 흥미 롭습니다. – JJJ
직원이 전화를 걸지 않으므로? 온라인 판매는하지 않습니다. 저희 웹 사이트는 온라인 안내 책자와 같습니다. – James
@James 당신은 좋아할 수 있습니다 ... 귀하의 웹 사이트에 쉽게 명시된 시간에 전화하지 말라 ..? –