def test_replace(self):
        expected_begin = datetime.datetime(2014, 8, 1, 6, 10, 23, 550)
        expected_end = datetime.datetime(2014, 8, 2, 6, 10, 23, 550)
        res = self.timerange % expression.Duration(hour=6)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 6, 1, 2, 10, 23, 550)
        expected_end = datetime.datetime(2014, 6, 2, 2, 10, 23, 550)
        res = self.timerange % expression.Duration(month=6)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2017, 8, 1, 2, 10, 23, 550)
        expected_end = datetime.datetime(2017, 8, 2, 2, 10, 23, 550)
        res = self.timerange % expression.Duration(year=2017)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 0, 0, 0, 0)
        expected_end = datetime.datetime(2014, 8, 2, 0, 0, 0, 0)
        res = self.timerange % expression.Duration(
            hour=0, minute=0, second=0, microsecond=0)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)
    def test_replace(self):
        expected_begin = datetime.datetime(2014, 8, 1, 2, 0, 0, 0)
        expected_end = datetime.datetime(2014, 8, 2, 2, 0, 0, 0)
        res = self.timerange % expression.Duration(hour=2)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 7, 31, 18, 0, 0, 0)
        expected_end = datetime.datetime(2014, 8, 1, 18, 0, 0, 0)
        res = self.timerange % expression.Duration(hour=18)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)
    def test_sub(self):
        expected_begin = datetime.datetime(2014, 8, 1, 0, 0, 0, 0)
        expected_end = datetime.datetime(2014, 8, 2, 0, 0, 0, 0)
        res = self.timerange - expression.Duration(hour=1)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 17, 0, 0, 0)
        expected_end = datetime.datetime(2014, 8, 2, 17, 0, 0, 0)
        res = self.timerange - expression.Duration(hour=8)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)
 def test_as_dict(self):
     d = expression.Duration(second=1, hour=1, day=1)
     dd = d.as_dict
     for unit in ('second', 'hour', 'day'):
         self.assertIn(unit, dd)
         self.assertEqual(dd[unit], 1)
     for unit in ('microsecond', 'minute', 'month', 'year', 'unknown'):
         self.assertNotIn(unit, dd)
 def test_handle_ambig_duration(self):
     d = expression.Duration(hour=10, unknown=2)
     self.assertRaises(expression.TimexExpressionError,
                       self.timestamp.__add__, d)
     self.assertRaises(expression.TimexExpressionError,
                       self.timestamp.__sub__, d)
     self.assertRaises(expression.TimexExpressionError,
                       self.timestamp.__mod__, d)
    def test_replace(self):
        expected = datetime.datetime(2014, 8, 2, 2, 10, 23, 550)
        res = self.timestamp % expression.Duration(day=2)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 6, 1, 2, 10, 23, 550)
        res = self.timestamp % expression.Duration(month=6)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2017, 8, 1, 2, 10, 23, 550)
        res = self.timestamp % expression.Duration(year=2017)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 8, 1, 0, 0, 0, 0)
        res = self.timestamp % expression.Duration(
            hour=0, minute=0, second=0, microsecond=0)
        self.assertEqual(res.timestamp, expected)
    def test_sub(self):
        expected = datetime.datetime(2014, 8, 1, 2, 10, 23, 540)
        res = self.timestamp - expression.Duration(microsecond=10)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 8, 1, 2, 10, 13, 550)
        res = self.timestamp - expression.Duration(second=10)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 8, 1, 2, 3, 23, 550)
        res = self.timestamp - expression.Duration(minute=7)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 8, 1, 1, 10, 23, 550)
        res = self.timestamp - expression.Duration(hour=1)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 7, 30, 2, 10, 23, 550)
        res = self.timestamp - expression.Duration(day=2)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 2, 1, 2, 10, 23, 550)
        res = self.timestamp - expression.Duration(month=6)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2011, 8, 1, 2, 10, 23, 550)
        res = self.timestamp - expression.Duration(year=3)
        self.assertEqual(res.timestamp, expected)
    def test_add(self):
        expected = datetime.datetime(2014, 8, 1, 2, 10, 23, 560)
        res = self.timestamp + expression.Duration(microsecond=10)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 8, 1, 2, 10, 33, 550)
        res = self.timestamp + expression.Duration(second=10)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 8, 1, 2, 17, 23, 550)
        res = self.timestamp + expression.Duration(minute=7)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 8, 1, 3, 10, 23, 550)
        res = self.timestamp + expression.Duration(hour=1)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2014, 8, 3, 2, 10, 23, 550)
        res = self.timestamp + expression.Duration(day=2)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2015, 2, 1, 2, 10, 23, 550)
        res = self.timestamp + expression.Duration(month=6)
        self.assertEqual(res.timestamp, expected)

        expected = datetime.datetime(2017, 8, 1, 2, 10, 23, 550)
        res = self.timestamp + expression.Duration(year=3)
        self.assertEqual(res.timestamp, expected)
 def setUp(self):
     super(TestDuration, self).setUp()
     self.second = expression.Duration(second=1)
     self.minute = expression.Duration(minute=1)
     self.hour = expression.Duration(hour=1)
     self.day = expression.Duration(day=1)
     self.month = expression.Duration(month=1)
     self.year = expression.Duration(year=1)
Esempio n. 10
0
    def test_handle_ambig_duration(self):
        d = expression.Duration(unknown=1)

        expected_begin = datetime.datetime(2014, 8, 1, 3, 10, 23, 550)
        expected_end = datetime.datetime(2014, 8, 2, 3, 10, 23, 550)
        res = self.timerange + d
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 1, 10, 23, 550)
        expected_end = datetime.datetime(2014, 8, 2, 1, 10, 23, 550)
        res = self.timerange - d
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 1, 10, 23, 550)
        expected_end = datetime.datetime(2014, 8, 2, 1, 10, 23, 550)
        res = self.timerange % d
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)
Esempio n. 11
0
    def test_sub(self):
        expected_begin = datetime.datetime(2014, 8, 1, 2, 10, 23, 540)
        expected_end = datetime.datetime(2014, 8, 2, 2, 10, 23, 540)
        res = self.timerange - expression.Duration(microsecond=10)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 2, 10, 13, 550)
        expected_end = datetime.datetime(2014, 8, 2, 2, 10, 13, 550)
        res = self.timerange - expression.Duration(second=10)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 2, 3, 23, 550)
        expected_end = datetime.datetime(2014, 8, 2, 2, 3, 23, 550)
        res = self.timerange - expression.Duration(minute=7)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 1, 10, 23, 550)
        expected_end = datetime.datetime(2014, 8, 2, 1, 10, 23, 550)
        res = self.timerange - expression.Duration(hour=1)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 7, 30, 2, 10, 23, 550)
        expected_end = datetime.datetime(2014, 7, 31, 2, 10, 23, 550)
        res = self.timerange - expression.Duration(day=2)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 2, 1, 2, 10, 23, 550)
        expected_end = datetime.datetime(2014, 2, 2, 2, 10, 23, 550)
        res = self.timerange - expression.Duration(month=6)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2011, 8, 1, 2, 10, 23, 550)
        expected_end = datetime.datetime(2011, 8, 2, 2, 10, 23, 550)
        res = self.timerange - expression.Duration(year=3)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)
Esempio n. 12
0
    def test_add(self):
        expected_begin = datetime.datetime(2014, 8, 1, 2, 10, 23, 560)
        expected_end = datetime.datetime(2014, 8, 2, 2, 10, 23, 560)
        res = self.timerange + expression.Duration(microsecond=10)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 2, 10, 33, 550)
        expected_end = datetime.datetime(2014, 8, 2, 2, 10, 33, 550)
        res = self.timerange + expression.Duration(second=10)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 2, 17, 23, 550)
        expected_end = datetime.datetime(2014, 8, 2, 2, 17, 23, 550)
        res = self.timerange + expression.Duration(minute=7)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 1, 3, 10, 23, 550)
        expected_end = datetime.datetime(2014, 8, 2, 3, 10, 23, 550)
        res = self.timerange + expression.Duration(hour=1)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2014, 8, 3, 2, 10, 23, 550)
        expected_end = datetime.datetime(2014, 8, 4, 2, 10, 23, 550)
        res = self.timerange + expression.Duration(day=2)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2015, 2, 1, 2, 10, 23, 550)
        expected_end = datetime.datetime(2015, 2, 2, 2, 10, 23, 550)
        res = self.timerange + expression.Duration(month=6)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)

        expected_begin = datetime.datetime(2017, 8, 1, 2, 10, 23, 550)
        expected_end = datetime.datetime(2017, 8, 2, 2, 10, 23, 550)
        res = self.timerange + expression.Duration(year=3)
        self.assertEqual(res.begin, expected_begin)
        self.assertEqual(res.end, expected_end)