public static function getHumanReadableFromPattern($start, $pattern) { $untilpos = strpos($pattern, 'UNTIL'); $startDateTime = new \DateTime($start); if ($untilpos !== false) { $time = $startDateTime->format('\\This\\Z'); $newpattern = substr_replace($pattern, $time, $untilpos + 6 + 8, 0); $rule = 'DTSTART;TZID=Etc/GMT:' . $startDateTime->format('Ymd\\THis') . ' RRULE:' . $newpattern; } else { $rule = 'DTSTART;TZID=Etc/GMT:' . $startDateTime->format('Ymd\\THis') . ' RRULE:' . $pattern; } $rrule = new RRule($rule); return $rrule->humanReadable(array('locale' => 'fr')); }
/** * Annule l'évènement et tous ses enfants * Si pas d'heure de fin programmée, utilisation de l'heure actuelle * * @param \Application\Entity\Status $status * @throws \RuntimeException */ public function cancelEvent(Status $status) { if ($status->getId() != 4) { throw new \RuntimeException("Statut annulé attendu, un autre statut a été fourni."); } $this->setStatus($status); if ($this->isPunctual() || !$this->isPunctual() && $this->getEnddate() === null) { $now = new \DateTime('now'); $now->setTimezone(new \DateTimeZone('UTC')); $this->setEnddate($now); } foreach ($this->getChildren() as $child) { // annuler tous les évènement sauf les actions if (!$child instanceof ActionCategory) { $child->cancelEvent($status); } } }
/** * @return string * @Grid\Header(label="Age", sort={"dateOfBirth"}, reverse=true) */ public function getAge() { $now = new \DateTime(); $age = $now->diff($this->dateOfBirth); return $age->y > 1 ? sprintf('%d years', $age->y) : sprintf('%d months', $age->m); }
public function getHour() { $datetime = new \DateTime(); if ($this->hour != null) { $this->hour->setDate($datetime->format('Y'), $datetime->format('n'), $datetime->format('d')); } return $this->hour; }
public function getRemainingTime() { $stop = $this->stop->getTimeStamp(); $now = new \DateTime(); return $stop - $now->getTimeStamp(); }
/** * @return string|null * @Grid\Header(label="Time", sort={"time"}) */ public function getTimeDisplay() { return $this->time ? $this->time->format('h:i A') : null; }
/** * Set time * * @param \DateTime $time * * @return Event */ public function setTime($time) { if (isset($time)) { if (is_string($time)) { $time = \DateTime::createFromFormat('H:i:s', trim($time)); } } $this->time = $time; return $this; }
public function formatDate($date) { $dateTime = null; //retorna o mesmo o objeto if (is_object($date)) { $dateTime = $date; // retorna data atual } else { if (trim($date) == "" || $date == null || $date == 'now') { $dateTime = new \DateTime(date('Y-m-d H:i:s')); } else { if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $date)) { $dateTime = \DateTime::createFromFormat('Y-m-d H:i:s', $date . ' 00:00:00'); } else { if (preg_match('/^[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}$/', $date)) { $dateTime = \DateTime::createFromFormat('d/m/Y H:i:s', $date . ' 00:00:00'); } else { if (preg_match('/^[0-9]{2}\\/[0-9]{2}\\/[0-9]{4} [0-9]{2}:[0-9]{2}$/', $date)) { $dateTime = \DateTime::createFromFormat('d/m/Y H:i', $date); } else { if (preg_match('/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/', $date)) { $dateTime = \DateTime::createFromFormat('d-m-Y H:i:s', $date . ' 00:00:00'); } else { if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $date)) { $dateTime = \DateTime::createFromFormat('Y-m-d H:i:s', $date); } else { if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}$/', $date)) { $dateTime = new \DateTime($date); } else { if (preg_match('/^[0-9]{2}:[0-9]{2}$/', $date)) { $dateTime = \DateTime::createFromFormat('H:i', $date); } else { if (preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $date)) { $dateTime = \DateTime::createFromFormat('H:i:s', $date); } else { if (is_numeric($date)) { $dateTime = new \DateTime(date('Y-m-d H:i:s', $date)); } } } } } } } } } } } return $dateTime; }