dateHelper.php 824 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. use Illuminate\Support\Carbon;
  3. if(!function_exists('humanDate')) {
  4. function humanDate($date, $withTime = false): string
  5. {
  6. if(!$date) return '-';
  7. $today = date('Y-m-d');
  8. $tomorrow = date('Y-m-d', strtotime('tomorrow'));
  9. $ret = '';
  10. switch ($date) {
  11. case $today:
  12. $ret .= 'Сегодня';
  13. break;
  14. case $tomorrow:
  15. $ret .= 'Завтра';
  16. break;
  17. default:
  18. $ret .= Carbon::parse($date)->isoFormat('D MMMM');
  19. }
  20. $year = date('Y', strtotime($date));
  21. if(date('Y') != $year){
  22. $ret .= ' ' . $year;
  23. }
  24. if($withTime) {
  25. $ret .= date(' H:i', strtotime($date));
  26. }
  27. return $ret;
  28. }
  29. }