c5df1d057fd02c9ded35122931a040fdd0b0a48b
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL THE BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 #
18 # $Id: test_dates.py,v 1.5 2001-08-07 00:15:51 richard Exp $
20 import unittest, time
22 from roundup.date import Date, Interval
24 class DateTestCase(unittest.TestCase):
25 def testDateInterval(self):
26 ae = self.assertEqual
27 date = Date("2000-06-26.00:34:02 + 2d")
28 ae(str(date), '2000-06-28.00:34:02')
29 date = Date("2000-02-27 + 2d")
30 ae(str(date), '2000-02-29.00:00:00')
31 date = Date("2001-02-27 + 2d")
32 ae(str(date), '2001-03-01.00:00:00')
34 def testDate(self):
35 ae = self.assertEqual
36 date = Date("2000-04-17")
37 ae(str(date), '2000-04-17.00:00:00')
38 date = Date("01-25")
39 y, m, d, x, x, x, x, x, x = time.gmtime()
40 ae(str(date), '%s-01-25.00:00:00'%y)
41 date = Date("2000-04-17.03:45")
42 ae(str(date), '2000-04-17.03:45:00')
43 date = Date("08-13.22:13")
44 ae(str(date), '%s-08-13.22:13:00'%y)
45 date = Date("11-07.09:32:43")
46 ae(str(date), '%s-11-07.09:32:43'%y)
47 date = Date("14:25")
48 ae(str(date), '%s-%02d-%02d.14:25:00'%(y, m, d))
49 date = Date("8:47:11")
50 ae(str(date), '%s-%02d-%02d.08:47:11'%(y, m, d))
52 def testOffset(self):
53 ae = self.assertEqual
54 date = Date("2000-04-17", -5)
55 ae(str(date), '2000-04-17.00:00:00')
56 date = Date("01-25", -5)
57 y, m, d, x, x, x, x, x, x = time.gmtime()
58 ae(str(date), '%s-01-25.00:00:00'%y)
59 date = Date("2000-04-17.03:45", -5)
60 ae(str(date), '2000-04-17.08:45:00')
61 date = Date("08-13.22:13", -5)
62 ae(str(date), '%s-08-14.03:13:00'%y)
63 date = Date("11-07.09:32:43", -5)
64 ae(str(date), '%s-11-07.14:32:43'%y)
65 date = Date("14:25", -5)
66 ae(str(date), '%s-%02d-%02d.19:25:00'%(y, m, d))
67 date = Date("8:47:11", -5)
68 ae(str(date), '%s-%02d-%02d.13:47:11'%(y, m, d))
70 def testInterval(self):
71 ae = self.assertEqual
72 ae(str(Interval('3y')), '+ 3y')
73 ae(str(Interval('2 y 1 m')), '+ 2y 1m')
74 ae(str(Interval('1m 25d')), '+ 1m 25d')
75 ae(str(Interval('-2w 3 d ')), '- 17d')
76 ae(str(Interval(' - 1 d 2:50 ')), '- 1d 2:50')
77 ae(str(Interval(' 14:00 ')), '+ 14:00')
78 ae(str(Interval(' 0:04:33 ')), '+ 0:04:33')
80 def suite():
81 return unittest.makeSuite(DateTestCase, 'test')
84 #
85 # $Log: not supported by cvs2svn $
86 # Revision 1.4 2001/07/29 23:32:13 richard
87 # Fixed bug in unit test ;)
88 #
89 # Revision 1.3 2001/07/29 07:01:39 richard
90 # Added vim command to all source so that we don't get no steenkin' tabs :)
91 #
92 # Revision 1.2 2001/07/29 06:42:20 richard
93 # Added Interval tests.
94 #
95 # Revision 1.1 2001/07/27 06:55:07 richard
96 # moving tests -> test
97 #
98 # Revision 1.2 2001/07/25 04:34:31 richard
99 # Added id and log to tests files...
100 #
101 #
102 # vim: set filetype=python ts=4 sw=4 et si