0

我想显示体育中心(协会)的开放时间。此代码必须涉及 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 中

我放 :

我尝试在其他天数之间使用“&&”,但我认为这不是一个好的解决方案。

4

1 回答 1

0

我已经解决了我的问题/我用 || 替换了逻辑运算符 && 在两个日期的多重比较中。

于 2019-09-12T10:28:52.530 回答