import 'package:intl/intl.dart';

String formatDateTime(DateTime? date) {
  if (date == null) return '-';
  return DateFormat('yyyy-MM-dd HH:mm:ss').format(date.toLocal());
}

String formatDate(DateTime? date) {
  if (date == null) return '-';
  return DateFormat('yyyy-MM-dd').format(date.toLocal());
}

String formatTime(DateTime? date) {
  if (date == null) return '-';
  return DateFormat('HH:mm:ss').format(date.toLocal());
}

String formatRelative(DateTime? date) {
  if (date == null) return '-';
  final now = DateTime.now();
  final diff = now.difference(date);

  if (diff.inDays > 0) {
    return '${diff.inDays}天前';
  } else if (diff.inHours > 0) {
    return '${diff.inHours}小时前';
  } else if (diff.inMinutes > 0) {
    return '${diff.inMinutes}分钟前';
  } else {
    return '刚刚';
  }
}
