/** * Validate the input value and set the value of @see validPattern if the input machtes a pattern * * @param string $value The format string to validate * @param null $context The form context (ignored) * * @return bool True when the input is valid, otherwise false * * @see Zend_Validate_Abstract::isValid() */ public function isValid($value, $context = null) { $this->validPattern = false; if (!is_string($value) && !is_int($value)) { $this->error('INVALID_TYPE'); return false; } if ($this->isUnixTimestamp($value)) { $dt = DateTimeFactory::create(); $dt->setTimestamp($value); } else { if (!isset($this->patterns)) { throw new ProgrammingError('There are no allowed timeformats configured'); } $match_found = false; foreach ($this->patterns as $pattern) { $dt = DateTimeFactory::parse($value, $pattern); if ($dt !== false && $dt->format($pattern) === $value) { $match_found = true; $this->validPattern = $pattern; break; } } if (!$match_found) { $this->_error('NO_MATCHING_PATTERN'); return false; } } return true; }
/** * Calculate the labels for this dataset * * @param integer $unit The unit to use as the basis for calculation */ private function calculateLabels($unit) { $fac = DateTimeFactory::create(); $duration = $this->getMax() - $this->getMin(); // Calculate number of ticks, but not more than 30 $tickCount = $duration / $unit * 10; if ($tickCount > 30) { $tickCount = 30; } $step = $duration / $tickCount; $format = $this->timeFormat; if ($unit === self::DAY) { $format = $this->dateFormat; } elseif ($unit === self::MONTH) { $format = $this->dateFormat; } for ($i = 0; $i <= $duration; $i += $step) { $this->labels[] = $fac->setTimestamp($this->getMin() + $i)->format($format); } }
/** * @param $weekday * * @return string */ private function weekdayName($weekday) { $sun = DateTimeFactory::create('last Sunday'); $interval = new DateInterval('P' . $weekday . 'D'); $sun->add($interval); return $sun->format('D'); }