I
I
Igor2018-05-17 20:57:01
PHP
Igor, 2018-05-17 20:57:01

I can not understand where I made a mistake in DateTime?

<?php
$currentDateTime = new DateTime("now", new DateTimeZone("Europe/Kiev"));

if(isWeekend($currentDateTime)){
    _e( "Сообщение в выходной", 'woocommerce' );
}else{
    if (isBeforeAM($currentDateTime)) {
    _e( "Сообщение до обеда", 'woocommerce' );
    }else{
    _e( "Сообщение после обеда", 'woocommerce' );
      }
  }


function isWeekend($currentDateTime) {
    if (isFridayWeekend($currentDateTime)) {
        return true;
    }
    return $currentDateTime->format('N') >= 6;
}
function isBeforeAM($currentDateTime){
    $currentTimeStamp = $currentDateTime->getTimestamp();
    $timeStamp = strtotime(date('Y-m-d') . "13:00");
    return $currentTimeStamp < $timeStamp ;
}
function isFridayWeekend($currentDateTime){
    return $currentDateTime->format('N') == 5 && isBeforeAM($currentDateTime);
}

?>

Sending messages is not correct, sends not what it should on weekdays

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question