forked from bjonnh/PyOrgMode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dates.py
67 lines (57 loc) · 2.3 KB
/
test_dates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import PyOrgMode
import unittest
class TestDates(unittest.TestCase):
"""Test the org file parser with several date formats"""
def test_baredate(self):
"""
Tests parsing dates without time.
"""
datestr = '<2013-11-20 Wed>'
date = PyOrgMode.OrgDate(datestr)
self.assertEqual(tuple(date.value), (2013, 11, 20, 0, 0, 0, 2, 324, -1))
self.assertEqual(date.get_value(), datestr)
def test_datetime(self):
"""
Tests parsing dates with time.
"""
datestr = '<2011-12-12 Mon 09:00>'
date = PyOrgMode.OrgDate(datestr)
self.assertEqual(tuple(date.value), (2011, 12, 12, 9, 0, 0, 0, 346, -1))
self.assertEqual(date.get_value(), datestr)
def test_datenoweekday(self):
"""
Tests parsing simple dates without weekdays.
"""
datestr = '<2013-11-20>'
date = PyOrgMode.OrgDate(datestr)
self.assertEqual(tuple(date.value), (2013, 11, 20, 0, 0, 0, 2, 324, -1))
self.assertEqual(date.get_value(), datestr)
def test_timerange(self):
"""
Tests parsing time ranges on the same day.
"""
datestr = '<2012-06-28 Thu 12:00-13:00>'
date = PyOrgMode.OrgDate(datestr)
self.assertEqual(tuple(date.value), (2012, 6, 28, 12, 0, 0, 3, 180, -1))
self.assertEqual(tuple(date.end), (2012, 6, 28, 13, 0, 0, 3, 180, -1))
self.assertEqual(date.get_value(), datestr)
def test_daterange(self):
"""
Tests parsing date ranges.
"""
datestr = '<2012-07-20 Fri>--<2012-07-31 Tue>'
date = PyOrgMode.OrgDate(datestr)
self.assertEqual(tuple(date.value), (2012, 7, 20, 0, 0, 0, 4, 202, -1))
self.assertEqual(tuple(date.end), (2012, 7, 31, 0, 0, 0, 1, 213, -1))
self.assertEqual(date.get_value(), datestr)
def test_daterangewithtimes(self):
"""
Tests parsing date ranges with times.
"""
datestr = '<2012-07-20 Fri 09:00>--<2012-07-31 Tue 14:00>'
date = PyOrgMode.OrgDate(datestr)
self.assertEqual(tuple(date.value), (2012, 7, 20, 9, 0, 0, 4, 202, -1))
self.assertEqual(tuple(date.end), (2012, 7, 31, 14, 0, 0, 1, 213, -1))
self.assertEqual(date.get_value(), datestr)
if __name__ == '__main__':
unittest.main()