Skip to content

Instantly share code, notes, and snippets.

@TheBrenny
Last active July 17, 2020 06:23
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 TheBrenny/91371b77d07f38a271ef70ec1eefa353 to your computer and use it in GitHub Desktop.
Save TheBrenny/91371b77d07f38a271ef70ec1eefa353 to your computer and use it in GitHub Desktop.
Extending DateTime
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