sum method

DateTime sum({
  1. int years = 0,
  2. int months = 0,
  3. int days = 0,
  4. int hours = 0,
  5. int minutes = 0,
  6. int seconds = 0,
  7. int milliseconds = 0,
  8. int microseconds = 0,
})

Returns a new DateTime object by adding the specified amount of time to the current date and time.

The years, monthsh], days, hours, minutes, seconds, milliseconds, and microseconds parameters represent the amount of time to add to the current date and time. If any of these parameters are not provided, their default value is 0.

Example usage:

DateTime currentDate = DateTime.now();
DateTime futureDate = currentDate.sum(year: 1, month: 3, day: 7);
print(futureDate); // Output: 2023-04-07 12:34:56.789

Implementation

DateTime sum({int years = 0, int months = 0, int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0}) {
  return DateTime(
    year + (years),
    month + (months),
    day + (days),
    hour + (hours),
    minute + (minutes),
    second + (seconds),
    millisecond + (milliseconds),
    microsecond + (microseconds),
  );
}