本文整理汇总了PHP中Carbon\Carbon::formatLocalized方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::formatLocalized方法的具体用法?PHP Carbon::formatLocalized怎么用?PHP Carbon::formatLocalized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::formatLocalized方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFilters
/**
* 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);
}
})];
}
示例2: month
/**
* @param string $year
* @param string $month
*
* @param bool $shared
*
* @return \Illuminate\View\View
*/
public function month($year = '2014', $month = '1', $shared = false)
{
$start = new Carbon($year . '-' . $month . '-01');
$subTitle = trans('firefly.reportForMonth', ['month' => $start->formatLocalized($this->monthFormat)]);
$subTitleIcon = 'fa-calendar';
$end = clone $start;
$incomeTopLength = 8;
$expenseTopLength = 8;
if ($shared == 'shared') {
$shared = true;
$subTitle = trans('firefly.reportForMonthShared', ['month' => $start->formatLocalized($this->monthFormat)]);
}
$end->endOfMonth();
$accounts = $this->helper->getAccountReport($start, $end, $shared);
$incomes = $this->helper->getIncomeReport($start, $end, $shared);
$expenses = $this->helper->getExpenseReport($start, $end, $shared);
$budgets = $this->helper->getBudgetReport($start, $end, $shared);
$categories = $this->helper->getCategoryReport($start, $end, $shared);
$balance = $this->helper->getBalanceReport($start, $end, $shared);
$bills = $this->helper->getBillReport($start, $end);
Session::flash('gaEventCategory', 'report');
Session::flash('gaEventAction', 'month');
Session::flash('gaEventLabel', $start->format('F Y'));
return view('reports.month', compact('start', 'shared', 'subTitle', 'subTitleIcon', 'accounts', 'incomes', 'incomeTopLength', 'expenses', 'expenseTopLength', 'budgets', 'balance', 'categories', 'bills'));
}
示例3: formatLocalized
public function formatLocalized($format = self::COOKIE)
{
if (strpos($format, '%f') !== false) {
$langKey = strtolower(parent::format("F"));
$replace = \Lang::get("localized-carbon::months." . $langKey);
$result = str_replace('%f', $replace, $format);
} else {
$result = $format;
}
$result = parent::formatLocalized($result);
return $result;
}
示例4: history
/**
* @param Collection $set
*
* @return array
*/
public function history(Collection $set) : array
{
// language:
$format = (string) trans('config.month_and_day');
$data = ['count' => 1, 'labels' => [], 'datasets' => [['label' => 'Diff', 'data' => []]]];
$sum = '0';
foreach ($set as $key => $value) {
$date = new Carbon($key);
$sum = bcadd($sum, $value);
$data['labels'][] = $date->formatLocalized($format);
$data['datasets'][0]['data'][] = round($sum, 2);
}
return $data;
}
示例5: history
/**
* @param Collection $set
*
* @return array
*/
public function history(Collection $set)
{
// language:
$format = trans('config.month_and_day');
$data = ['count' => 1, 'labels' => [], 'datasets' => [['label' => 'Diff', 'data' => []]]];
$sum = '0';
bcscale(2);
foreach ($set as $entry) {
$date = new Carbon($entry->date);
$sum = bcadd($sum, $entry->sum);
$data['labels'][] = $date->formatLocalized($format);
$data['datasets'][0]['data'][] = round($sum, 2);
}
return $data;
}
示例6: history
/**
* @param Collection $set
*
* @return array
*/
public function history(Collection $set)
{
// language:
$language = Preferences::get('language', 'en')->data;
$format = Config::get('firefly.month.' . $language);
$data = ['count' => 1, 'labels' => [], 'datasets' => [['label' => 'Diff', 'data' => []]]];
$sum = '0';
bcscale(2);
foreach ($set as $entry) {
$date = new Carbon($entry->date);
$sum = bcadd($sum, $entry->sum);
$data['labels'][] = $date->formatLocalized($format);
$data['datasets'][0]['data'][] = round($sum, 2);
}
return $data;
}
示例7: report
/**
* @param string $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return View
* @throws FireflyException
*/
public function report(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
$this->createRepositories();
// throw an error if necessary.
if ($end < $start) {
throw new FireflyException('End date cannot be before start date, silly!');
}
// lower threshold
if ($start < session('first')) {
$start = session('first');
}
View::share('subTitle', trans('firefly.report_' . $reportType, ['start' => $start->formatLocalized($this->monthFormat), 'end' => $end->formatLocalized($this->monthFormat)]));
View::share('subTitleIcon', 'fa-calendar');
switch ($reportType) {
default:
throw new FireflyException('Unfortunately, reports of the type "' . e($reportType) . '" are not yet available. ');
case 'default':
// more than one year date difference means year report.
if ($start->diffInMonths($end) > 12) {
return $this->defaultMultiYear($reportType, $start, $end, $accounts);
}
// more than two months date difference means year report.
if ($start->diffInMonths($end) > 1) {
return $this->defaultYear($reportType, $start, $end, $accounts);
}
// otherwise default
return $this->defaultMonth($reportType, $start, $end, $accounts);
case 'audit':
// always default
return $this->auditReport($start, $end, $accounts);
}
}
示例8: timestamp
public function timestamp(Carbon $date, $format = '%x %X')
{
return $date->formatLocalized($format);
}
示例9: report
/**
* @param $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return View
*/
public function report($reportType, Carbon $start, Carbon $end, Collection $accounts)
{
// throw an error if necessary.
if ($end < $start) {
return view('error')->with('message', 'End date cannot be before start date, silly!');
}
// lower threshold
if ($start < Session::get('first')) {
$start = Session::get('first');
}
switch ($reportType) {
default:
case 'default':
View::share('subTitle', trans('firefly.report_default', ['start' => $start->formatLocalized($this->monthFormat), 'end' => $end->formatLocalized($this->monthFormat)]));
View::share('subTitleIcon', 'fa-calendar');
// more than one year date difference means year report.
if ($start->diffInMonths($end) > 12) {
return $this->defaultMultiYear($reportType, $start, $end, $accounts);
}
// more than two months date difference means year report.
if ($start->diffInMonths($end) > 1) {
return $this->defaultYear($reportType, $start, $end, $accounts);
}
return $this->defaultMonth($reportType, $start, $end, $accounts);
}
}
示例10: createYearHeaders
/**
* @param Carbon $current
* @param Carbon $end
*
* @return array
*/
private function createYearHeaders(Carbon $current, Carbon $end) : array
{
$headers = [];
while ($current < $end) {
$short = $current->format('m-Y');
$headers[$short] = $current->formatLocalized((string) trans('config.month'));
$current->addMonth();
}
return $headers;
}
示例11: periodShow
/**
* @param \Carbon\Carbon $date
* @param $repeatFrequency
*
* @return string
* @throws FireflyException
*/
public function periodShow(Carbon $date, $repeatFrequency)
{
$formatMap = ['daily' => '%e %B %Y', 'week' => 'Week %W, %Y', 'weekly' => 'Week %W, %Y', 'quarter' => '%B %Y', 'month' => '%B %Y', 'monthly' => '%B %Y', 'year' => '%Y', 'yearly' => '%Y'];
if (isset($formatMap[$repeatFrequency])) {
return $date->formatLocalized($formatMap[$repeatFrequency]);
}
throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!');
}
示例12: periodShow
/**
* @param \Carbon\Carbon $date
* @param $repeatFrequency
*
* @return string
* @throws FireflyException
*/
public function periodShow(Carbon $date, string $repeatFrequency) : string
{
$formatMap = ['1D' => trans('config.specific_day'), 'daily' => trans('config.specific_day'), 'custom' => trans('config.specific_day'), '1W' => trans('config.week_in_year'), 'week' => trans('config.week_in_year'), 'weekly' => trans('config.week_in_year'), '3M' => trans('config.quarter_of_year'), 'quarter' => trans('config.quarter_of_year'), '1M' => trans('config.month'), 'month' => trans('config.month'), 'monthly' => trans('config.month'), '1Y' => trans('config.year'), 'year' => trans('config.year'), 'yearly' => trans('config.year'), '6M' => trans('config.half_year')];
if (isset($formatMap[$repeatFrequency])) {
return $date->formatLocalized(strval($formatMap[$repeatFrequency]));
}
throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!');
}
示例13: getMonthName
/**
*
* Returns localized month name
*
* @param string $date
* @return string
*/
protected function getMonthName($date = '')
{
$d = new Carbon($date);
return $d->formatLocalized('%B');
}
示例14: getPostedOnAttribute
public function getPostedOnAttribute($date)
{
$new_date = new Carbon($date);
return $new_date->formatLocalized('%A %d, %B %Y at %H:%M:%S');
}