Repository: dimitarOnGithub/temporals

Issue:
DatePeriod implementation
Implemented the `is_before` and `is_after` logic for the `DatePeriod` class

Hints from issue comments:

Solution patch:
diff --git a/temporals/periods.py b/temporals/periods.py
index 64b0248..5a10dda 100644
--- a/temporals/periods.py
+++ b/temporals/periods.py
@@ -423,6 +423,54 @@ def __contains__(self, item):
             return self.start <= item <= self.end
         return False
 
+    def is_before(self,
+                  other: Union['DatePeriod', 'DatetimePeriod', datetime, date]
+                  ) -> bool:
+        """ Test if this period is ending before another one begins. This check will evaluate as True in the
+        following scenario:
+        2024-01-01        2024-01-05
+            |================|   <------ This period
+                                |================|
+                            2024-01-06        2024-01-10
+
+        Since dates do not distinguish between specific hours, periods sharing the same start-end date, or vice versa,
+        are considered overlapping.
+        """
+        _value: date = None
+        if isinstance(other, DatePeriod):
+            _value = other.start
+        elif isinstance(other, DatetimePeriod):
+            _value = other.start.date()
+        elif isinstance(other, datetime):
+            _value = other.date()
+        else:
+            _value = other
+        return self.end < _value
+
+    def is_after(self,
+                 other: Union['DatePeriod', 'DatetimePeriod', datetime, date]
+                 ) -> bool:
+        """ Test if this period is starting after another one ends. This check will evaluate as True in the
+        following scenario:
+        2024-01-01        2024-01-05
+            |================|
+                                |================| <----- This period
+                            2024-01-06        2024-01-10
+
+        Since dates do not distinguish between specific hours, periods sharing the same start-end date, or vice versa,
+        are considered overlapping.
+        """
+        _value: date = None
+        if isinstance(other, DatePeriod):
+            _value = other.end
+        elif isinstance(other, DatetimePeriod):
+            _value = other.end.date()
+        elif isinstance(other, datetime):
+            _value = other.date()
+        else:
+            _value = other
+        return _value < self.start
+
     def overlaps_with(self,
                       other: Union['DatePeriod', 'DatetimePeriod']
                       ) -> bool:


Test patch:
diff --git a/tests/test_dateperiod.py b/tests/test_dateperiod.py
index e96cca3..b0f44a6 100644
--- a/tests/test_dateperiod.py
+++ b/tests/test_dateperiod.py
@@ -77,6 +77,64 @@ def test_membership(self):
         self.period_dt = DatetimePeriod(start=self.start_dt, end=self.end_dt)
         assert self.period_dt in self.period
 
+    def test_is_before(self):
+        self.start = date(2024, 1, 1)
+        self.end = date(2024, 1, 10)
+        self.period = DatePeriod(start=self.start, end=self.end)
+        assert self.period.is_before(date(2024, 1, 11)) is True
+        assert self.period.is_before(date(2024, 1, 10)) is False
+        assert self.period.is_before(datetime(2024, 1, 11, 8, 0)) is True
+        assert self.period.is_before(datetime(2024, 1, 10, 8, 0)) is False
+
+        self.other_start = date(2024, 1, 11)
+        self.other_end = date(2024, 1, 30)
+        self.other_period = DatePeriod(start=self.other_start, end=self.other_end)
+        assert self.period.is_before(self.other_period) is True
+
+        self.other_start = date(2024, 1, 10)
+        self.other_end = date(2024, 1, 30)
+        self.other_period = DatePeriod(start=self.other_start, end=self.other_end)
+        assert self.period.is_before(self.other_period) is False
+
+        self.other_start = datetime(2024, 1, 10, 8, 0)
+        self.other_end = datetime(2024, 1, 12, 8, 0)
+        self.other_period = DatetimePeriod(start=self.other_start, end=self.other_end)
+        assert self.period.is_before(self.other_period) is False
+
+        self.other_start = datetime(2024, 1, 11, 8, 0)
+        self.other_end = datetime(2024, 1, 12, 8, 0)
+        self.other_period = DatetimePeriod(start=self.other_start, end=self.other_end)
+        assert self.period.is_before(self.other_period) is True
+
+    def test_is_after(self):
+        self.start = date(2024, 1, 10)
+        self.end = date(2024, 1, 20)
+        self.period = DatePeriod(start=self.start, end=self.end)
+        assert self.period.is_after(date(2024, 1, 10)) is False
+        assert self.period.is_after(date(2024, 1, 9)) is True
+        assert self.period.is_after(datetime(2024, 1, 10, 8, 0)) is False
+        assert self.period.is_after(datetime(2024, 1, 9, 8, 0)) is True
+
+        self.other_start = date(2024, 1, 1)
+        self.other_end = date(2024, 1, 10)
+        self.other_period = DatePeriod(start=self.other_start, end=self.other_end)
+        assert self.period.is_after(self.other_period) is False
+
+        self.other_start = date(2024, 1, 1)
+        self.other_end = date(2024, 1, 5)
+        self.other_period = DatePeriod(start=self.other_start, end=self.other_end)
+        assert self.period.is_after(self.other_period) is True
+
+        self.other_start = datetime(2024, 1, 1, 8, 0)
+        self.other_end = datetime(2024, 1, 10, 8, 0)
+        self.other_period = DatetimePeriod(start=self.other_start, end=self.other_end)
+        assert self.period.is_after(self.other_period) is False
+
+        self.other_start = datetime(2024, 1, 1, 8, 0)
+        self.other_end = datetime(2024, 1, 9, 8, 0)
+        self.other_period = DatetimePeriod(start=self.other_start, end=self.other_end)
+        assert self.period.is_after(self.other_period) is True
+
     def test_overlaps(self):
         """
         2024-01-01 Period 1   2024-01-10