isSameDateOrBefore method
Returns true if this date is the same as or before other
date.
This method compares the year, month, and day of the current DateTime with another DateTime object.
Implementation
bool isSameDateOrBefore(DateTime other) {
// Check if the year of this date is less than the year of the other date
if (year < other.year) {
return true;
}
// If the years are equal, check if the month of this date is less than
// the month of the other date
if (year == other.year && month < other.month) {
return true;
}
// If the years and months are equal, check if the day of this date is
// less than or equal to the day of the other date
if (year == other.year && month == other.month && day <= other.day) {
return true;
}
// If none of the above conditions are met, return false
return false;
}