fluffychat/lib/pangea/utils/p_extension.dart
2023-11-08 12:27:18 -05:00

12 lines
386 B
Dart

extension IsAtLeastYearsOld on DateTime {
bool isAtLeastYearsOld(int years) {
final now = DateTime.now();
final boundaryDate = DateTime(now.year - years, now.month, now.day);
// Discard the time from [this].
final thisDate = DateTime(year, month, day);
// Did [thisDate] occur on or before [boundaryDate]?
return thisDate.compareTo(boundaryDate) <= 0;
}
}