setTimezone(self::timezone()); } catch (Throwable) { return null; } } public static function formatDateTime(mixed $value): string { return self::parse($value)?->format('Y-m-d H:i') ?? '-'; } public static function formatWaiting(mixed $value, ?CarbonInterface $now = null): string { $startedAt = self::parse($value); if ($startedAt === null) { return '-'; } $nowAt = $now === null ? self::now() : CarbonImmutable::instance($now)->setTimezone(self::timezone()); if ($startedAt->greaterThan($nowAt)) { return '-'; } $hours = intdiv($startedAt->diffInSeconds($nowAt), 3600); $steps = intdiv($hours, self::WAIT_STEP_HOURS); if ($steps < 1) { return '不足12小时'; } $days = intdiv($steps, 2); $halfDays = $steps % 2; $parts = []; if ($days > 0) { $parts[] = $days . '天'; } if ($halfDays > 0) { $parts[] = self::WAIT_STEP_HOURS . '小时'; } return implode('', $parts); } }