def testTESequenceSelectsAnyMemberThatAppliesToTheDate(self): # first tuesday and last friday of the month fnt = te.temporalExpressionSequence([ \ te.dayInMonth(2,0) \ ,te.dayInMonth(5,-1) \ ]) dtApplies1 = dt.datetime(2015, 12, 25, 0, 0, 0, tzinfo=tz.utc) dtApplies2 = dt.datetime(2015, 2, 3, 0, 0, 0, tzinfo=tz.utc) dtDoesNotApply1 = dt.datetime(2015, 2, 4, 0, 0, 0, tzinfo=tz.utc) self.assertTrue(fnt(dtApplies1)) self.assertTrue(fnt(dtApplies2)) self.assertFalse(fnt(dtDoesNotApply1))
def testTESequenceSelectsAnyMemberThatAppliesToTheDate(self): # first tuesday and last friday of the month fnt = te.temporalExpressionSequence([ \ te.dayInMonth(2,0) \ ,te.dayInMonth(5,-1) \ ]) dtApplies1 = dt.datetime(2015,12,25,0,0,0,tzinfo=tz.utc) dtApplies2 = dt.datetime(2015,2,3,0,0,0,tzinfo=tz.utc) dtDoesNotApply1 = dt.datetime(2015,2,4,0,0,0,tzinfo=tz.utc) self.assertTrue(fnt(dtApplies1)) self.assertTrue(fnt(dtApplies2)) self.assertFalse(fnt(dtDoesNotApply1))
def testGenerateAllWorkDaysInMarch(self): fnt = te.temporalExpressionDifference( \ te.rangeInYear(3,1,4,1) , te.temporalExpressionSequence([ \ te.dayOfWeek(0), te.dayOfWeek(6)])) dateList = [d for d in de.dateRangeGenerator( \ dt.datetime(2015,3,1,0,0,0, tzinfo=tz.utc) \ ,dt.datetime(2015,4,1,0,0,0, tzinfo=tz.utc)) \ if fnt(d)] self.assertEqual(dateList[0], dt.datetime(2015,3,2,0,0,0, tzinfo=tz.utc)) self.assertEqual(dateList[-1], dt.datetime(2015,3,31,0,0,0, tzinfo=tz.utc)) self.assertEqual(len(dateList), 22)
def testTEIntersectionSelectsOnlyIfDateMatchesAllConditions(self): # Tuesday and Friday in March fnt = te.temporalExpressionIntersection([ \ te.temporalExpressionSequence([ \ te.dayOfWeek(2), te.dayOfWeek(5)]) \ , te.rangeInYear(3,1,3,31)]) dtApplies1 = dt.datetime(2015, 3, 24, 0, 0, 0, tzinfo=tz.utc) dtApplies2 = dt.datetime(2015, 3, 6, 0, 0, 0, tzinfo=tz.utc) dtDoesNotApply1 = dt.datetime(2015, 2, 4, 0, 0, 0, tzinfo=tz.utc) dtDoesNotApply2 = dt.datetime(2015, 3, 4, 0, 0, 0, tzinfo=tz.utc) self.assertTrue(fnt(dtApplies1)) self.assertTrue(fnt(dtApplies2)) self.assertFalse(fnt(dtDoesNotApply1)) self.assertFalse(fnt(dtDoesNotApply2))
def testGenerateAllWorkDaysInMarch(self): fnt = te.temporalExpressionDifference( \ te.rangeInYear(3,1,4,1) , te.temporalExpressionSequence([ \ te.dayOfWeek(0), te.dayOfWeek(6)])) dateList = [d for d in de.dateRangeGenerator( \ dt.datetime(2015,3,1,0,0,0, tzinfo=tz.utc) \ ,dt.datetime(2015,4,1,0,0,0, tzinfo=tz.utc)) \ if fnt(d)] self.assertEqual(dateList[0], dt.datetime(2015, 3, 2, 0, 0, 0, tzinfo=tz.utc)) self.assertEqual(dateList[-1], dt.datetime(2015, 3, 31, 0, 0, 0, tzinfo=tz.utc)) self.assertEqual(len(dateList), 22)
def testTEIntersectionSelectsOnlyIfDateMatchesAllConditions(self): # Tuesday and Friday in March fnt = te.temporalExpressionIntersection([ \ te.temporalExpressionSequence([ \ te.dayOfWeek(2), te.dayOfWeek(5)]) \ , te.rangeInYear(3,1,3,31)]) dtApplies1 = dt.datetime(2015,3,24,0,0,0,tzinfo=tz.utc) dtApplies2 = dt.datetime(2015,3,6,0,0,0,tzinfo=tz.utc) dtDoesNotApply1 = dt.datetime(2015,2,4,0,0,0,tzinfo=tz.utc) dtDoesNotApply2 = dt.datetime(2015,3,4,0,0,0,tzinfo=tz.utc) self.assertTrue(fnt(dtApplies1)) self.assertTrue(fnt(dtApplies2)) self.assertFalse(fnt(dtDoesNotApply1)) self.assertFalse(fnt(dtDoesNotApply2))
def testTEDifferenceExcludesWeekends(self): # Excludes weekends from dates fnt = te.temporalExpressionDifference( \ te.rangeInYear(3,1,3,31) , te.temporalExpressionSequence([ \ te.dayOfWeek(0), te.dayOfWeek(6)])) dtApplies1 = dt.datetime(2015, 3, 24, 0, 0, 0, tzinfo=tz.utc) dtApplies2 = dt.datetime(2015, 3, 6, 0, 0, 0, tzinfo=tz.utc) dtDoesNotApply1 = dt.datetime(2015, 2, 4, 0, 0, 0, tzinfo=tz.utc) dtDoesNotApply2 = dt.datetime(2015, 3, 7, 0, 0, 0, tzinfo=tz.utc) dtDoesNotApply3 = dt.datetime(2015, 3, 29, 0, 0, 0, tzinfo=tz.utc) self.assertTrue(fnt(dtApplies1)) self.assertTrue(fnt(dtApplies2)) self.assertFalse(fnt(dtDoesNotApply1)) self.assertFalse(fnt(dtDoesNotApply2)) self.assertFalse(fnt(dtDoesNotApply3))
def testTEDifferenceExcludesWeekends(self): # Excludes weekends from dates fnt = te.temporalExpressionDifference( \ te.rangeInYear(3,1,3,31) , te.temporalExpressionSequence([ \ te.dayOfWeek(0), te.dayOfWeek(6)])) dtApplies1 = dt.datetime(2015,3,24,0,0,0,tzinfo=tz.utc) dtApplies2 = dt.datetime(2015,3,6,0,0,0,tzinfo=tz.utc) dtDoesNotApply1 = dt.datetime(2015,2,4,0,0,0,tzinfo=tz.utc) dtDoesNotApply2 = dt.datetime(2015,3,7,0,0,0,tzinfo=tz.utc) dtDoesNotApply3 = dt.datetime(2015,3,29,0,0,0,tzinfo=tz.utc) self.assertTrue(fnt(dtApplies1)) self.assertTrue(fnt(dtApplies2)) self.assertFalse(fnt(dtDoesNotApply1)) self.assertFalse(fnt(dtDoesNotApply2)) self.assertFalse(fnt(dtDoesNotApply3))