2 Commits

Author SHA1 Message Date
mdesouza b1435d39dc Add twig filter for brazilian date formatting. 2026-04-20 09:04:30 -04:00
mdesouza 16270fedf8 Merge pull request 'Release-v1.0.7' (#8) from release-v1.0.7 into master
Reviewed-on: #8
2025-10-07 14:48:42 -04:00
2 changed files with 18 additions and 0 deletions
+17
View File
@@ -50,6 +50,7 @@ class MDTwigExtension extends AbstractExtension {
new TwigFilter('cnpj', [$this, 'formatCNPJ']),
new TwigFilter('real', [$this, 'formatReal']),
new TwigFilter('unicode', [$this, 'returnUnicode']),
new TwigFilter('dateshort', [$this, 'formatDateShort']),
];
}
@@ -183,4 +184,20 @@ class MDTwigExtension extends AbstractExtension {
return $unicode;
}
/**
* Format and translate date to portuguese.
* 2026-04-01 => 01 Apr. 2026
*/
public function formatDateShort(string $value) : string {
$df = new \IntlDateFormatter(
'pt_BR',
\IntlDateFormatter::FULL,
\IntlDateFormatter::NONE
);
$df->setPattern('d-LLL-yy');
$d = $df->format(new \DateTime($value));
return strtoupper(str_replace(".", "", $d));
}
}
+1
View File
@@ -81,6 +81,7 @@ class TwigRender {
try {
$this->twig->addExtension(new DebugExtension());
$this->twig->addExtension(new MFDESTwigExtension());
$this->twig->addExtension(new MDTwigExtension());
$this->addPaths();
$html = $this->twig->render($this->template, ['data' => $this->data]);
}