コード例 #1
0
 def test_bare_day_of_week(self):
     """Issue: https://github.com/Cartroo/ttrack/issues/5"""
     tree = datetimeparse.DateSubtree("x")
     # 8th June 2012 was a Friday.
     with fake_now(2012, 6, 8):
         fields = {}
         self.assertEqual(tree.check_match(("Wednesday", ), fields=fields),
                          None)
         self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 6)]})
         fields = {}
         self.assertEqual(tree.check_match(("Sun", ), fields=fields), None)
         self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 10)]})
コード例 #2
0
 def test_date(self):
     tree = datetimeparse.DateSubtree("x")
     fields = {}
     self.assertEqual(tree.check_match(("2012-02-03", ), fields=fields),
                      None)
     self.assertEqual(fields, {"<x>": [datetime.date(2012, 2, 3)]})
     fields = {}
     self.assertEqual(tree.check_match(("15/4/2030", ), fields=fields),
                      None)
     self.assertEqual(fields, {"<x>": [datetime.date(2030, 4, 15)]})
     self.assertRegexpMatches(tree.check_match(("4-15-2030", )),
                              "not a valid")
コード例 #3
0
 def test_yesterday_today_tomorrow(self):
     tree = datetimeparse.DateSubtree("x")
     with fake_now(2012, 6, 10, 14, 20, 40):
         fields = {}
         self.assertEqual(tree.check_match(("yesterday", ), fields=fields),
                          None)
         self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 9)]})
         fields = {}
         self.assertEqual(tree.check_match(("today", ), fields=fields),
                          None)
         self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 10)]})
         fields = {}
         self.assertEqual(tree.check_match(("tomorrow", ), fields=fields),
                          None)
         self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 11)]})
コード例 #4
0
    def test_day_of_week(self):
        tree = datetimeparse.DateSubtree("x")
        # 8th June 2012 was a Friday.
        with fake_now(2012, 6, 8):
            fields = {}
            self.assertEqual(
                tree.check_match(("Wednesday", "this", "week"), fields=fields),
                None)
            self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 6)]})
            fields = {}
            self.assertEqual(
                tree.check_match(("Sun", "last", "week"), fields=fields), None)
            self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 3)]})
            fields = {}
            self.assertEqual(
                tree.check_match(("Mon", "next", "week"), fields=fields), None)
            self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 11)]})

        # 10th June 2012 was a Sunday.
        with fake_now(2012, 6, 10):
            fields = {}
            self.assertEqual(
                tree.check_match(("Sunday", "in", "2", "weeks"),
                                 fields=fields), None)
            self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 24)]})
            fields = {}
            self.assertEqual(
                tree.check_match(("Monday", "in", "3", "weeks"),
                                 fields=fields), None)
            self.assertEqual(fields, {"<x>": [datetime.date(2012, 6, 25)]})
            fields = {}
            self.assertEqual(
                tree.check_match(("Wednesday", "4", "weeks", "from", "now"),
                                 fields=fields), None)
            self.assertEqual(fields, {"<x>": [datetime.date(2012, 7, 4)]})

        # 4th June 2012 was a Monday.
        with fake_now(2012, 6, 4):
            fields = {}
            self.assertEqual(
                tree.check_match(("Monday", "2", "weeks", "ago"),
                                 fields=fields), None)
            self.assertEqual(fields, {"<x>": [datetime.date(2012, 5, 21)]})
            fields = {}
            self.assertEqual(
                tree.check_match(("Sunday", "3", "weeks", "earlier"),
                                 fields=fields), None)
            self.assertEqual(fields, {"<x>": [datetime.date(2012, 5, 20)]})
コード例 #5
0
 def test_day_of_month(self):
     tree = datetimeparse.DateSubtree("x")
     fields = {}
     self.assertEqual(tree.check_match(("3", "Nov", "2012"), fields=fields),
                      None)
     self.assertEqual(fields, {"<x>": [datetime.date(2012, 11, 3)]})
     fields = {}
     self.assertEqual(
         tree.check_match(("1st", "of", "September", "2013"),
                          fields=fields), None)
     self.assertEqual(fields, {"<x>": [datetime.date(2013, 9, 1)]})
     with fake_now(2010, 1, 1):
         fields = {}
         self.assertEqual(tree.check_match(("22nd", "May"), fields=fields),
                          None)
         self.assertEqual(fields, {"<x>": [datetime.date(2010, 5, 22)]})
     self.assertRegexpMatches(tree.check_match(("33 Nov 2012", )),
                              "not a valid")
     self.assertRegexpMatches(tree.check_match(("1 of Wibble 2012", )),
                              "not a valid")