import 'package:intl/intl.dart';
import 'package:persian_datetime_picker/persian_datetime_picker.dart';

extension XDateTime on String {
  get toDateTime => DateTime.parse(this);

  String get formattedJalaliDate {
    String tmp = contains("/") ? replaceAll("/", "-") : this;
    final dateTime = DateTime.parse(tmp);
    final jalaliDate = Jalali.fromDateTime(dateTime);
    return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";

  }

  String get formattedJalaliDateYHMS {
    final dateTime = DateTime.parse(this);
    final jalaliDate = Jalali.fromDateTime(dateTime);
    return "${jalaliDate.hour.toString().padLeft(2, '0')}:${jalaliDate.minute.toString().padLeft(2, '0')} - ${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
  }

  String get formattedYHMS {
    return DateFormat('yyyy-MM-dd HH:mm:ss').format(toDateTime);
  }
}

extension XDateTime2 on DateTime {
  get formattedJalaliDate {
    final jalaliDate = Jalali.fromDateTime(this);
    return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
  }

  get formattedYHMS {
    return DateFormat('yyyy-MM-dd HH:mm:ss').format(this);
  }
}
