コード例 #1
0
ファイル: Parser.php プロジェクト: Maksold/platform
 /**
  * @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();
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
 /**
  * @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);
 }
コード例 #4
0
 /**
  * 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'));
 }
コード例 #5
0
ファイル: CreateDate.php プロジェクト: Maksold/platform
 /**
  * {@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);
 }
コード例 #6
0
 /**
  * @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;
 }
コード例 #7
0
 /**
  * @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];
 }
コード例 #8
0
 /**
  * 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;
 }
コード例 #9
0
 /**
  * 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;
 }
コード例 #10
0
 /**
  * @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);
     }
 }
コード例 #11
0
 /**
  * @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());
 }
コード例 #12
0
 /**
  * @param LocaleSettings $localeSettings
  */
 public function __construct(LocaleSettings $localeSettings)
 {
     $this->timezone = new \DateTimeZone($localeSettings->getTimeZone());
 }
コード例 #13
0
 /**
  * {@inheritDoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['field_type' => 'datetime', 'field_options' => ['format' => 'yyyy-MM-dd HH:mm', 'view_timezone' => $this->localeSettings->getTimeZone()]]);
 }
コード例 #14
0
ファイル: LocaleExtension.php プロジェクト: ramunasd/platform
 /**
  * @return string
  */
 public function getTimeZoneOffset()
 {
     $date = new \DateTime('now', new \DateTimeZone($this->localeSettings->getTimeZone()));
     return $date->format('P');
 }
コード例 #15
0
 /**
  * {@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())));
 }