def clipPeriod(period, clipPeriod): """ Clip the start/end period so that it lies entirely within the clip period. @param period: the (start, end) tuple for the period to be clipped. @param clipPeriod: the (start, end) tuple for the period to clip to. @return: the (start, end) tuple for the clipped period, or None if the period is outside the clip period """ start = period.getStart() end = period.getEnd() clipStart = clipPeriod.getStart() clipEnd = clipPeriod.getEnd() if start < clipStart: start = clipStart if end > clipEnd: end = clipEnd if start >= end: return None else: # Try to preserve use of duration in period result = Period(start, end) result.setUseDuration(period.getUseDuration()) return result
def clipPeriod(period, clipPeriod): """ Clip the start/end period so that it lies entirely within the clip period. @param period: the (start, end) tuple for the period to be clipped. @param clipPeriod: the (start, end) tuple for the period to clip to. @return: the (start, end) tuple for the clipped period, or None if the period is outside the clip period """ start = period.getStart() end = period.getEnd() clipStart = clipPeriod.getStart() clipEnd = clipPeriod.getEnd() if start < clipStart: start = clipStart if end > clipEnd: end = clipEnd if start >= end: return None else: # Try to preserve use of duration in period result = Period(start, end) result.setUseDuration(period.getUseDuration()) return result
def testSetUseDuration(self): p1 = Period( start=DateTime(2000, 1, 1, 0, 0, 0), end=DateTime(2000, 1, 1, 1, 0, 0), ) p1.setUseDuration(True) self.assertTrue(p1.getText(), "20000101T000000/PT1H") p2 = Period( start=DateTime(2000, 1, 1, 0, 0, 0), duration=Duration(hours=1), ) p2.setUseDuration(False) self.assertTrue(p2.getText(), "20000101T000000/20000101T010000")
def testSetUseDuration(self): p1 = Period( start=DateTime(2000, 1, 1, 0, 0, 0), end=DateTime(2000, 1, 1, 1, 0, 0), ) p1.setUseDuration(True) self.assertTrue(p1.getText(), "20000101T000000/PT1H") p2 = Period( start=DateTime(2000, 1, 1, 0, 0, 0), duration=Duration(hours=1), ) p2.setUseDuration(False) self.assertTrue(p2.getText(), "20000101T000000/20000101T010000")