예제 #1
0
    def test_monweekday_timeperiod_with_exclude(self):
        """
        Test mon week day timeperiod with exclude

        :return: None
        """
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 july - monday 1 september  16:30-24:00'
        timeperiod = Timeperiod()
        timeperiod.timeperiod_name = 'T1'
        timeperiod.resolve_daterange(
            timeperiod.dateranges,
            'tuesday -1 july - monday 1 september  16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # and from april (before) to august monday 3 (monday 16 august),
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges,
                             'thursday 1 april - monday 3 august 00:00-24:00')
        timeperiod.exclude = [t2]
        timeperiod.cache = {}
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual('Tue Aug 17 16:30:00 2010', t_next)
예제 #2
0
    def test_dayweek_timeperiod_with_exclude(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a simple same day
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday 2 16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "T next", t_next
        self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'tuesday 00:00-23:58')
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 58 + 1second :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)

        print "T next raw", t_next
        t_next = time.asctime(time.localtime(t_next))
        print "TOTO T next", t_next

        self.assertEqual('Tue Jul 13 23:58:01 2010', t_next)
예제 #3
0
    def test_dayweek_timeperiod_with_exclude(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a simple same day
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday 2 16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "T next", t_next
        self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'tuesday 00:00-23:58')
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 58 + 1second :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)

        print "T next raw", t_next
        t_next = time.asctime(time.localtime(t_next))
        print "TOTO T next", t_next

        self.assertEqual('Tue Jul 13 23:58:01 2010', t_next)
    def test_monweekday_timeperiod_with_exclude(self):
        """
        Test mon week day timeperiod with exclude

        :return: None
        """
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print("Testing daterange", 'tuesday -1 july - monday 1 september  16:30-24:00')
        timeperiod = Timeperiod()
        timeperiod.timeperiod_name = 'T1'
        timeperiod.resolve_daterange(timeperiod.dateranges,
                                     'tuesday -1 july - monday 1 september  16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print("Next without exclude", t_next)
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # and from april (before) to august monday 3 (monday 16 august),
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'thursday 1 april - monday 3 august 00:00-24:00')
        timeperiod.exclude = [t2]
        timeperiod.cache = {}
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual('Tue Aug 17 16:30:00 2010', t_next)
    def test_mondayweek_timeperiod_with_exclude(self):
        """
        Test monday week timeperiod with exclude

        :return: None
        """
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a simple same day
        timeperiod = Timeperiod()
        timeperiod.timeperiod_name = 'T1'
        timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 3 16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual("Tue Jul 20 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before) to august (after), and full time.
        # But the 17 is a tuesday, but the 3 of august, so the next 3 tuesday is
        # ..... the Tue Sep 21 :) Yes, we should wait quite a lot :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 23 00:00-24:00')
        timeperiod.exclude = [t2]
        timeperiod.cache = {}
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual('Tue Sep 21 16:30:00 2010', t_next)

        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        t_exclude_inv = time.asctime(time.localtime(t_exclude_inv))
        self.assertEqual('Tue Aug 24 00:00:00 2010', t_exclude_inv)
예제 #6
0
    def test_funky_mondayweek_timeperiod_with_exclude_and_multiple_daterange(
            self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 - monday 1  16:30-24:00'
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday -1 - monday 1  16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before so agust (after), and full time.
        # But the 27 is nw not possible? So what next? Add a month!
        # But maybe it's not enoutgth? :)
        # The withoutthe 2nd exclude, it's the Tues Aug 31, btu it's inside
        # saturday -1 - monday 1 because saturday -1 is the 28 august, so no.
        # in september saturday -1 is the 25, and tuesday -1 is 28, so still no
        # A month again! So now tuesday -1 is 26 and saturday -1 is 30. So ok
        # for this one! that was quite long isn't it? And funky! :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        # Oups, I add a inner daterange ;)
        t2.resolve_daterange(t2.dateranges,
                             'saturday -1 - monday 1  16:00-24:00')
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 59 :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        #print "Check from", time.asctime(time.localtime(july_the_12))
        #t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        #print "T2 next valid", time.asctime(time.localtime(t_exclude))
        print "Next invalid T2", time.asctime(time.localtime(t_exclude_inv))

        print "T next raw", t_next
        print "T next?", time.asctime(time.localtime(t_next))
        t_next = time.asctime(time.localtime(t_next))

        self.assertEqual('Tue Oct 26 16:30:00 2010', t_next)
        print "Finish this Funky test :)"
예제 #7
0
    def test_funky_mondayweek_timeperiod_with_exclude_and_multiple_daterange(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 - monday 1  16:30-24:00'
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday -1 - monday 1  16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before so agust (after), and full time.
        # But the 27 is nw not possible? So what next? Add a month!
        # But maybe it's not enoutgth? :)
        # The withoutthe 2nd exclude, it's the Tues Aug 31, btu it's inside
        # saturday -1 - monday 1 because saturday -1 is the 28 august, so no.
        # in september saturday -1 is the 25, and tuesday -1 is 28, so still no
        # A month again! So now tuesday -1 is 26 and saturday -1 is 30. So ok
        # for this one! that was quite long isn't it? And funky! :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        # Oups, I add a inner daterange ;)
        t2.resolve_daterange(t2.dateranges, 'saturday -1 - monday 1  16:00-24:00')
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 59 :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        #print "Check from", time.asctime(time.localtime(july_the_12))
        #t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        #print "T2 next valid", time.asctime(time.localtime(t_exclude))
        print "Next invalid T2", time.asctime(time.localtime(t_exclude_inv))

        print "T next raw", t_next
        print "T next?", time.asctime(time.localtime(t_next))
        t_next = time.asctime(time.localtime(t_next))

        self.assertEqual('Tue Oct 26 16:30:00 2010', t_next)
        print "Finish this Funky test :)"
예제 #8
0
    def test_mondayweek_timeperiod_with_exclude_and_multiple_daterange(self):
        """
        Test monday week timeperiod with exclude multiple dateranges

        :return: None
        """
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 - monday 1  16:30-24:00'
        timeperiod = Timeperiod()
        timeperiod.timeperiod_name = 'T1'
        timeperiod.resolve_daterange(timeperiod.dateranges,
                                     'tuesday -1 - monday 1  16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before) to august (after), and full time.
        # But the 27 is nw not possible? So what next? Add a month!
        # But maybe it's not enough? :)
        # The without the 2nd exclude, it's the Tues Aug 31, but it's inside
        # saturday -1 - monday 1 because saturday -1 is the 28 august, so no.
        # in september saturday -1 is the 25, and tuesday -1 is 28, so still no
        # A month again! So now tuesday -1 is 26 and saturday -1 is 30. So ok
        # for this one! that was quite long isn't it?
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        t2.resolve_daterange(t2.dateranges,
                             'saturday -1 - monday 1  16:00-24:00')
        timeperiod.exclude = [t2]
        timeperiod.cache = {}
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual('Tue Oct 26 16:30:00 2010', t_next)

        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        t_exclude_inv = time.asctime(time.localtime(t_exclude_inv))
        self.assertEqual('Tue Aug 17 00:00:00 2010', t_exclude_inv)
예제 #9
0
    def test_simple_timeperiod_with_exclude(self):
        """
        Test simple timeperiod with exclude periods

        :return: None
        """
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
        print july_the_12

        # First a false test, no results
        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges,
                                     '1999-01-28  00:00-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(now)
        self.assertIs(None, t_next)

        # Then a simple same day
        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges,
                                     'tuesday 16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print t_next
        self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        t2 = Timeperiod()
        t2.timeperiod_name = ''
        t2.resolve_daterange(t2.dateranges, 'tuesday 08:30-21:00')
        timeperiod.exclude = [t2]
        # So the next will be after 16:30 and not before 21:00. So
        # It will be 21:00:01 (first second after invalid is valid)

        # we clean the cache of previous calc of t ;)
        timeperiod.cache = {}
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "T nxt with exclude:", t_next
        self.assertEqual("Tue Jul 13 21:00:01 2010", t_next)
예제 #10
0
    def test_mondayweek_timeperiod_with_exclude_bis(self):
        """
        Test monday weeb timeperiod with exclude, version 2 :D

        :return: None
        """
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 - monday 1  16:30-24:00'
        timerange = Timeperiod()
        timerange.timeperiod_name = 'T1'
        timerange.resolve_daterange(timerange.dateranges,
                                    'tuesday -1 - monday 1  16:30-24:00')
        t_next = timerange.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before) to august (after), and full time.
        # But the 27 is now not possible? So what next? Add a month!
        # last tuesday of august, the 31 :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        timerange.exclude = [t2]
        timerange.cache = {}
        t_next = timerange.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual('Tue Aug 31 16:30:00 2010', t_next)

        t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude = time.asctime(time.localtime(t_exclude))
        self.assertEqual('Mon Jul 12 15:00:00 2010', t_exclude)

        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        t_exclude_inv = time.asctime(time.localtime(t_exclude_inv))
        self.assertEqual('Tue Aug 17 00:00:00 2010', t_exclude_inv)
예제 #11
0
    def test_monweekday_timeperiod_with_exclude(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 july - monday 1 august  16:30-24:00'
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(
            t.dateranges, 'tuesday -1 july - monday 1 september  16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # and from april (before) to august monday 3 (monday 16 august),
        # so Jul 17 is no more possible. So just after it, Tue 17
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges,
                             'thursday 1 april - monday 3 august 00:00-24:00')
        print t2.dateranges[0].__dict__
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 59 :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        #print "Check from", time.asctime(time.localtime(july_the_12))
        #t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        #print "T2 next valid", time.asctime(time.localtime(t_exclude))
        print "Next invalid T2", time.asctime(time.localtime(t_exclude_inv))

        print "T next raw", t_next
        print "T next?", time.asctime(time.localtime(t_next))
        t_next = time.asctime(time.localtime(t_next))

        self.assertEqual('Tue Aug 17 16:30:00 2010', t_next)
예제 #12
0
    def test_mondayweek_timeperiod_with_exclude_and_multiple_daterange(self):
        """
        Test monday week timeperiod with exclude multiple dateranges

        :return: None
        """
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print("Testing daterange", 'tuesday -1 - monday 1  16:30-24:00')
        timeperiod = Timeperiod()
        timeperiod.timeperiod_name = 'T1'
        timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday -1 - monday 1  16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print("Next without exclude", t_next)
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before) to august (after), and full time.
        # But the 27 is nw not possible? So what next? Add a month!
        # But maybe it's not enough? :)
        # The without the 2nd exclude, it's the Tues Aug 31, but it's inside
        # saturday -1 - monday 1 because saturday -1 is the 28 august, so no.
        # in september saturday -1 is the 25, and tuesday -1 is 28, so still no
        # A month again! So now tuesday -1 is 26 and saturday -1 is 30. So ok
        # for this one! that was quite long isn't it?
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        t2.resolve_daterange(t2.dateranges, 'saturday -1 - monday 1  16:00-24:00')
        timeperiod.exclude = [t2]
        timeperiod.cache = {}
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual('Tue Oct 26 16:30:00 2010', t_next)

        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        t_exclude_inv = time.asctime(time.localtime(t_exclude_inv))
        self.assertEqual('Tue Aug 17 00:00:00 2010', t_exclude_inv)
예제 #13
0
    def test_mondayweek_timeperiod_with_exclude_bis(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 - monday 1  16:30-24:00'
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday -1 - monday 1  16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before so agust (after), and full time.
        # But the 27 is nw not possible? So what next? Add a month!
        # last tuesday of august, the 31 :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        #print t2.__dict__
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 59 :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        #print "Check from", time.asctime(time.localtime(july_the_12))
        #t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        #print "T2 next valid", time.asctime(time.localtime(t_exclude))
        print "Next invalid T2", time.asctime(time.localtime(t_exclude_inv))

        print "T next raw JEAN2", t_next
        print "T next?", time.asctime(time.localtime(t_next))
        t_next = time.asctime(time.localtime(t_next))

        self.assertEqual('Tue Aug 31 16:30:00 2010', t_next)
예제 #14
0
    def test_mondayweek_timeperiod_with_exclude_bis(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 - monday 1  16:30-24:00'
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday -1 - monday 1  16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before so agust (after), and full time.
        # But the 27 is nw not possible? So what next? Add a month!
        # last tuesday of august, the 31 :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        #print t2.__dict__
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 59 :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        #print "Check from", time.asctime(time.localtime(july_the_12))
        #t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        #print "T2 next valid", time.asctime(time.localtime(t_exclude))
        print "Next invalid T2", time.asctime(time.localtime(t_exclude_inv))

        print "T next raw JEAN2", t_next
        print "T next?", time.asctime(time.localtime(t_next))
        t_next = time.asctime(time.localtime(t_next))

        self.assertEqual('Tue Aug 31 16:30:00 2010', t_next)
예제 #15
0
    def test_mondayweek_timeperiod_with_exclude_bis(self):
        """
        Test monday weeb timeperiod with exclude, version 2 :D

        :return: None
        """
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print("Testing daterange", 'tuesday -1 - monday 1  16:30-24:00')
        timerange = Timeperiod()
        timerange.timeperiod_name = 'T1'
        timerange.resolve_daterange(timerange.dateranges, 'tuesday -1 - monday 1  16:30-24:00')
        t_next = timerange.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print("Next without exclude", t_next)
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before) to august (after), and full time.
        # But the 27 is now not possible? So what next? Add a month!
        # last tuesday of august, the 31 :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        timerange.exclude = [t2]
        timerange.cache = {}
        t_next = timerange.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual('Tue Aug 31 16:30:00 2010', t_next)

        t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude = time.asctime(time.localtime(t_exclude))
        self.assertEqual('Mon Jul 12 15:00:00 2010', t_exclude)

        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        t_exclude_inv = time.asctime(time.localtime(t_exclude_inv))
        self.assertEqual('Tue Aug 17 00:00:00 2010', t_exclude_inv)
예제 #16
0
    def test_simple_timeperiod_with_exclude(self):
        """
        Test simple timeperiod with exclude periods

        :return: None
        """
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
        print("July 12th, 2010: %s" % july_the_12)

        # First a false test, no results
        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges, '1999-01-28  00:00-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(now)
        self.assertIs(None, t_next)

        # Then a simple same day
        timeperiod = Timeperiod()
        timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print(t_next)
        self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        t2 = Timeperiod()
        t2.timeperiod_name = ''
        t2.resolve_daterange(t2.dateranges, 'tuesday 08:30-21:00')
        timeperiod.exclude = [t2]
        # So the next will be after 16:30 and not before 21:00. So
        # It will be 21:00:01 (first second after invalid is valid)

        # we clean the cache of previous calc of t ;)
        timeperiod.cache = {}
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print("T nxt with exclude:", t_next)
        self.assertEqual("Tue Jul 13 21:00:01 2010", t_next)
예제 #17
0
    def test_monweekday_timeperiod_with_exclude(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a funny daterange
        print "Testing daterange", 'tuesday -1 july - monday 1 august  16:30-24:00'
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday -1 july - monday 1 september  16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        print "Next without exclude", t_next
        self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # and from april (before) to august monday 3 (monday 16 august),
        # so Jul 17 is no more possible. So just after it, Tue 17
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'thursday 1 april - monday 3 august 00:00-24:00')
        print t2.dateranges[0].__dict__
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 59 :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        #print "Check from", time.asctime(time.localtime(july_the_12))
        #t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        #print "T2 next valid", time.asctime(time.localtime(t_exclude))
        print "Next invalid T2", time.asctime(time.localtime(t_exclude_inv))

        print "T next raw", t_next
        print "T next?", time.asctime(time.localtime(t_next))
        t_next = time.asctime(time.localtime(t_next))

        self.assertEqual('Tue Aug 17 16:30:00 2010', t_next)
예제 #18
0
    def test_mondayweek_timeperiod_with_exclude(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a simple same day
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday 2 16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before so agust (after), and full time.
        # But the 17 is a tuesday, but the 3 of august, so the next 2 tuesday is
        # ..... the Tue Sep 14 :) Yes, we should wait quite a lot :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        #print t2.__dict__
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 59 :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        #print "Check from", time.asctime(time.localtime(july_the_12))
        #t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        #print "T2 next valid", time.asctime(time.localtime(t_exclude))
        print "Next invalid T2", time.asctime(time.localtime(t_exclude_inv))

        print "T next raw JEAN", t_next
        print "T next?", time.asctime(time.localtime(t_next))
        t_next = time.asctime(time.localtime(t_next))

        self.assertEqual('Tue Sep 14 16:30:00 2010', t_next)
예제 #19
0
    def test_mondayweek_timeperiod_with_exclude(self):
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a simple same day
        t = Timeperiod()
        t.timeperiod_name = 'T1'
        t.resolve_daterange(t.dateranges, 'tuesday 2 16:30-24:00')
        t_next = t.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before so agust (after), and full time.
        # But the 17 is a tuesday, but the 3 of august, so the next 2 tuesday is
        # ..... the Tue Sep 14 :) Yes, we should wait quite a lot :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 16 00:00-24:00')
        #print t2.__dict__
        t.exclude = [t2]
        # We are a bad boy: first time period want a tuesday
        # but exclude do not want it until 23:58. So next is 59 :)
        t.cache = {}
        t_next = t.get_next_valid_time_from_t(july_the_12)
        #print "Check from", time.asctime(time.localtime(july_the_12))
        #t_exclude = t2.get_next_valid_time_from_t(july_the_12)
        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        #print "T2 next valid", time.asctime(time.localtime(t_exclude))
        print "Next invalid T2", time.asctime(time.localtime(t_exclude_inv))

        print "T next raw JEAN", t_next
        print "T next?", time.asctime(time.localtime(t_next))
        t_next = time.asctime(time.localtime(t_next))

        self.assertEqual('Tue Sep 14 16:30:00 2010', t_next)
예제 #20
0
    def test_mondayweek_timeperiod_with_exclude(self):
        """
        Test monday week timeperiod with exclude

        :return: None
        """
        self.print_header()
        now = time.time()
        # Get the 12 of july 2010 at 15:00, monday
        july_the_12 = time.mktime(
            time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))

        # Then a simple same day
        timeperiod = Timeperiod()
        timeperiod.timeperiod_name = 'T1'
        timeperiod.resolve_daterange(timeperiod.dateranges,
                                     'tuesday 3 16:30-24:00')
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual("Tue Jul 20 16:30:00 2010", t_next)

        # Now we add this timeperiod an exception
        # And a good one: from april (so before) to august (after), and full time.
        # But the 17 is a tuesday, but the 3 of august, so the next 3 tuesday is
        # ..... the Tue Sep 21 :) Yes, we should wait quite a lot :)
        t2 = Timeperiod()
        t2.timeperiod_name = 'T2'
        t2.resolve_daterange(t2.dateranges, 'april 1 - august 23 00:00-24:00')
        timeperiod.exclude = [t2]
        timeperiod.cache = {}
        t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
        t_next = time.asctime(time.localtime(t_next))
        self.assertEqual('Tue Sep 21 16:30:00 2010', t_next)

        t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
        t_exclude_inv = time.asctime(time.localtime(t_exclude_inv))
        self.assertEqual('Tue Aug 24 00:00:00 2010', t_exclude_inv)