Client/lib/extensions/dateTime.dart

21 lines
709 B
Dart

import 'package:flutter/material.dart';
extension IsSameDay on DateTime {
bool isSameDay(DateTime other) => year == other.year && month == other.month && day == other.day;
DateTime nextWeekday(int day) => add(Duration(days: (day - weekday) % DateTime.daysPerWeek));
DateTime withTime(TimeOfDay time) => copyWith(hour: time.hour, minute: time.minute);
TimeOfDay toTimeOfDay() => TimeOfDay(hour: hour, minute: minute);
bool isSameDateTime(DateTime other) {
var isSameDay = this.isSameDay(other);
var isSameTimeOfDay = (toTimeOfDay() == other.toTimeOfDay());
return isSameDay && isSameTimeOfDay;
}
bool isSameOrAfter(DateTime other) => isSameDateTime(other) || isAfter(other);
}