Skip to content

Instantly share code, notes, and snippets.

@Grohden
Last active July 1, 2020 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grohden/e3a6375e587ea8f8c61505b8a0888a38 to your computer and use it in GitHub Desktop.
Save Grohden/e3a6375e587ea8f8c61505b8a0888a38 to your computer and use it in GitHub Desktop.
Dart extension for DateTime sum/subtraction operations
extension CopyWithAdditional on DateTime {
DateTime copyWithAdditional({
int years,
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,
);
}
}
void main() {
print(DateTime.now().copyWithAdditional(years: 2, months: 14));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment