| 12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- use Illuminate\Support\Carbon;
- if(!function_exists('humanDate')) {
- function humanDate($date, $withTime = false): string
- {
- if(!$date) return '-';
- $today = date('Y-m-d');
- $tomorrow = date('Y-m-d', strtotime('tomorrow'));
- $ret = '';
- switch ($date) {
- case $today:
- $ret .= 'Сегодня';
- break;
- case $tomorrow:
- $ret .= 'Завтра';
- break;
- default:
- $ret .= Carbon::parse($date)->isoFormat('D MMMM');
- }
- $year = date('Y', strtotime($date));
- if(date('Y') != $year){
- $ret .= ' ' . $year;
- }
- if($withTime) {
- $ret .= date(' H:i', strtotime($date));
- }
- return $ret;
- }
- }
|