Skip to content

Instantly share code, notes, and snippets.

@paulcervov
Last active March 26, 2020 19:34
Show Gist options
  • Save paulcervov/db251a98e823a6a8369c7143cb13bee7 to your computer and use it in GitHub Desktop.
Save paulcervov/db251a98e823a6a8369c7143cb13bee7 to your computer and use it in GitHub Desktop.
Example function to get the correct string of the current time (Cyrillic)
<?php
/**
* Get correct time string
* E.g.: "01 час 01 минута", "02 час 02 минуты", "02 часа 05 минут".
*
* @return string
*/
function getCurrentTimeString() {
$ts = time();
$hours = date('H', $ts);
$minutes = date('i', $ts);
$singular = ['02', '03', '04', '22', '23', '24', '32', '33', '34', '42', '43', '44', '52', '53', '54'];
$plural = ['05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'];
$hoursName = in_array($hours, $singular) ? 'часа' : (in_array($hours, $plural) ? 'часов' : 'час');
$minutesName = in_array($minutes, $singular) ? 'минуты' : (in_array($minutes, $plural) ? 'минут' : 'минута');
return "{$hours} {$hoursName} {$minutes} {$minutesName}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment