import 'package:timezone/timezone.dart' as tz;
import 'package:intl/intl.dart' as intl;

class DateUtility {
  static final intl.DateFormat _hmFormat = intl.DateFormat('Hm');
  static final intl.DateFormat _ymdhmFormat =
      intl.DateFormat('yyyy-MM-dd HH:mm');
  static final intl.DateFormat _ymdFormat = intl.DateFormat('yyyy-MM-dd');

  // private default contructor so class can't be instanciated
  DateUtility._();

  static DateTime get currentUKTimeUtc {
    final london = tz.getLocation('Europe/London');
    return tz.TZDateTime.now(london).toUtc();
  }

  /// Formats a date in minutesSinceEpoch to a formatted String of HH:mm
  static String formatMinutesToHm(double value) {
    return _hmFormat.format(
        DateTime.fromMillisecondsSinceEpoch((value * 1000 * 60).toInt()));
  }

  static String formatDateToHm(DateTime date) {
    return _hmFormat.format(date);
  }

  /// Formats a date to yyyy-MM-dd HH:mm
  static String formatDateToYmdhm(DateTime date) {
    return _ymdhmFormat.format(date);
  }

  /// Formats a date to yyyy-MM-dd
  static String formatDateToYmd(DateTime date) {
    return _ymdFormat.format(date);
  }
}
