subtractDays method

DateTime subtractDays(
  1. int? days
)

Subtracts the specified number of days from the current DateTime.

Args: days (int?): The number of days to subtract.

Returns: DateTime: A new DateTime object with the subtracted days.

Implementation

DateTime subtractDays(int? days) {
  if (days == null || days == 0) {
    // same
    return this;
  }

  // We used the Jiffy package to add years, months, etc
  // https://stackoverflow.com/questions/54792056/add-subtract-months-years-to-date-in-dart
  return Jiffy.parseFromDateTime(this).subtract(days: days).dateTime;
}