Statistics
20
2
0
77d
Badges
Tags
latte

Date filter

Build Status Downloads this Month Latest stable

Require PHP 5.4+.

This extension is for php Nette framework.

Installation to project

The best way to install h4kuna/date-filter is using composer:

$ composer require h4kuna/date-filter

How to use

Register extension for Nette in neon config file.

extensions:
    dateFilterExtension: h4kuna\DateFilter\DI\DateFilterExtension

Now show you how set new date filters and other variants.

You can overwrite default latte filter date!

For define format use letters from table date function.

You can set own filters groups like:

dateFilterExtension:
	formats:
		cze: # name of group is optional (i choose country)
			# filter name: format
			day: D
			date: j. n. Y # overwrite default latte filter
			dateTime: j. n. Y H:i:s
		uk:
			day: D
			date: d/m/Y
			dateTime: d/m/Y H:i:s

First group is default. Now in latte you can use:

{$date|dateTime}
{$date|day}
{$date|date}

You can forget on this and duplicate on every place where you need.

{$date|date:'j. n. Y H:i:s'}

For different country you can change date format. And change it by:

/* @var $dateTimeFormat h4kuna\DateFilter\DateTimeFormat */
$dateTimeFormat = $container->getService('dateFilterExtension.dateTimeFormat');
$dateTimeFormat->setFormatsGroup('uk');
$dateTimeFormat->format('dateTime', 'now'); // internaly call filter from latte

If you don't change locale, then date letters (D, l (lower L), F, M) are everytime in english language, ok here is example how change it.

	dayMonth:
		cs: # name of group is optional (i choose language) it isn't same group above
			# days:
			l: # lower L long
				# original name: translate
				Monday: Pondělí
				Tuesday: Úterý
				Wednesday: Středa
				Thursday: Čtvrtek
				Friday: Pátek
				Saturday: Sobota
				Sunday: Neděle

			D: # short
				Mon: Po
				Tue: Út
				Wed: St
				Thu: Čt
				Fri: Pá
				Sat: So
				Sun: Ne

			# months:
			F: # long
				January: Leden
				February: Únor
				March: Březen
				April: Duben
				May: Květen
				June: Červen
				July: Červenec
				August: Srpen
				September: Září
				October: Říjen
				November: Listopad
				December: Prosinec

			M: # short
				Jan: Led
				Feb: Úno
				Mar: Bře
				Apr: Dub
				May: Kvě
				Jun: Čvn
				Jul: Čvc
				Aug: Srp
				Sep: Zář
				Oct: Říj
				Nov: Lis
				Dec: Pro
		en: [] # we don't need translate

First group is default. Change group like:

/* @var $dateTimeFormat h4kuna\DateFilter\DateTimeFormat */
$dateTimeFormat = $container->getService('dateFilterExtension.dateTimeFormat');
$dateTimeFormat->setDayMonthGroup('en');
$dateTimeFormat->format('day', 'now()');

No release at this moment. Try to create first one.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com