import 'package:flutter/material.dart';

extension TimeExtensions on DateTime {
  DateTime forwardTo(TimeOfDay timeOfDay) {
    final now = DateTime.now();
    final today = DateTime(now.year, now.month, now.day);
    DateTime result;

    final targetTime = DateTime(now.year, now.month, now.day, timeOfDay.hour, timeOfDay.minute);
    if (targetTime.isBefore(now) || targetTime.isAtSameMomentAs(now)) {
      result = today.add(Duration(days: 1));
    } else {
      result = today;
    }

    return result.add(Duration(hours: timeOfDay.hour, minutes: timeOfDay.minute));
  }

  bool isBetweenTimeOfDay(TimeOfDay start, TimeOfDay end) {
    final now = this;
    final today = DateTime(now.year, now.month, now.day);

    final startTime = today.add(Duration(hours: start.hour, minutes: start.minute));
    final endTime = today.add(Duration(hours: end.hour, minutes: end.minute));

    return now.isAfter(startTime) && now.isBefore(endTime);
  }
}