h4kuna / date-filter
Add option define own filters based on date for latte.
Installs: 3 032
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: >= 7.1
- symfony/polyfill-php73: ^1.10
Requires (Dev)
- latte/latte: ~2.0
- nette/application: ~3.0
- nette/bootstrap: ~3.0
- nette/tester: ^2.1
- phpstan/phpstan: ^0.11
- tracy/tracy: ^2.6
Suggests
- latte/latte: If you want to use Nette extension in templates.
- nette/application: If you want to use Nette extension in templates.
- nette/bootstrap: If you want to use Nette extension in templates.
This package is auto-updated.
Last update: 2024-12-08 13:26:09 UTC
README
Náhrada
Koukněte na knihovnu Format konkrétně na formátování datumů. Doplněk by vás měl odstínit od manuálního vypisování a skládání objektů, na to momentálně nemám kapacitu, tak vám ukážu jak to dělat ručně ve třech krocích.
- nainstalovat knihovnu
composer require h4kuna/number-format
- sepsat si vlastní sadu formátů v neonu
services: format.date: factory: h4kuna\Format\Date\Formatters\DateTimeFormatter('j. n. Y') autowired: false format.time: factory: h4kuna\Format\Date\Formatters\DateTimeFormatter('H:i:s') autowired: false # budete-li potřebovat formátovat kdekoliv v projektu, použijte tento Accessor number.formats: h4kuna\Format\Date\FormatsAccessor( date: @format.date time: @format.time ) latte.latteFactory: setup: - addFilter('date', @format.date) - addFilter('time', @format.time)
- v šabloně pak bude fungovat
{=(new DateTime())|date}<br> {=(new DateTime())|time}
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()');