/** * @param array $tokens * * @throws \LogicException * @return mixed */ public function parse($tokens) { $this->validate($tokens); $RPNTokens = $this->convertExprToRPN($tokens); $stack = []; foreach ($RPNTokens as $token) { if ($token instanceof Token && $token->is(Token::TYPE_OPERATOR)) { $a = array_shift($stack); $b = array_shift($stack); $method = $token->getValue() === '-' ? 'subtract' : 'add'; $result = $a->{$method}($b); array_push($stack, $result); } else { $stack[] = new ExpressionResult($token, $this->localeSettings->getTimeZone()); } } /** @var ExpressionResult $result */ $result = array_pop($stack); if (count($stack) > 0) { foreach ($stack as $stackedResult) { $result->merge($stackedResult); } } return $result === null ? $result : $result->getValue(); }
/** * @param User $user * @param Period $period * @return Timesheet */ private function timesheet(User $user, Period $period) { $worklogs = $this->workLogRepository->listAllByUserAndPeriod($user, $period); $taskList = new TaskList($period, $worklogs, new \DateTimeZone($this->localeSettings->getTimeZone())); $timeSheet = new Timesheet($user, $taskList); return $timeSheet; }
/** * @param Period $period * @return CalendarPeriod */ public function createCalendarPeriod(Period $period) { $begin = $period->getBegin(); $end = $period->getEnd(); $begin->setTimezone(new \DateTimeZone($this->localeSettings->getTimeZone())); $end->setTimezone(new \DateTimeZone($this->localeSettings->getTimeZone())); return new CalendarPeriod($begin, $end); }
/** * Formats date time * * @param \DateTime|string|int $date * @param string|int|null $dateType * @param string|int|null $timeType * @param string|null $locale * @param string|null $timeZone * @param string|null $pattern * @return string */ public function format($date, $dateType = null, $timeType = null, $locale = null, $timeZone = null, $pattern = null) { if (!$timeZone) { $timeZone = $this->localeSettings->getTimeZone(); } $date = $this->getDateTime($date); $formatter = $this->getFormatter($dateType, $timeType, $locale, $timeZone, $pattern); return $formatter->format((int) $date->format('U')); }
/** * {@inheritdoc} */ public function initialize(array $options) { if (empty($options['date'])) { // as a default value should be used local timezone date $localDate = new \DateTime(null, new \DateTimeZone($this->localeSettings->getTimeZone())); $options['date'] = $localDate->format('Y-m-d'); } elseif (!is_string($options['date'])) { throw new InvalidParameterException(sprintf('Option "date" must be a string, %s given.', $this->getClassOrType($options['date']))); } return parent::initialize($options); }
/** * @param \DateTime|null $date * @return array */ public function getTimezoneOffset(\DateTime $date = null) { $timezone = $this->localeSettings->getTimeZone(); $timezoneObj = new \DateTimeZone($timezone); if ($date === null) { $date = new \DateTime('now', $timezoneObj); } else { $date->setTimezone($timezoneObj); } $timezoneOffset = $timezoneObj->getOffset($date) / 60; return $timezoneOffset; }
/** * @param integer $weeksDiff * * @return \DateTime[] */ public function getLastWeekPeriod($weeksDiff = 0) { $end = new \DateTime('last Saturday', new \DateTimeZone($this->localeSettings->getTimeZone())); $start = clone $end; $start->modify('-7 days'); $end->setTime(23, 59, 59); if ($weeksDiff) { $days = $weeksDiff * 7; $start->modify("{$days} days"); $end->modify("{$days} days"); } return ['start' => $start, 'end' => $end]; }
/** * Formats date time * * @param \DateTime|string|int $date * @param string|int|null $dateType * @param string|int|null $timeType * @param string|null $locale * @param string|null $timeZone * @param string|null $pattern * @return string */ public function format($date, $dateType = null, $timeType = null, $locale = null, $timeZone = null, $pattern = null) { if (!$timeZone) { $timeZone = $this->localeSettings->getTimeZone(); } $dateTime = $this->getDateTime($date); // use Formatter if we have DateTime object and return the incoming argument otherwise if ($dateTime) { $formatter = $this->getFormatter($dateType, $timeType, $locale, $timeZone, $pattern); return $formatter->format((int) $dateTime->format('U')); } return $date; }
/** * Get current timezone offset * * @return string */ private function getTimeZoneOffset() { if (null === $this->offset) { $time = new \DateTime('now', new \DateTimeZone($this->localeSettings->getTimeZone())); $this->offset = $time->format('P'); } return $this->offset; }
/** * @param BuildAfter $event */ public function onBuildAfter(BuildAfter $event) { $datagrid = $event->getDatagrid(); $datasource = $datagrid->getDatasource(); if ($datasource instanceof OrmDatasource) { $parameters = $datagrid->getParameters(); $entityClass = $this->entityRoutingHelper->decodeClassName($parameters->get('entityClass')); $entityId = $parameters->get('entityId'); $qb = $datasource->getQueryBuilder(); // apply activity filter $this->activityManager->addFilterByTargetEntity($qb, $entityClass, $entityId); // apply filter by date $start = new \DateTime('now', new \DateTimeZone($this->localeSettings->getTimeZone())); $start->setTime(0, 0, 0); $qb->andWhere('event.start >= :date OR event.end >= :date')->setParameter('date', $start); } }
/** * @param $expectedValue * @param $configurationValue * @dataProvider getTimeZoneDataProvider */ public function testGetTimeZone($expectedValue, $configurationValue) { $this->configManager->expects($this->once())->method('get')->with('oro_locale.timezone', false)->will($this->returnValue($configurationValue)); $this->assertEquals($expectedValue, $this->localeSettings->getTimeZone()); $this->assertEquals($expectedValue, $this->localeSettings->getTimeZone()); }
/** * @param LocaleSettings $localeSettings */ public function __construct(LocaleSettings $localeSettings) { $this->timezone = new \DateTimeZone($localeSettings->getTimeZone()); }
/** * {@inheritDoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['field_type' => 'datetime', 'field_options' => ['format' => 'yyyy-MM-dd HH:mm', 'view_timezone' => $this->localeSettings->getTimeZone()]]); }
/** * @return string */ public function getTimeZoneOffset() { $date = new \DateTime('now', new \DateTimeZone($this->localeSettings->getTimeZone())); return $date->format('P'); }
/** * {@inheritDoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array('field_type' => 'datetime', 'field_options' => array('format' => 'yyyy-MM-dd HH:mm', 'view_timezone' => $this->localeSettings->getTimeZone()))); }