We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42239
    • 73 Posts
    Posted this in the wrong area before under discussion.

    I'm having trouble with multi day events not posting the last day if the time is < that of the start time.
    for example if i have a start date/time of 8/8/2014 7:00 pm and and end date/time of 8/10/2014 12:00 pm. It only displays on the 8th and 9th not on the 10th.

    So best I can tell there seems to some kind of issue with what value is given for $mxcArray['durDay'].

    In the above example I should get a 2 for 'durDay' but I get a 1. So it doesn't add the final date to the array.

    if(version_compare(PHP_VERSION, '5.3.0') >= 0){
           $diff = $eStart->diff($eEnd);
           $durYear = $diff->format('%y');
           $durMonth = $diff->format('%m');
           $durDay = $diff->format('%d');
           $durHour = $diff->format('%h');
           $durMin = $diff->format('%i');
           $durSec = $diff->format('%s');
       } else {
           $diff = (object)$mxcal->datediff($mxc->get('startdate'),$mxc->get('enddate'),true);
           $durYear = $diff->years;
           $durMonth = $diff->months;
           $durDay = $diff->days;
           $durHour = $diff->hours;
           $durMin = $diff->minutes;
           $durSec = $diff->seconds;
       }
        
       //-- return event duration values 
       $mxcArray['durYear']    = !empty($durYear) ? $durYear : null; 
       $mxcArray['durMonth']    = !empty($durMonth) ? $durMonth : null; 
       $mxcArray['durDay']      = !empty($durDay) ? $durDay : null; 
       $mxcArray['durHour']     = !empty($durHour) ? $durHour : null; 
       $mxcArray['durMin']      = !empty($durMin) ? $durMin : null; 
       $mxcArray['durSec']      = !empty($durSec) ? $durSec : null;
       $mxcArray['mxcmodalClass'] = ($modalView && $ajaxResourceId || isset($_REQUEST['imajax']) ? 'mxcmodal' : '');
     
       // Add date for each day in a multiple day event ( #127 )
       if($mxcArray['durDay'] !== null && $mxcArray['durDay'] >= 1){
           if($debug) echo 'Multiple Day Event: '.$mxcArray['title'].'<br />';
           for($i = 1; $i<=$mxcArray['durDay']; $i++){
               $theSpanDate = strtotime('+'.$i.' day', $mxcArray['startdate']);
               $arrEventDates[$mxcArray['id'].'_'.$i] = array('date'=>$theSpanDate, 'eventId'=>$mxcArray['id'],'repeatId'=>null);
               if($debug) echo '   ++(0)  '.strftime($dateFormat.' '.$timeFormat, $theSpanDate).'<br>';
           }
       }



    Problem with diff()? Where would I find this function? Is there something there that subtracts 1 if end time is < start time?

    This question has been answered by mandledesign. See the first response.

    [ed. note: mandledesign last edited this post 12 years, 2 months ago.]
      • 42239
      • 73 Posts
      this seems to sum up my problem.

      It appears that they "days" property that is populated by \DateTime::diff does not contain a float for the differences in time.
      It is rounded down to the nearest whole day.

      $d1 = new \DateTime("2013-07-31 10:29:00");
      $d2 = new \DateTime("2013-08-02 5:32:12");
      echo $d1->diff($d2)->days;

      Output: 1

      uhhhhhhhh what should i do?
      • discuss.answer
        • 42239
        • 73 Posts
        Think I solved my own problem.

            $eStart    = new DateTime(date('Y-m-d H:i:s',$mxc->get('startdate'))); 
            $eEnd      = new DateTime(date('Y-m-d H:i:s',$mxc->get('enddate')));
        
        	$eStart2    = new DateTime(date('Y-m-d',$mxc->get('startdate'))); 
            $eEnd2      = new DateTime(date('Y-m-d',$mxc->get('enddate')));
        
            $durYear; $durMonth; $durDay; $durHour; $durMin; $durSec;
            
            if(version_compare(PHP_VERSION, '5.3.0') >= 0){
                $diff = $eStart->diff($eEnd);
        		$diff2 = $eStart2->diff($eEnd2);
                $durYear = $diff->format('%y');
                $durMonth = $diff->format('%m');
                $durDay = $diff2->format('%d');
                $durHour = $diff->format('%h');
                $durMin = $diff->format('%i');
                $durSec = $diff->format('%s');
            } else {
                $diff = (object)$mxcal->datediff($mxc->get('startdate'),$mxc->get('enddate'),true);
                $durYear = $diff->years;
                $durMonth = $diff->months;
                $durDay = $diff->days;
                $durHour = $diff->hours;
                $durMin = $diff->minutes;
                $durSec = $diff->seconds;
            }