subtractHours method

DateTime subtractHours(
  1. int hours
)

Subtracts the specified number of hours from the current DateTime.

Args: hours (int): The number of hours to subtract.

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

Implementation

DateTime subtractHours(int hours) {
  if (hours == 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(hours: hours).dateTime;
}