From 9f01b4a7caea27ab8d7010eb871a3ad8651b4f3c Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Mon, 28 Dec 2020 15:33:25 +0530 Subject: [PATCH] [Extension] Add DateTime extension for same Date --- lib/src/extensions/date_time.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/src/extensions/date_time.dart diff --git a/lib/src/extensions/date_time.dart b/lib/src/extensions/date_time.dart new file mode 100644 index 0000000..a421929 --- /dev/null +++ b/lib/src/extensions/date_time.dart @@ -0,0 +1,17 @@ +extension DateTimeX on DateTime { + /// Use [isSameDate] to check whether the date + /// + /// matches with the date passed as an argument + /// + /// For example: + /// + /// Date 13 Dec 2020 12:01 AM and 13 Dec 2020 1:19 PM + /// + /// when compared would return [true] whereas + /// + /// 13 Dec 2020 and 13 Dec 2019 would return [false] + bool isSameDate(DateTime other) { + assert(other != null, "Date should not be null"); + return year == other.year && month == other.month && day == other.day; + } +}