Last active
July 17, 2020 06:23
-
-
Save TheBrenny/91371b77d07f38a271ef70ec1eefa353 to your computer and use it in GitHub Desktop.
Extending DateTime
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
void main() { | |
var now = new DateTime.now(); | |
var later = now.add(const Duration(seconds: 5)); | |
print("now > later == ${now > later}"); | |
print("now >= later == ${now >= later}"); | |
print("now < later == ${now < later}"); | |
print("now <= later == ${now <= later}"); | |
} | |
extension BetterDateTime on DateTime { | |
bool operator <(dynamic other) { | |
return other is DateTime && this.isBefore(other); | |
} | |
bool operator <=(dynamic other) { | |
return other is DateTime && (this < other || this.isAtSameMomentAs(other)); | |
} | |
bool operator >(dynamic other) { | |
return other is DateTime && this.isAfter(other); | |
} | |
bool operator >=(dynamic other) { | |
return other is DateTime && (this > other || this.isAtSameMomentAs(other)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment