Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2.  
  3. function getTimeString1()
  4. {
  5. $keys = [2, 1, 0, 0, 0, 2];
  6. $timeSigns = ['H','i','s'];
  7. $hoursSufx = [" часa ", " час ", " часов "];
  8. $minutesSufx =[" минуты ", " минутa ", " минут "];
  9. $secondsSufx = [" секунды ", " секунда ", " секунд "];
  10.  
  11.  
  12. $timeHours = (int)date($timeSigns[0]);
  13. $mod = $timeHours % 10;
  14. $suffIndx= ($timeHours > 10 && $timeHours < 19) ? 0 : $suffIndx = min($mod, 5);
  15. $hoursStr = $hoursSufx[$keys[$suffIndx]];
  16.  
  17. $timeMinutes= (int)date($timeSigns[1]);
  18. $mod = $timeMinutes % 10;
  19. $suffIndx= ($timeMinutes > 10 && $timeMinutes < 19) ? 0 : $suffIndx = min($mod, 5);
  20. $minsStr = $minutesSufx[$keys[$suffIndx]];
  21.  
  22. $timeSeconds = (int)date($timeSigns[2]);
  23. $mod = $timeSeconds % 10;
  24. $suffIndx= ($timeSeconds > 10 && $timeSeconds < 19) ? 0 : $suffIndx = min($mod, 5);
  25. $secStr = $secondsSufx[$keys[$suffIndx]];
  26.  
  27. return "{$timeHours} {$hoursStr} {$timeMinutes} {$minsStr} {$timeSeconds} {$secStr}";
  28. }
  29.  
  30.  
  31. function getTimeString2()
  32. {
  33. $keys = [2, 1, 0, 0, 0, 2];
  34. $timeSigns = ['H', 'i', 's'];
  35.  
  36. $sufxArrs = [
  37. [" часa ", " час ", " часов "],
  38. [" минуты ", " минутa ", " минут "],
  39. [" секунды ", " секунда ", " секунд "]
  40. ];
  41. $resString = '';
  42.  
  43. for ($i = 0; $i < 3; $i++) {
  44. $timeItem = (int)date($timeSigns[$i]);
  45. $mod = $timeItem % 10;
  46. $suffIndx = ($timeItem > 10 && $timeItem < 19) ? 0 : $suffIndx = min($mod, 5);
  47. $itemStr = $sufxArrs[$i][$keys[$suffIndx]];
  48. $resString .= "{$timeItem} {$itemStr}";
  49. }
  50. return $resString;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement