第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

根據(jù)工作時(shí)間和工作日的分鐘數(shù)計(jì)算 SLA

根據(jù)工作時(shí)間和工作日的分鐘數(shù)計(jì)算 SLA

PHP
慕勒3428872 2023-08-11 15:31:03
我正在嘗試構(gòu)建一個(gè)函數(shù),該函數(shù)根據(jù)工作時(shí)間計(jì)算票務(wù)服務(wù)協(xié)議,并跳過(guò)非工作時(shí)間和周末的計(jì)算,并將時(shí)間相應(yīng)地轉(zhuǎn)移到第二天或下一個(gè)工作日。我對(duì)工單的響應(yīng) SLA 是 30 分鐘,如果工單插入日期在工作日 {周一至周五} 和工作時(shí)間內(nèi) {08:00:00 - 17:00:00},那么我的結(jié)束日期應(yīng)根據(jù)以下公式計(jì)算因素:對(duì)于周一至周四,如果 insertDate 落在工作時(shí)間內(nèi),則時(shí)間應(yīng)移至工作時(shí)間的下 30 分鐘,例如 if case1: insertDate = '2020-07-16 16:00:00'; 在這里,我得到了預(yù)期的結(jié)果,endDate ='2020-07-16 16:30:00'; 如果 insertDate 時(shí)間戳超出工作時(shí)間窗口,例如 if case2: insertDate = '2020-07-16 16:50:00'; 在這里,我沒(méi)有得到預(yù)期的結(jié)果,應(yīng)該是 endDate ='2020-07-17 08:20:00';對(duì)于周末(周六至周日),在該周末窗口創(chuàng)建的任何工單,應(yīng)從周一 08:00:00 開(kāi)始計(jì)算 case3: insertDate = '2020-07-18 16:50:00'; 在這里,我沒(méi)有得到預(yù)期的結(jié)果,應(yīng)該是 endDate ='2020-07-20 08:30:00';下面是我的代碼,適用于 case1 很好,ubt 則適用于 case2 和 case3,對(duì)此的任何幫助都非常感謝。<?phpfunction calculateSLA($totalMinutes){$insertDate = '2020-07-16 16:00:00';$endDate = date('Y-m-d H:00:00',strtotime($insertDate)); //$t_min = date('i',strtotime($insertDate));$BusinessStart = '08:00:00';$BusinessEnd   = '17:00:00';$i           = 1;$flag        = false;while ($totalMinutes > 0) {    $day = date('D', strtotime($endDate)); // fetching day of week    if ($day == 'Sat') { // checking if saturday thenskip by adding 2 day to end date        $endDate = date('Y-m-d', strtotime($endDate . " +2 Day")) . ' ' . $BusinessStart; // adding 2 day if saturday        continue;    }    $diff  = strtotime($BusinessEnd) - strtotime(date("H:i:s", strtotime($insertDate))); // getting difference of time of office end date and result end date    var_dump($diff);    $mins = $diff / (60); // difference in mins.    if ($mins > $totalMinutes) {        $mins = $totalMinutes;        $flag  = true;     } else {        $mins = $totalMinutes - $mins; // substracting mins from total minutes left            }    $endDate = date('Y-m-d H:i:s', strtotime("+$mins Minute", strtotime($insertDate))); // adding subtracted minutes    if (!$flag) {        $endDate = date('Y-m-d', strtotime($insertDate . " +1 Day")) . ' ' . $BusinessStart; // if not last loop add day to result end date    } else {        break;    }}echo $endDate;}calculateSLA(30);?>
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊

我將發(fā)布我的函數(shù)版本。您傳遞票證提交的日期時(shí)間并獲取允許響應(yīng)的日期時(shí)間。


function calculateSLA(DateTime $reportDate): DateTime {

  $responseDate = (clone $reportDate);


  // check conditions and add 1 minute to provided date 30 times (so 30 minutes)

  for($i=0; $i<30;$i++) {

    // if time is before 8:00 (working hours) skip to 8:00

    if ($responseDate->format('G') < 8) {

      $responseDate->setTime(8, 0);

    }


    // if time is after 17:00 (working hours) skip to next day at 8:00

    if ($responseDate->format('G') >= 17) {

      $responseDate->add(new DateInterval('PT15H'));

      $responseDate->setTime(8, 0);

    }


    // if at any time it is weekend skip to monday at 8:00

    if (in_array($responseDate->format('D'), ['Sat', 'Sun'])) {

      $responseDate = $responseDate->modify('next monday 8:00');

    }


    $responseDate->add(new DateInterval('PT1M'));

  }


  return $responseDate;

}

我用來(lái)在不同條件下測(cè)試這個(gè)函數(shù)的代碼:


function test(string $date, string $expected) {

  $result = calculateSLA(new DateTime($date));

  echo 'date: '.$date.', expected: '.$expected.', got: '.$result->format('Y-m-d H:i:s').' '.($result->format('Y-m-d H:i:s') === $expected ? 'OK' : 'ERRROR').PHP_EOL;

}

test('2020-07-16 16:00:00', '2020-07-16 16:30:00'); // weekday during hours

test('2020-07-16 16:50:00', '2020-07-17 08:20:00'); // weekday during hours until next day

test('2020-07-18 16:50:00', '2020-07-20 08:30:00'); // weekend

test('2020-07-16 06:50:00', '2020-07-16 08:30:00'); // weekday before working hours

test('2020-07-16 20:50:00', '2020-07-17 08:30:00'); // weekday after working hours

test('2020-07-17 16:50:00', '2020-07-20 08:20:00'); // friday during working hours until monday

test('2020-07-17 17:50:00', '2020-07-20 08:30:00'); // friday after hours

輸出:


date: 2020-07-16 16:00:00, expected: 2020-07-16 16:30:00, got: 2020-07-16 16:30:00 OK

date: 2020-07-16 16:50:00, expected: 2020-07-17 08:20:00, got: 2020-07-17 08:20:00 OK

date: 2020-07-18 16:50:00, expected: 2020-07-20 08:30:00, got: 2020-07-20 08:30:00 OK

date: 2020-07-16 06:50:00, expected: 2020-07-16 08:30:00, got: 2020-07-16 08:30:00 OK

date: 2020-07-16 20:50:00, expected: 2020-07-17 08:30:00, got: 2020-07-17 08:30:00 OK

date: 2020-07-17 16:50:00, expected: 2020-07-20 08:20:00, got: 2020-07-20 08:20:00 OK

date: 2020-07-17 17:50:00, expected: 2020-07-20 08:30:00, got: 2020-07-20 08:30:00 OK

棘手的部分是星期五,您沒(méi)有真正提到,但我為其添加了測(cè)試用例。


查看完整回答
反對(duì) 回復(fù) 2023-08-11
  • 1 回答
  • 0 關(guān)注
  • 153 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)