48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Smarty plugin.
|
|
*/
|
|
|
|
/**
|
|
* Smarty {translate} function plugin.
|
|
*
|
|
* @param $date DateTime
|
|
* @param null $format
|
|
* @param string $default_date
|
|
* @param string $formatter
|
|
*
|
|
* @return string
|
|
*/
|
|
function smarty_modifier_format_date_pretty($date, $format = null, $default_date = '', $formatter = 'auto')
|
|
{
|
|
if ($format === null) {
|
|
$format = 'd. m. Y';
|
|
}
|
|
|
|
if (!($date instanceof DateTime)) {
|
|
$date = new DateTime($date);
|
|
}
|
|
|
|
$today = new DateTime('midnight');
|
|
$tomorrow = new DateTime('+1 day midnight');
|
|
$dayAfterTomorrow = new DateTime('+2 day midnight');
|
|
|
|
if ($date > $today && $date < $tomorrow) {
|
|
return 'dnes';
|
|
}
|
|
|
|
if ($date > $tomorrow && $date < $dayAfterTomorrow) {
|
|
return 'zítra';
|
|
}
|
|
|
|
$format_date = $date->format($format);
|
|
|
|
$en_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
$cz_days = ['Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota', 'Neděle', 'leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'];
|
|
|
|
$format_date = str_replace($en_days, $cz_days, $format_date);
|
|
|
|
return $format_date;
|
|
}
|