/**
  * Formats date time according to locale settings.
  *
  * Options format:
  * array(
  *     'dateType' => <dateType>,
  *     'locale' => <locale>,
  *     'timeZone' => <timeZone>,
  * )
  *
  * @param \DateTime|string|int $date
  * @param array $options
  * @return string
  */
 public function formatDate($date, array $options = array())
 {
     $dateType = $this->getOption($options, 'dateType');
     $locale = $this->getOption($options, 'locale');
     $timeZone = $this->getOption($options, 'timeZone');
     return $this->formatter->formatDate($date, $dateType, $locale, $timeZone);
 }
 /**
  * {@inheritdoc}
  */
 public function getViewValue($value)
 {
     switch ($value['type']) {
         case AbstractDateFilterType::TYPE_MORE_THAN:
             return sprintf('%s %s', $this->translator->trans('oro.filter.form.label_date_type_more_than'), $this->formatter->formatDate($value['start']));
         case AbstractDateFilterType::TYPE_LESS_THAN:
             return sprintf('%s %s', $this->translator->trans('oro.filter.form.label_date_type_less_than'), $this->formatter->formatDate($value['end']));
     }
     return sprintf('%s - %s', $this->formatter->formatDate($value['start']), $this->formatter->formatDate($value['end']));
 }
Ejemplo n.º 3
0
 /**
  * @param Reminder $reminder
  * @return array
  */
 public function getMessageParams(Reminder $reminder)
 {
     $now = new \DateTime();
     $expiredDate = $this->dateTimeFormatter->formatDate($reminder->getExpireAt(), \IntlDateFormatter::SHORT);
     $nowDate = $this->dateTimeFormatter->formatDate($now, \IntlDateFormatter::SHORT);
     if ($expiredDate === $nowDate) {
         $expireAt = $this->dateTimeFormatter->formatTime($reminder->getExpireAt());
     } else {
         $expireAt = $this->dateTimeFormatter->format($reminder->getExpireAt());
     }
     return array('templateId' => $this->getTemplateId($reminder), 'expireAt' => $expireAt, 'subject' => $reminder->getSubject(), 'url' => $this->urlProvider->getUrl($reminder), 'id' => $reminder->getId(), 'uniqueId' => md5($reminder->getRelatedEntityClassName() . $reminder->getRelatedEntityId()));
 }
 /**
  * @dataProvider formatDateDataProvider
  */
 public function testFormatDate($expected, $date, $dateType, $locale, $timeZone, $language, $defaultLocale = null, $defaultTimeZone = null)
 {
     $this->localeSettings->expects($this->once())->method('getLanguage')->will($this->returnValue($language));
     $methodCalls = 1;
     if ($defaultLocale) {
         $this->localeSettings->expects($this->once())->method('getLocale')->will($this->returnValue($defaultLocale));
         $methodCalls++;
     }
     if ($defaultTimeZone) {
         $this->localeSettings->expects($this->once())->method('getTimeZone')->will($this->returnValue($defaultTimeZone));
         $methodCalls++;
     }
     $this->localeSettings->expects($this->exactly($methodCalls))->method($this->anything());
     $this->assertEquals($expected, $this->formatter->formatDate($date, $dateType, $locale, $timeZone));
 }
Ejemplo n.º 5
0
 /**
  * Apply formatting to totals values
  *
  * @param mixed|null $val
  * @param string|null $formatter
  * @return string|null
  */
 protected function applyFrontendFormatting($val = null, $formatter = null)
 {
     if (null != $formatter) {
         switch ($formatter) {
             case PropertyInterface::TYPE_DATE:
                 $val = $this->dateTimeFormatter->formatDate($val);
                 break;
             case PropertyInterface::TYPE_DATETIME:
                 $val = $this->dateTimeFormatter->format($val);
                 break;
             case PropertyInterface::TYPE_TIME:
                 $val = $this->dateTimeFormatter->formatTime($val);
                 break;
             case PropertyInterface::TYPE_DECIMAL:
                 $val = $this->numberFormatter->formatDecimal($val);
                 break;
             case PropertyInterface::TYPE_INTEGER:
                 $val = $this->numberFormatter->formatDecimal($val);
                 break;
             case PropertyInterface::TYPE_PERCENT:
                 $val = $this->numberFormatter->formatPercent($val);
                 break;
             case PropertyInterface::TYPE_CURRENCY:
                 $val = $this->numberFormatter->formatCurrency($val);
                 break;
         }
     }
     return $val;
 }
 /**
  * @param string $value
  * @param array $options
  * @return string
  */
 protected function applyFrontendFormatting($value, array $options)
 {
     $frontendType = isset($options['frontend_type']) ? $options['frontend_type'] : null;
     switch ($frontendType) {
         case PropertyInterface::TYPE_DATE:
             $value = $this->dateTimeFormatter->formatDate($value);
             break;
         case PropertyInterface::TYPE_DATETIME:
             $value = $this->dateTimeFormatter->format($value);
             break;
         case PropertyInterface::TYPE_DECIMAL:
             $value = $this->numberFormatter->formatDecimal($value);
             break;
         case PropertyInterface::TYPE_INTEGER:
             $value = $this->numberFormatter->formatDecimal($value);
             break;
         case PropertyInterface::TYPE_BOOLEAN:
             $value = $this->translator->trans((bool) $value ? self::YES_LABEL_KEY : self::NO_LABEL_KEY);
             break;
         case PropertyInterface::TYPE_PERCENT:
             $value = $this->numberFormatter->formatPercent($value);
             break;
         case PropertyInterface::TYPE_CURRENCY:
             $value = $this->numberFormatter->formatCurrency($value);
             break;
         case PropertyInterface::TYPE_SELECT:
             if (isset($options['choices'][$value])) {
                 $value = $this->translator->trans($options['choices'][$value]);
             }
             break;
     }
     return $value;
 }
Ejemplo n.º 7
0
 /**
  * @param array $ownerIds
  * @param \DateTime|string|int $date
  * @return mixed
  */
 protected function getOwnersValues(array $ownerIds, $date)
 {
     $key = sha1(implode('_', $ownerIds) . $this->dateTimeFormatter->formatDate($date));
     if (!isset($this->ownersValues[$key])) {
         $this->ownersValues[$key] = $this->doctrine->getRepository('OroCRMSalesBundle:Opportunity')->getForecastOfOpporunitiesData($ownerIds, $date, $this->aclHelper);
     }
     return $this->ownersValues[$key];
 }
Ejemplo n.º 8
0
 /**
  * @dataProvider formatDateDataProvider
  */
 public function testFormatDate($expectedDateType, \DateTime $date, $dateType, $locale, $timeZone, $language, $defaultLocale = null, $defaultTimeZone = null)
 {
     $this->localeSettings->expects($this->once())->method('getLanguage')->will($this->returnValue($language));
     $methodCalls = 1;
     if ($defaultLocale) {
         $this->localeSettings->expects($this->once())->method('getLocale')->will($this->returnValue($defaultLocale));
         $methodCalls++;
     }
     if ($defaultTimeZone) {
         $this->localeSettings->expects($this->once())->method('getTimeZone')->will($this->returnValue($defaultTimeZone));
         $methodCalls++;
     }
     $this->localeSettings->expects($this->exactly($methodCalls))->method($this->anything());
     $pattern = $this->getPattern($locale ?: $defaultLocale, $expectedDateType, \IntlDateFormatter::NONE);
     $formatter = $this->getFormatter($language, $timeZone ?: $defaultTimeZone, $pattern);
     $expected = $formatter->format((int) $date->format('U'));
     $this->assertEquals($expected, $this->formatter->formatDate($date, $dateType, $locale, $timeZone));
 }
Ejemplo n.º 9
0
 /**
  * Returns a string represents a range between $startDate and $endDate, formatted according the given parameters
  * Examples:
  *      $endDate is not specified
  *          Thu Oct 17, 2013 - when $skipTime = true
  *          Thu Oct 17, 2013 5:30pm - when $skipTime = false
  *      $startDate equals to $endDate
  *          Thu Oct 17, 2013 - when $skipTime = true
  *          Thu Oct 17, 2013 5:30pm - when $skipTime = false
  *      $startDate and $endDate are the same day
  *          Thu Oct 17, 2013 - when $skipTime = true
  *          Thu Oct 17, 2013 5:00pm – 5:30pm - when $skipTime = false
  *      $startDate and $endDate are different days
  *          Thu Oct 17, 2013 5:00pm – Thu Oct 18, 2013 5:00pm - when $skipTime = false
  *          Thu Oct 17, 2013 – Thu Oct 18, 2013 - when $skipTime = true
  *
  * @param \DateTime|null    $startDate
  * @param \DateTime|null    $endDate
  * @param bool              $skipTime
  * @param string|null       $dateTimeFormat
  * @param string|int|null   $dateType \IntlDateFormatter constant or it's string name
  * @param string|int|null   $timeType \IntlDateFormatter constant or it's string name
  * @param string|null       $locale
  * @param string|null       $timeZone
  *
  * @return string
  */
 public function formatCalendarDateRange(\DateTime $startDate = null, \DateTime $endDate = null, $skipTime = false, $dateTimeFormat = null, $dateType = null, $timeType = null, $locale = null, $timeZone = null)
 {
     if (is_null($startDate)) {
         // exit because nothing to format.
         // We have to accept null as $startDate because the validator of email templates calls functions
         // with empty arguments
         return '';
     }
     // check if $endDate is not specified or $startDate equals to $endDate
     if (is_null($endDate) || $startDate == $endDate) {
         return $skipTime ? $this->formatter->formatDate($startDate, $dateType, $locale, $timeZone) : $this->formatter->format($startDate, $dateType, $timeType, $locale, $timeZone);
     }
     // check if $startDate and $endDate are the same day
     if ($startDate->format('Ymd') == $endDate->format('Ymd')) {
         if ($skipTime) {
             return $this->formatter->formatDate($startDate, $dateType, $locale, $timeZone);
         }
         return sprintf('%s %s - %s', $this->formatter->formatDate($startDate, $dateType, $locale, $timeZone), $this->formatter->formatTime($startDate, $timeType, $locale, $timeZone), $this->formatter->formatTime($endDate, $timeType, $locale, $timeZone));
     }
     // $startDate and $endDate are different days
     if ($skipTime) {
         return sprintf('%s - %s', $this->formatter->formatDate($startDate, $dateType, $locale, $timeZone), $this->formatter->formatDate($endDate, $dateType, $locale, $timeZone));
     }
     return sprintf('%s - %s', $this->formatter->format($startDate, $dateTimeFormat, $locale, $timeZone), $this->formatter->format($endDate, $dateTimeFormat, $locale, $timeZone));
 }
Ejemplo n.º 10
0
 /**
  * @param WidgetOptionBag $widgetOptions
  * @param                 $getterName
  * @param                 $dataType
  * @param bool            $lessIsBetter
  * @return array
  */
 public function getBigNumberValues(WidgetOptionBag $widgetOptions, $getterName, $dataType, $lessIsBetter = false)
 {
     $lessIsBetter = (bool) $lessIsBetter;
     $result = [];
     $dateRange = $widgetOptions->get('dateRange');
     $value = $this->{$getterName}($dateRange);
     $result['value'] = $this->formatValue($value, $dataType);
     $previousInterval = $widgetOptions->get('usePreviousInterval', []);
     if (count($previousInterval)) {
         $pastResult = $this->{$getterName}($previousInterval);
         $result['deviation'] = $this->translator->trans('orocrm.magento.dashboard.e_commerce_statistic.no_changes');
         $deviation = $value - $pastResult;
         if ($pastResult != 0 && $dataType !== 'percent') {
             if ($deviation != 0) {
                 $deviationPercent = $deviation / $pastResult;
                 $result['deviation'] = sprintf('%s (%s)', $this->formatValue($deviation, $dataType, true), $this->formatValue($deviationPercent, 'percent', true));
                 if (!$lessIsBetter) {
                     $result['isPositive'] = $deviation > 0;
                 } else {
                     $result['isPositive'] = !($deviation > 0);
                 }
             }
         } else {
             if (round($deviation * 100, 0) != 0) {
                 $result['deviation'] = $this->formatValue($deviation, $dataType, true);
                 if (!$lessIsBetter) {
                     $result['isPositive'] = $deviation > 0;
                 } else {
                     $result['isPositive'] = !($deviation > 0);
                 }
             }
         }
         $result['previousRange'] = sprintf('%s - %s', $this->dateTimeFormatter->formatDate($previousInterval['start']), $this->dateTimeFormatter->formatDate($previousInterval['end']));
     }
     return $result;
 }
 /**
  * @param array $result
  * @param bool  $addValue
  */
 protected function addCurrentDateAndTime(array &$result, $addValue)
 {
     if ($addValue) {
         $dateTime = new \DateTime('now', new \DateTimeZone('UTC'));
         $dateTimeVal = $dateTime;
         $dateVal = $this->dateTimeFormatter->formatDate($dateTime);
         $timeVal = $this->dateTimeFormatter->formatTime($dateTime);
     } else {
         $dateTimeVal = ['type' => 'datetime', 'label' => $this->translator->trans('oro.email.emailtemplate.current_datetime')];
         $dateVal = ['type' => 'string', 'label' => $this->translator->trans('oro.email.emailtemplate.current_date')];
         $timeVal = ['type' => 'string', 'label' => $this->translator->trans('oro.email.emailtemplate.current_time')];
     }
     // @todo: the datetime object cannot be added due __toString of DateTime is not allowed error
     //        this code can be uncommented after validation and formatting are fixed
     //$result['currentDateTime'] = $dateTimeVal;
     $result['currentDate'] = $dateVal;
     $result['currentTime'] = $timeVal;
 }
Ejemplo n.º 12
0
 /**
  * @param mixed       $val
  * @param array       $options
  *
  * @return string|null
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function applyFrontendFormatting($val, $options)
 {
     if (null !== $val) {
         $frontendType = isset($options['frontend_type']) ? $options['frontend_type'] : null;
         switch ($frontendType) {
             case PropertyInterface::TYPE_DATE:
                 $val = $this->dateTimeFormatter->formatDate($val);
                 break;
             case PropertyInterface::TYPE_DATETIME:
                 $val = $this->dateTimeFormatter->format($val);
                 break;
             case PropertyInterface::TYPE_TIME:
                 $val = $this->dateTimeFormatter->formatTime($val);
                 break;
             case PropertyInterface::TYPE_DECIMAL:
                 $val = $this->numberFormatter->formatDecimal($val);
                 break;
             case PropertyInterface::TYPE_INTEGER:
                 $val = $this->numberFormatter->formatDecimal($val);
                 break;
             case PropertyInterface::TYPE_BOOLEAN:
                 $val = $this->translator->trans((bool) $val ? 'Yes' : 'No', [], 'jsmessages');
                 break;
             case PropertyInterface::TYPE_PERCENT:
                 $val = $this->numberFormatter->formatPercent($val);
                 break;
             case PropertyInterface::TYPE_CURRENCY:
                 $val = $this->numberFormatter->formatCurrency($val);
                 break;
             case PropertyInterface::TYPE_SELECT:
                 if (isset($options['choices'][$val])) {
                     $val = $this->translator->trans($options['choices'][$val]);
                 }
                 break;
             case PropertyInterface::TYPE_HTML:
                 $val = $this->formatHtmlFrontendType($val, isset($options['export_type']) ? $options['export_type'] : null);
                 break;
         }
     }
     return $val;
 }
Ejemplo n.º 13
0
 /**
  * @param DateTime $from
  * @param DateTime $to
  *
  * @return string
  */
 protected function createPeriodLabel(DateTime $from, DateTime $to)
 {
     return sprintf('%s - %s', $this->dateTimeFormatter->formatDate($from), $this->dateTimeFormatter->formatDate($to));
 }
Ejemplo n.º 14
0
 /**
  * @param \DateTime $value
  * @return string
  */
 protected function getValueForDateTime(\DateTime $value)
 {
     return $this->dateTimeFormatter->formatDate($value);
 }