简体   繁体   English

如何在条件中放入多个间隔“ new DateTime”(php)

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

I would like to display the opening hours of a sport center (association). 我想显示一个体育中心(协会)的开放时间。 This code must concern the school year 2019-2020. 该守则必须涉及2019-2020学年。 By default (else) it display the opening yours, in first condition(if) it display the school vacation and in second condition (else if) it display holidays. 默认情况下(否则)它将显示您的开场时间,在第一个条件下(如果)则显示学校假期,在第二个条件下(否则)则显示假期。

For one interval of "new Datetime" it works fine. 对于“新日期时间”的间隔,它可以正常工作。 As soon as I put multiple interval it doesn't work and I think its normal . 一旦我设置了多个间隔,它就不起作用了,我认为它是正常的。 But i can't find the good way to put multiple interval of datetime. 但是我找不到放置多个日期时间间隔的好方法。

Could I use dateInterval ? 我可以使用dateInterval吗?

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

function whatday() { 函数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');

In header.php 在header.php中

I put : 我放 :

I try tu use "&&" between others interval of days but I think it's not the good solution. 我尝试在其他间隔天之间使用“ &&”,但是我认为这不是一个好的解决方案。

I have resolved my problem/ I replaced Logical Operators && by || 我已经解决了我的问题/我用||代替了逻辑运算符&& in multiple comparison of two dates. 在两个日期的多次比较中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM