static function FormatDatetimeBeauty($in, $arParams = array(),
$formatDatetimePHP = false
)
{
if ($formatDatetimePHP === false)
{
$formatDatetimePHP = CDatabase::DateFormatToPHP(FORMAT_DATETIME);
}
if (
defined(LANGUAGE_ID)
&& (strcasecmp(LANGUAGE_ID, 'EN') !== 0)
&& (strcasecmp(LANGUAGE_ID, 'DE') !== 0)
)
{
return (FormatDate($formatDatetimePHP, MakeTimeStamp($in)));
}
$bStripCurrentYear = true;
$bSexySmallMonthNames = true;
if (isset($arParams['stripCurrentYear']))
$bStripCurrentYear = (bool) $arParams['stripCurrentYear'];
if (isset($arParams['sexySmallMonthNames']))
$bSexySmallMonthNames = (bool) $arParams['sexySmallMonthNames'];
if ($bSexySmallMonthNames)
{
// Replace month number (or long name) to short name
$formatDatetimePHP = str_replace(array('F', 'm', 'n'), 'M', $formatDatetimePHP);
// Replace, for example, "05.Dec" to "05 Dec"
$formatDatetimePHP = str_replace(array('d.M', 'j.M'), array('d M', 'j M'), $formatDatetimePHP);
}
if (
(mb_strpos($formatDatetimePHP, 'A') !== false)
|| (mb_strpos($formatDatetimePHP, 'a') !== false)
)
{
$formatTimePHP = CDatabase::DateFormatToPHP('H:MI T');
}
else
{
$formatTimePHP = CDatabase::DateFormatToPHP('HH:MI');
}
$bTimeStripped = false;
$formatPHP = $formatDatetimePHP;
// Strip time, if it's zeroed
if (
(FormatDate(CDatabase::DateFormatToPHP('HH:MI'), MakeTimeStamp($in)) === '00:00')
|| (FormatDate(CDatabase::DateFormatToPHP('HH:MI'), MakeTimeStamp($in)) === '0:00')
)
{
$bTimeStripped = true;
$formatPHP = str_replace(
array(
' a', ' A', 'a', 'A',
' g', ' G', 'g', 'G',
' h', ' H', 'h', 'H',
':i', ':s', 'i', 's'
),
'',
$formatPHP
);
}
// For current date strip date
if ( ! $bTimeStripped )
{
$curDate = FormatDate(CDatabase::DateFormatToPHP('Y-m-d'), MakeTimeStamp(time()));
$givenDate = FormatDate(CDatabase::DateFormatToPHP('Y-m-d'), MakeTimeStamp($in));
if ($curDate === $givenDate)
$formatPHP = $formatTimePHP;
}
$formatPHPWoSeconds = str_replace(
array(':SS', ':ss', ':S', ':s', 's', 'S'),
'',
$formatPHP
);
$dateTimeFormated = FormatDate($formatPHPWoSeconds, MakeTimeStamp($in));
if (defined(LANGUAGE_ID)
&& (strcasecmp(LANGUAGE_ID, 'EN') !== 0)
&& (strcasecmp(LANGUAGE_ID, 'DE') !== 0)
)
{
$dateTimeFormated = ToLower($dateTimeFormated);
}
// strip current year
if ($bStripCurrentYear)
{
$dateTimeFormated = ltrim($dateTimeFormated, '0');
$curYear = date('Y');
$dateTimeFormated = str_replace(
array(
'-' . $curYear,
'/' . $curYear,
' ' . $curYear,
'.' . $curYear,
$curYear . '-',
$curYear . '/',
$curYear . ' ',
$curYear . '.'
),
'',
$dateTimeFormated
);
}
return ($dateTimeFormated);
}