public static function populate($calendarEntry, $timeZone = '')
 {
     if ($timeZone == '') {
         $timeZone = Yii::$app->formatter->timeZone;
     }
     // Get given start & end datetime
     $startTime = new \DateTime(Yii::$app->request->get('start_datetime', ''), new \DateTimeZone($timeZone));
     $endTime = new \DateTime(Yii::$app->request->get('end_datetime', ''), new \DateTimeZone($timeZone));
     // Remember current (user) timeZone - and switch to system timezone
     $userTimeZone = Yii::$app->formatter->timeZone;
     Yii::$app->formatter->timeZone = Yii::$app->timeZone;
     $calendarEntry->start_datetime = Yii::$app->formatter->asDateTime($startTime, 'php:Y-m-d H:i:s');
     $calendarEntry->start_time = $startTime->format('H:i');
     // Fix FullCalendar EndTime
     if (\humhub\modules\calendar\Utils::isFullDaySpan($startTime, $endTime, true)) {
         // In Fullcalendar the EndTime is the moment AFTER the event
         $oneSecond = new \DateInterval("PT1S");
         $endTime->sub($oneSecond);
         $calendarEntry->all_day = 1;
     }
     $calendarEntry->end_time = $endTime->format('H:i');
     $calendarEntry->end_datetime = Yii::$app->formatter->asDateTime($endTime, 'php:Y-m-d H:i:s');
     // Switch back to user time zone
     Yii::$app->formatter->timeZone = $userTimeZone;
 }
 public static function populate($calendarEntry)
 {
     $startTime = new \DateTime(Yii::$app->request->get('start_datetime', ''));
     $endTime = new \DateTime(Yii::$app->request->get('end_datetime', ''));
     $calendarEntry->start_datetime = Yii::$app->formatter->asDate($startTime);
     $calendarEntry->start_time = $startTime->format('H:i');
     // Fix FullCalendar EndTime
     if (\humhub\modules\calendar\Utils::isFullDaySpan($startTime, $endTime, true)) {
         // In Fullcalendar the EndTime is the moment AFTER the event
         $oneSecond = new \DateInterval("PT1S");
         $endTime->sub($oneSecond);
         $calendarEntry->all_day = 1;
     }
     $calendarEntry->end_time = $endTime->format('H:i');
     $calendarEntry->end_datetime = Yii::$app->formatter->asDate($endTime);
 }
 public function beforeSave($insert)
 {
     $this->content->visibility = $this->is_public;
     $format = Yii::$app->formatter->dateFormat;
     if (substr($format, 0, 4) == "php:") {
         $format = substr($format, 4);
         $s = \DateTime::createFromFormat($format, $this->start_datetime);
         $e = \DateTime::createFromFormat($format, $this->end_datetime);
     } else {
         $s = new \DateTime($this->start_datetime);
         $e = new \DateTime($this->end_datetime);
     }
     if ($this->all_day == 0 && \humhub\modules\calendar\Utils::isFullDaySpan($s, $e)) {
         $this->all_day = 1;
     }
     if ($this->all_day) {
         $this->start_datetime = Yii::$app->formatter->asDateTime($s, 'php:Y-m-d') . " 00:00:00";
         $this->end_datetime = Yii::$app->formatter->asDateTime($e, 'php:Y-m-d') . " 23:59:59";
     } else {
         $this->start_datetime = Yii::$app->formatter->asDateTime($s, 'php:Y-m-d') . " " . $this->start_time . ":00";
         $this->end_datetime = Yii::$app->formatter->asDateTime($e, 'php:Y-m-d') . " " . $this->end_time . ":59";
     }
     return parent::beforeSave($insert);
 }
 public function beforeSave($insert)
 {
     $this->content->visibility = $this->is_public;
     $startDateTime = new \DateTime($this->start_datetime);
     $endDateTime = new \DateTime($this->end_datetime);
     // Check is a full day span
     if ($this->all_day == 0 && \humhub\modules\calendar\Utils::isFullDaySpan($startDateTime, $endDateTime)) {
         $this->all_day = 1;
     }
     if ($this->all_day) {
         $this->start_datetime = Yii::$app->formatter->asDateTime($startDateTime, 'php:Y-m-d') . " 00:00:00";
         $this->end_datetime = Yii::$app->formatter->asDateTime($endDateTime, 'php:Y-m-d') . " 23:59:59";
     }
     return parent::beforeSave($insert);
 }