Last active
July 1, 2020 20:47
-
-
Save Grohden/e3a6375e587ea8f8c61505b8a0888a38 to your computer and use it in GitHub Desktop.
Dart extension for DateTime sum/subtraction operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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