簡體   English   中英

如何在條件中放入多個間隔“ new DateTime”(php)

[英]How to put multiple interval “new DateTime” (php) inside a condition

我想顯示一個體育中心(協會)的開放時間。 該守則必須涉及2019-2020學年。 默認情況下(否則)它將顯示您的開場時間,在第一個條件下(如果)則顯示學校假期,在第二個條件下(否則)則顯示假期。

對於“新日期時間”的間隔,它可以正常工作。 一旦我設置了多個間隔,它就不起作用了,我認為它是正常的。 但是我找不到放置多個日期時間間隔的好方法。

我可以使用dateInterval嗎?

$ TodayDate-> getTimestamp()> $ automne1-> getTimestamp()&& $ TodayDate-> getTimestamp()<$ automne2-> getTimestamp()

函數whatday(){

     //vac automne
     $automne1 = new DateTime('2019-10-19');
     $automne2  = new DateTime('2019-11-03');

     //vac noel - voir horaires exceptionnels plus bas
     $noel1 = new DateTime('2019-12-21');
     $noel2 = new DateTime('2020-01-05');

     // vac hiver
     $hiver1 = new DateTime('2020-02-08');
     $hiver2 = new DateTime('2020-02-23');

     //vac printemps
     $printemps1 = new DateTime('2020-04-04');
     $printemps2 = new DateTime('2020-04-19');

     // vac été
     $ete1 = new DateTime('2020-07-04');
     $ete2 = new DateTime('2020-07-13');
     $ete3 = new DateTime('2020-07-15');
     $ete4 = new DateTime('2020-08-14');
     $ete5 = new DateTime('2020-08-16');

     //rentrée sco 2020
     $ete6 = new DateTime('2020-09-01');

     //jours fériés
     $armistice18 = new DateTime('2019-11-11');
     $epiphanie = new DateTime('2020-01-06');
     $fetetravail = new DateTime('2020-05-01');
     $victoire45 = new DateTime('2020-05-08');
     $ascension = new DateTime('2020-05-21');
     $lunpentecote = new DateTime('2020-06-01');
     $14juillet = new DateTime('2020-07-14');
     $asomption = new DateTime('2020-08-15');

     // Horaires execptionnels noel du 24 dec au 5 janvier

     // conditions vacances scolaires
     if (
     $TodayDate->getTimestamp() > $automne1->getTimestamp() && $TodayDate->getTimestamp() < $automne2->getTimestamp() &&
     $TodayDate->getTimestamp() > $noel1->getTimestamp() && $TodayDate->getTimestamp() < $noel2->getTimestamp() &&
     $TodayDate->getTimestamp() > $hiver1->getTimestamp() && $TodayDate->getTimestamp() < $hiver2->getTimestamp() &&
     $TodayDate->getTimestamp() > $printemps1->getTimestamp() && $TodayDate->getTimestamp() < $printemps2->getTimestamp() &&
     $TodayDate->getTimestamp() > $automne1->getTimestamp() && $TodayDate->getTimestamp() < $automne2->getTimestamp() &&
     $TodayDate->getTimestamp() > $ete1->getTimestamp() && $TodayDate->getTimestamp() < $ete2->getTimestamp() &&
     $TodayDate->getTimestamp() > $ete3->getTimestamp() && $TodayDate->getTimestamp() < $ete4->getTimestamp() &&
     $TodayDate->getTimestamp() > $ete5->getTimestamp() && $TodayDate->getTimestamp() < $ete6->getTimestamp()
     )
     {
     if($NameDay === 'Mon')
     return "8h00 à 21h30";
     if($NameDay === 'Tue')
     return "12h00 à 21h30";
     if($NameDay === 'Wed')
     return "8h00 à 21h30";
     if($NameDay === 'Thu')
     return "12h00 à 21h30";
     if($NameDay === 'Fri')
     return "8h00 à 21h30";
     if($NameDay === 'Sat')
     return "8h00 à 19h00";
     if($NameDay === 'Sun')
     return "8h00 à 12h00";
     }
     // conditions jours fériés et vac noel
     else if(
     $TodayDate->getTimestamp() === $armistice18->getTimestamp() &&
     $TodayDate->getTimestamp() === $epiphanie->getTimestamp() &&
     $TodayDate->getTimestamp() === $fetetravail->getTimestamp() &&
     $TodayDate->getTimestamp() === $victoire45->getTimestamp() &&
     $TodayDate->getTimestamp() === $ascension->getTimestamp() &&
     $TodayDate->getTimestamp() === $lunpentecote->getTimestamp() &&
     $TodayDate->getTimestamp() === $14juillet->getTimestamp() &&
     $TodayDate->getTimestamp() === $asomption->getTimestamp() &&
     )
     {
     return "FERMÉEE";
     }
     // conditions horaires normaux
     else{

     if($NameDay === 'Mon')
     return "8h00 à 21h30";
     if($NameDay === 'Tue')
     return "8h00 à 21h30";
     if($NameDay === 'Wed')
     return "8h00 à 21h30";
     if($NameDay === 'Thu')
     return "8h00 à 21h30";
     if($NameDay === 'Fri')
     return "8h00 à 21h30";
     if($NameDay === 'Sat')
     return "08h00 à 19h00";
     if($NameDay === 'Sun')
     return "08h00 à 12h00";
     }
     */
};
add_shortcode('opendays', 'whatday');

在header.php中

我放 :

我嘗試在其他間隔天之間使用“ &&”,但是我認為這不是一個好的解決方案。

我已經解決了我的問題/我用||代替了邏輯運算符&& 在兩個日期的多次比較中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM