Last active
March 26, 2020 19:34
-
-
Save paulcervov/db251a98e823a6a8369c7143cb13bee7 to your computer and use it in GitHub Desktop.
Example function to get the correct string of the current time (Cyrillic)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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