Example #1
1
 /**
  * Dodatkowe filtry Twig zwiazane z formatowaniem danych uzytkownika
  *
  * @return array
  */
 public function getFilters()
 {
     return [new Twig_SimpleFilter('format_date', function ($dateTime, $diffForHumans = true) {
         $format = Auth::check() ? auth()->user()->date_format : '%Y-%m-%d %H:%M';
         if (!$dateTime instanceof Carbon) {
             $dateTime = new Carbon($dateTime);
         }
         $now = Carbon::now();
         if (!$diffForHumans) {
             return $dateTime->formatLocalized($format);
         } elseif ($dateTime->diffInHours($now) < 1) {
             return $dateTime->diffForHumans(null, true) . ' temu';
         } elseif ($dateTime->isToday()) {
             return 'dziÅ›, ' . $dateTime->format('H:i');
         } elseif ($dateTime->isYesterday()) {
             return 'wczoraj, ' . $dateTime->format('H:i');
         } else {
             return $dateTime->formatLocalized($format);
         }
     }), new Twig_SimpleFilter('timestamp', function ($dateTime) {
         if ($dateTime instanceof Carbon) {
             return $dateTime->getTimestamp();
         } else {
             return strtotime($dateTime);
         }
     })];
 }
 /**
  * Get the trial end timestamp for a Stripe subscription update.
  *
  * @return int
  */
 protected function getTrialEndForUpdate()
 {
     if ($this->skipTrial) {
         return 'now';
     }
     return $this->trialEnd ? $this->trialEnd->getTimestamp() : null;
 }
 public static function diffInDates(Carbon $date1, Carbon $date2)
 {
     $date1ToSeconds = $date1->getTimestamp();
     $date2ToSeconds = $date2->getTimestamp();
     $difference = $date1ToSeconds - $date2ToSeconds;
     return self::differenceToTime($difference);
 }
Example #4
0
 /**
  * {@inheritdoc}
  *
  * @return int
  */
 public function extract($model)
 {
     $value = parent::extract($model);
     if ($value === null) {
         return null;
     }
     if (!$value instanceof Carbon) {
         $value = new Carbon($value);
     }
     return $value->getTimestamp();
 }
Example #5
0
 /**
  * Registers CMS markup tags introduced by this plugin.
  *
  * @return  array
  */
 public function registerMarkupTags()
 {
     return ['filters' => ['strftime' => function ($time, $format) {
         static $locale;
         if (!$locale) {
             $locale = Lang::getLocale();
             Carbon::setLocale($locale);
             setlocale(LC_TIME, sprintf('%s_%s.UTF-8', $locale, strtoupper($locale)));
         }
         if (!$time instanceof Carbon) {
             $time = new Carbon($time);
         }
         return strftime($format, $time->getTimestamp());
     }]];
 }
Example #6
0
 /**
  *
  * Returns last post's published_at timestamp for current year
  * or $year/12/31 00:00:00 timestamp for other years
  *
  * @param $year
  * @return int
  */
 protected static function getMtime($year)
 {
     if ($year == date('Y')) {
         $post = BlogPost::orderBy('published_at', 'desc')->isPublished()->first();
         if ($post) {
             $date = new Carbon($post->published_at);
         } else {
             // if no posts, set date to the first of january
             $date = new Carbon();
             $date->setDateTime(date('Y'), 1, 1, 0, 0, 0);
         }
     } else {
         // previous year
         $date = new Carbon();
         $date->setDateTime($year, 12, 31, 0, 0, 0);
     }
     return $date->getTimestamp();
 }
 /**
  * Serialize SharePoint Access Token
  *
  * @access  public
  * @return  string
  */
 public function serialize()
 {
     return serialize([$this->token, $this->expires->getTimestamp(), $this->expires->getTimezone()->getName()]);
 }
Example #8
0
 /**
  * Add Twig extensions
  *
  * @see Text extensions http://twig.sensiolabs.org/doc/extensions/text.html
  * @see Intl extensions http://twig.sensiolabs.org/doc/extensions/intl.html
  * @see Array extension http://twig.sensiolabs.org/doc/extensions/array.html
  * @see Time extension http://twig.sensiolabs.org/doc/extensions/date.html
  *
  * @return array
  */
 public function registerMarkupTags()
 {
     $twig = App::make('twig.environment');
     $filters = [];
     // add Text extensions
     $textExtension = new \Twig_Extensions_Extension_Text();
     $textFilters = $textExtension->getFilters();
     $filters += ['truncate' => function ($value, $length = 30, $preserve = false, $separator = '...') use($twig, $textFilters) {
         $callable = $textFilters['0']->getCallable();
         return $callable($twig, $value, $length, $preserve, $separator);
     }, 'wordwrap' => function ($value, $length = 80, $separator = "\n", $preserve = false) use($twig, $textFilters) {
         $callable = $textFilters['1']->getCallable();
         return $callable($twig, $value, $length, $separator, $preserve);
     }];
     // add Intl extensions if php5-intl installed
     if (class_exists('IntlDateFormatter')) {
         $intlExtension = new \Twig_Extensions_Extension_Intl();
         $intlFilters = $intlExtension->getFilters();
         $filters += ['localizeddate' => function ($date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null) use($twig, $intlFilters) {
             $callable = $intlFilters['0']->getCallable();
             return $callable($twig, $date, $dateFormat, $timeFormat, $locale, $timezone, $format);
         }, 'localizednumber' => function ($number, $style = 'decimal', $type = 'default', $locale = null) use($twig, $intlFilters) {
             $callable = $intlFilters['1']->getCallable();
             return $callable($twig, $number, $style, $type, $locale);
         }, 'localizedcurrency' => function ($number, $currency = null, $locale = null) use($twig, $intlFilters) {
             $callable = $intlFilters['2']->getCallable();
             return $callable($twig, $number, $currency, $locale);
         }];
     }
     // add Array extensions
     $arrayExtension = new \Twig_Extensions_Extension_Array();
     $arrayFilters = $arrayExtension->getFilters();
     $filters += ['shuffle' => function ($array) use($twig, $arrayFilters) {
         $callable = $arrayFilters['0']->getCallable();
         return $callable($twig, $array);
     }];
     // add Time extensions
     $timeExtension = new \Twig_Extensions_Extension_Date();
     $timeFilters = $timeExtension->getFilters();
     $filters += ['time_diff' => function ($date, $now = null) use($twig, $timeFilters) {
         $callable = $timeFilters['0']->getCallable();
         return $callable($twig, $date, $now);
     }];
     // add PHP functions
     $filters += ['strftime' => function ($time, $format = '%d.%m.%Y %H:%M:%S') {
         $timeObj = new Carbon($time);
         return strftime($format, $timeObj->getTimestamp());
     }, 'uppercase' => function ($string) {
         return strtoupper($string);
     }, 'lowercase' => function ($string) {
         return strtolower($string);
     }, 'ucfirst' => function ($string) {
         return ucfirst($string);
     }, 'lcfirst' => function ($string) {
         return lcfirst($string);
     }, 'ltrim' => function ($string, $charlist = " \t\n\r\v") {
         return ltrim($string, $charlist);
     }, 'rtrim' => function ($string, $charlist = " \t\n\r\v") {
         return rtrim($string, $charlist);
     }, 'str_repeat' => function ($string, $multiplier = 1) {
         return str_repeat($string, $multiplier);
     }, 'plural' => function ($string, $count = 2) {
         return str_plural($string, $count);
     }];
     return ['filters' => $filters];
 }
Example #9
0
 /**
  *
  * Checks if current date in in range of ($first_date:time())
  *
  * @return bool
  */
 protected function isInRange()
 {
     $first_date = self::getFirstDate();
     if (!$this->month) {
         $first_date->month(1);
     }
     if (!$this->day) {
         $first_date->day(1);
     }
     $now = new Carbon();
     $year = $this->year;
     $month = !$this->month ? '1' : $this->month;
     $day = !$this->day ? '1' : $this->day;
     $current = new Carbon();
     $current->setDate($year, $month, $day);
     $current->setTime(0, 0);
     return $first_date->getTimestamp() <= $current->getTimestamp() && $current->getTimestamp() <= $now->getTimestamp();
 }
 public function fullmix($dateType, $timeType, Carbon $carbon)
 {
     $fmt = new IntlDateFormatter($this->langCode, $this->getType($dateType), $this->getType($timeType), $carbon->tz);
     return $fmt->format($carbon->getTimestamp());
 }
 protected function formatDate(Carbon $date)
 {
     return ['rfc3339' => $date->toRfc3339String(), 'timestamp' => $date->getTimestamp(), 'diffForHumans' => $date->diffForHumans()];
 }
 public function postPause($stream)
 {
     $time = Input::get('time');
     $date = new Carbon($time);
     $series = AnnouncementSeries::find($stream);
     $series->paused_until = $date;
     $series->save();
     $this->broadcast(array('stream' => $series, 'type' => 'pause', 'date' => $date->getTimestamp()));
 }
 /**
  * Set the timestamp.
  *
  * @param  Carbon  $timestamp
  * @return $this
  */
 public function timestamp(Carbon $timestamp)
 {
     $this->timestamp = $timestamp->getTimestamp();
     return $this;
 }
Example #14
0
 /**
  * {@inheritDoc}
  */
 public function getReadableSort()
 {
     return $this->date->getTimestamp();
 }
Example #15
0
 /**
  * Sets up pager to switch prev/next day
  */
 protected function setupDayPager()
 {
     $first_date = $this->first_date;
     $current_date = $this->current_date;
     // previous
     if ($first_date->getTimestamp() < $current_date->getTimestamp()) {
         $previous_date = $current_date->copy();
         $previous_date->subDay(1);
         $this->previous_text = $previous_date->formatLocalized('%d') . ' ' . $previous_date->formatLocalized('%B') . ', ' . $previous_date->year;
         $this->previous_url = $this->makePagerUrl(array('year' => $previous_date->year, 'month' => $previous_date->month, 'day' => $previous_date->day));
     } else {
         $this->previous_text = $current_date->formatLocalized('%d') . ' ' . $current_date->formatLocalized('%B') . ', ' . $current_date->year;
         $this->previous_url = '';
     }
     // next
     $today = new Carbon();
     $today->setTime(0, 0);
     if ($this->current_date->getTimestamp() < $today->getTimestamp()) {
         $next_date = $current_date->copy();
         $next_date->addDay(1);
         $this->next_text = $next_date->formatLocalized('%d') . ' ' . $next_date->formatLocalized('%B') . ', ' . $next_date->year;
         $this->next_url = $this->makePagerUrl(array('year' => $next_date->year, 'month' => $next_date->month, 'day' => $next_date->day));
     } else {
         $this->next_text = $current_date->formatLocalized('%d') . ' ' . $current_date->formatLocalized('%B') . ', ' . $current_date->year;
         $this->next_url = '';
     }
 }
Example #16
0
 /**
  * Trigger a visitor action
  *
  * @param        $companyFid
  * @param        $actionKey
  * @param        $transactionId
  * @param Carbon $time,
  * @param int    $transactionValue
  * @param array  $data
  * @param null   $couponCode
  * @param bool   $returnPixels
  * @param string $userReference
  * @param string $campaignHash
  * @param string $sid1
  * @param string $sid2
  * @param string $sid3
  *
  * @return PostActionPayload
  */
 public function preparePayload($companyFid, $actionKey, $transactionId, Carbon $time, $transactionValue = 0, array $data = null, $couponCode = null, $returnPixels = true, $userReference = null, $campaignHash = null, $sid1 = null, $sid2 = null, $sid3 = null)
 {
     $payload = new PostActionPayload();
     $payload->userAgent = $this->_fortifi->getUserAgent();
     $payload->language = $this->_fortifi->getUserLanguage();
     $payload->clientIp = $this->_fortifi->getClientIp();
     $payload->encoding = $this->_fortifi->getUserEncoding();
     $payload->companyFid = $companyFid;
     $payload->actionKey = $actionKey;
     $payload->transactionId = $transactionId;
     $payload->timestamp = $time->getTimestamp();
     $payload->transactionValue = $transactionValue;
     $payload->coupon = $couponCode;
     $payload->data = $data;
     $payload->returnPixels = $returnPixels;
     $payload->visitorId = $this->_visitorId;
     $payload->userReference = ValueAs::nonempty($userReference, $this->_alias);
     $payload->campaignHash = $campaignHash;
     $payload->sid1 = $sid1;
     $payload->sid2 = $sid2;
     $payload->sid3 = $sid3;
     return $payload;
 }
Example #17
0
 /**
  * Serialize SharePoint Access Token
  *
  * @return  string
  */
 public function serialize()
 {
     return serialize([$this->value, $this->expiration->getTimestamp(), $this->expiration->getTimezone()->getName()]);
 }
 /**
  * @return int|null
  */
 public function getDeletedAtTimestamp()
 {
     return $this->deletedAt instanceof Carbon ? $this->deletedAt->getTimestamp() : null;
 }
 /**
  * Returns plain PHP functions.
  *
  * @return array
  */
 private function getPhpFunctions()
 {
     return ['strftime' => function ($time, $format = '%d.%m.%Y %H:%M:%S') {
         $timeObj = new Carbon($time);
         return strftime($format, $timeObj->getTimestamp());
     }, 'uppercase' => function ($string) {
         return mb_convert_case($string, MB_CASE_UPPER, "UTF-8");
     }, 'lowercase' => function ($string) {
         return mb_convert_case($string, MB_CASE_LOWER, "UTF-8");
     }, 'ucfirst' => function ($string) {
         return mb_convert_case($string, MB_CASE_TITLE, "UTF-8");
     }, 'lcfirst' => function ($string) {
         return lcfirst($string);
     }, 'ltrim' => function ($string, $charlist = " \t\n\r\v") {
         return ltrim($string, $charlist);
     }, 'rtrim' => function ($string, $charlist = " \t\n\r\v") {
         return rtrim($string, $charlist);
     }, 'str_repeat' => function ($string, $multiplier = 1) {
         return str_repeat($string, $multiplier);
     }, 'plural' => function ($string, $count = 2) {
         return str_plural($string, $count);
     }, 'strpad' => function ($string, $pad_length, $pad_string = ' ') {
         return str_pad($string, $pad_length, $pad_string, $pad_type = STR_PAD_BOTH);
     }, 'leftpad' => function ($string, $pad_length, $pad_string = ' ') {
         return str_pad($string, $pad_length, $pad_string, $pad_type = STR_PAD_LEFT);
     }, 'rightpad' => function ($string, $pad_length, $pad_string = ' ') {
         return str_pad($string, $pad_length, $pad_string, $pad_type = STR_PAD_RIGHT);
     }, 'rtl' => function ($string) {
         return strrev($string);
     }, 'var_dump' => function ($expression) {
         ob_start();
         var_dump($expression);
         $result = ob_get_clean();
         return $result;
     }];
 }
Example #20
0
 /**
  * Get the difference in seconds
  *
  * @param Carbon  $dt
  * @param boolean $abs Get the absolute of the difference
  *
  * @return integer
  */
 public function diffInSeconds(Carbon $dt = null, $abs = true)
 {
     $value = ($dt === null ? time() : $dt->getTimestamp()) - $this->getTimestamp();
     return $abs ? abs($value) : $value;
 }
 /**
  *
  * Evaluates url to be for this row (/news/y/m/d/slug)
  * and replaces /node/id with it in disqus text
  *
  * @param array $row the row to be processed
  */
 protected function processDisqusRow($row)
 {
     $created = new Carbon($row[$this->created_index]);
     $url = '/news';
     $url .= '/' . date('Y', $created->getTimestamp());
     $url .= '/' . date('m', $created->getTimestamp());
     $url .= '/' . date('d', $created->getTimestamp());
     $url .= '/' . $row[$this->link_index];
     $url = '<link>' . $url . '</link>';
     $old_url = '<link>http://graker.ru/node/' . $row[$this->id_index] . '</link>';
     $this->discus_text = str_replace($old_url, $url, $this->discus_text);
 }