private function checkBlockAndDates($crawler, $season)
 {
     // Title present
     $blockTitle = $this->client->getContainer()->get('translator')->trans('season.block.title', array(), 'default');
     $this->assertTrue($crawler->filter('html:contains("' . $blockTitle . '")')->count() == 1);
     // TODO: Retrieve locale client.... returns null: $this->client->getContainer()->get('session')->get('_locale');
     $fmt = datefmt_create('fr_FR', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE);
     // dates compliant
     $this->assertTrue($crawler->filter('html:contains("' . datefmt_format($fmt, $season->getStartDate()) . '")')->count() == 1);
     $this->assertTrue($crawler->filter('html:contains("' . datefmt_format($fmt, $season->getEndDate()) . '")')->count() == 1);
 }
Exemple #2
0
 /**
  * @param \DateTime|int $value
  * @return Carbon|string
  */
 public function fromDateTime($value)
 {
     try {
         $result = parent::fromDateTime($value);
     } catch (InvalidArgumentException $e) {
         $containsTime = strpos($value, ':') !== false ? 3 : -1;
         $formatter = datefmt_create(\App::getLocale(), 3, $containsTime);
         $value = $formatter->parse($value);
         $format = $this->getDateFormat();
         $value = Carbon::createFromTimestamp($value);
         return $value->format($format);
     }
     return $result;
 }
Exemple #3
0
 public static function format($date, $dateFormat = self::SHORT, $timeFormat = self::NONE, $customPattern = null)
 {
     if (!$date instanceof Carbon) {
         try {
             $date = new Carbon($date);
         } catch (\Exception $e) {
             return null;
         }
     }
     if (!function_exists('datefmt_create')) {
         throw new \Exception('You must install "intl" php extension.');
     }
     $formatter = datefmt_create(App::getLocale(), $dateFormat, $timeFormat, \Config::get('app.timezone'), null, $customPattern);
     $pattern = $formatter->getPattern();
     $pattern = str_replace('yy', 'y', $pattern);
     $formatter->setPattern($pattern);
     return $formatter->format($date);
 }
 /**
  * Returns a new Time object after parsing the provided time string based on
  * the passed or configured date time format. This method is locale dependent,
  * Any string that is passed to this function will be interpreted as a locale
  * dependent string.
  *
  * When no $format is provided, the `toString` format will be used.
  *
  * If it was impossible to parse the provided time, null will be returned.
  *
  * Example:
  *
  * ```
  *  $time = Time::parseDateTime('10/13/2013 12:54am');
  *  $time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm');
  *  $time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, -1]);
  * ```
  *
  * @param string $time The time string to parse.
  * @param string|array|null $format Any format accepted by IntlDateFormatter.
  * @return static|null
  */
 public static function parseDateTime($time, $format = null)
 {
     $dateFormat = $format ?: static::$_toStringFormat;
     $timeFormat = $pattern = null;
     if (is_array($dateFormat)) {
         list($newDateFormat, $timeFormat) = $dateFormat;
         $dateFormat = $newDateFormat;
     } else {
         $pattern = $dateFormat;
         $dateFormat = null;
     }
     if (static::$_isDateInstance === null) {
         static::$_isDateInstance = is_subclass_of(static::class, ChronosDate::class) || is_subclass_of(static::class, MutableDate::class);
     }
     $defaultTimezone = static::$_isDateInstance ? 'UTC' : date_default_timezone_get();
     $formatter = datefmt_create(static::$defaultLocale, $dateFormat, $timeFormat, $defaultTimezone, null, $pattern);
     $time = $formatter->parse($time);
     if ($time !== false) {
         $result = new static('@' . $time);
         return static::$_isDateInstance ? $result : $result->setTimezone($defaultTimezone);
     }
     return null;
 }
 /**
  * Returns a new Time object after parsing the provided time string based on
  * the passed or configured date time format. This method is locale dependent,
  * Any string that is passed to this function will be interpreted as a locale
  * dependent string.
  *
  * When no $format is provided, the `toString` format will be used.
  *
  * If it was impossible to parse the provided time, null will be returned.
  *
  * Example:
  *
  * ```
  *  $time = Time::parseDateTime('10/13/2013 12:54am');
  *  $time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm');
  *  $time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, -1]);
  * ```
  *
  * @param string $time The time string to parse.
  * @param string|array $format Any format accepted by IntlDateFormatter.
  * @return static|null
  */
 public static function parseDateTime($time, $format = null)
 {
     $dateFormat = $format ?: static::$_toStringFormat;
     $timeFormat = $pattern = null;
     if (is_array($dateFormat)) {
         list($newDateFormat, $timeFormat) = $dateFormat;
         $dateFormat = $newDateFormat;
     } else {
         $pattern = $dateFormat;
         $dateFormat = null;
     }
     $formatter = datefmt_create(static::$defaultLocale, $dateFormat, $timeFormat, date_default_timezone_get(), null, $pattern);
     $time = $formatter->parse($time);
     if ($time !== false) {
         $result = new static('@' . $time);
         return $result->setTimezone(date_default_timezone_get());
     }
     return null;
 }
Exemple #6
0
 /**
  * Returns a translated and localized date string.
  * Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
  *
  * @param \DateTime $date
  * @param string|int|array $format
  * @param string $locale
  * @return string
  */
 protected function _formatObject($date, $format, $locale)
 {
     $pattern = $dateFormat = $timeFormat = $calendar = null;
     if (is_array($format)) {
         list($dateFormat, $timeFormat) = $format;
     } elseif (is_numeric($format)) {
         $dateFormat = $format;
     } else {
         $dateFormat = $timeFormat = IntlDateFormatter::FULL;
         $pattern = $format;
     }
     $timezone = $date->getTimezone()->getName();
     $formatter = datefmt_create($locale, $dateFormat, $timeFormat, $timezone === '+00:00' ? 'UTC' : $timezone, $calendar, $pattern);
     return $formatter->format($date);
 }
 public function preview(Request $request, Application $app, $quoteId)
 {
     if (!isset($quoteId)) {
         return $this->redirectMessage($app, 'Parâmetros inválidos', '/project');
     }
     $quote = $app['orm.em']->getRepository('Orcamentos\\Model\\Quote')->find($quoteId);
     if ($quote->getProject()->getCompany()->getId() != $app['session']->get('companyId')) {
         return $this->redirectMessage($app, 'Orçamento inválido', '/project');
     }
     $d = new DateTime($quote->getCreated());
     $fmt = datefmt_create("pt_BR", IntlDateFormatter::LONG, IntlDateFormatter::NONE, 'America/Sao_Paulo', IntlDateFormatter::GREGORIAN);
     $city = '';
     if ($quote->getProject()->getCompany()->getCity()) {
         $city = $quote->getProject()->getCompany()->getCity() . ', ';
     }
     $createdSignature = $city . datefmt_format($fmt, $d);
     return $app['twig']->render('share/detail.twig', array('quote' => $quote, 'createdSignature' => $createdSignature));
 }
 private function createdSignature($created, $city)
 {
     $d = new DateTime($created);
     $fmt = datefmt_create("pt_BR", \IntlDateFormatter::LONG, \IntlDateFormatter::NONE, 'America/Sao_Paulo', \IntlDateFormatter::GREGORIAN);
     $cityName = '';
     if ($city) {
         $cityName = $city . ', ';
     }
     return $cityName . datefmt_format($fmt, $d);
 }
Exemple #9
0
 protected function validateDateWithLocale($attribute, $value)
 {
     if ($this->validateDate($attribute, $value, [])) {
         return true;
     }
     $containsTime = strpos($value, ':') !== false ? 3 : -1;
     $formatter = datefmt_create(\App::getLocale(), 3, $containsTime);
     $value = $formatter->parse($value);
     return $value !== false;
 }
Exemple #10
0
<?php

header('Content-type: text/html; charset=utf-8');
require __DIR__ . '/vendor/autoload.php';
$params = array_merge(require __DIR__ . '/config.php');
$fmt = datefmt_create('ru_RU', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN);
$db = new MysqliDb($params['db_config']);
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>';
echo '<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">';
echo '<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>';
/*
action block's
*/
if (isset($_GET['bank']) and $_GET['bank'] != null) {
    echo "<a href='#' onclick='history.back()'>Вернуться назад</a> <br />";
    $db->where("bank_id", $_GET['bank']);
    $provodki = $db->get("provodki");
    echo '<table class="td-prov"><tbody><tr><td>Дата</td><td>Коментарий</td><td>Сумма</td></tr></tbody>';
    if ($db->count > 0) {
        foreach ($provodki as $prov) {
            $date = datefmt_format($fmt, $prov['date']);
            echo "<tr><td>{$date}</td><td>{$prov['com']}</td><td>{$prov['sum']}</td>";
        }
    }
    echo '</table>';
    $db->where("bank_id", $_GET['bank']);
    $sum = $db->getValue("provodki", "sum(sum)");
    echo "Итого: {$sum} <br />";
    die;
}
//end if(isset($_GET['bank']) and $_GET['bank']!=null)
 /**
  * @param int $unixTimestamp
  * @param string $context
  * @param int $languageCode
  * @return string
  */
 public static function formatDateTime($unixTimestamp, $context = null, $languageCode = null)
 {
     $data = array('timestamp' => $unixTimestamp, 'context' => $context);
     $formattedDate = ipJob('ipFormatDateTime', $data);
     if ($formattedDate === null) {
         if (function_exists('datefmt_create') && function_exists('datefmt_format')) {
             if ($languageCode === null) {
                 if ($context == 'Ip-admin') {
                     $code = ipConfig()->adminLocale();
                 } else {
                     $languageCode = ipContent()->getCurrentLanguage()->getId();
                     $code = $languageCode;
                 }
             }
             $locale = str_replace('-', '_', $languageCode);
             $fmt = datefmt_create($locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT, date_default_timezone_get());
             $formattedDate = datefmt_format($fmt, $unixTimestamp);
         } else {
             $formattedDate = date('Y-m-d H:i', $unixTimestamp);
         }
     }
     return $formattedDate;
 }
Exemple #12
0
 /**
  * Returns a translated and localized date string.
  * Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
  *
  * @param \DateTime $date Date.
  * @param string|int|array $format Format.
  * @param string $locale The locale name in which the date should be displayed.
  * @return string
  */
 protected function _formatObject($date, $format, $locale)
 {
     $pattern = $dateFormat = $timeFormat = $calendar = null;
     if (is_array($format)) {
         list($dateFormat, $timeFormat) = $format;
     } elseif (is_numeric($format)) {
         $dateFormat = $format;
     } else {
         $dateFormat = $timeFormat = IntlDateFormatter::FULL;
         $pattern = $format;
     }
     $timezone = $date->getTimezone()->getName();
     $key = "{$locale}.{$dateFormat}.{$timeFormat}.{$timezone}.{$calendar}.{$pattern}";
     if (!isset(static::$_formatters[$key])) {
         static::$_formatters[$key] = datefmt_create($locale, $dateFormat, $timeFormat, $timezone === '+00:00' ? 'UTC' : $timezone, $calendar, $pattern);
     }
     return static::$_formatters[$key]->format($date);
 }
Exemple #13
0
 /**
  * Returns a new Time object after parsing the provided time string based on
  * the passed or configured date time format. This method is locale dependent,
  * Any string that is passed to this function will be interpreted as a locale
  * dependent string.
  *
  * When no $format is provided, the `toString` format will be used.
  *
  * If it was impossible to parse the provided time, null will be returned.
  *
  * Example:
  *
  * ```
  *  $time = Time::parseDateTime('10/13/2013 12:54am');
  *  $time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm');
  *  $time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, -1]);
  * ```
  *
  * @param string $time The time string to parse.
  * @param string|array $format Any format accepted by IntlDateFormatter.
  * @return static|null
  */
 public static function parseDateTime($time, $format = null)
 {
     $dateFormat = $format ?: static::$_toStringFormat;
     $timeFormat = $pattern = null;
     if (is_array($dateFormat)) {
         list($newDateFormat, $timeFormat) = $dateFormat;
         $dateFormat = $newDateFormat;
     } else {
         $pattern = $dateFormat;
         $dateFormat = null;
     }
     $formatter = datefmt_create(static::$defaultLocale, $dateFormat, $timeFormat, null, null, $pattern);
     $time = $formatter->parse($time);
     if ($time) {
         return new static('@' . $time);
     }
     return null;
 }