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')); }
/** * @expectedException RuntimeException */ public function testHumanReadableRuntimeException() { $rrule = new RRule(array('freq' => 'daily', 'count' => 10, 'dtstart' => '2007-01-01')); $rrule->humanReadable(array('locale' => 'xx', 'fallback' => 'xx')); // the locales are correctly formatted, but not such file exist, so this should throw a RuntimeException }
/** * Simple wrapper function to convert the RRule into its human readable form. * * @return string */ public function getRruleHumanReadable() { if ($this->rrule) { $rrule_str = $this->rrule; // ensure rrule string has a start date if not defined so that it will be part of the // formatted output if (!$this->isNewRecord && !strpos($rrule_str, 'DTSTART=')) { $created_date = new DateTime($this->created_date); $rrule_str .= ";DTSTART=" . $created_date->format('Y-m-d'); } $final_rrule = new RRule($rrule_str); return $final_rrule->humanReadable(array('date_formatter' => function ($d) { return $d->format(Helper::NHS_DATE_FORMAT); })); } }