Mercurial > p > roundup > code
comparison test/test_dates.py @ 1356:83f33642d220 maint-0.5
[[Metadata associated with this commit was garbled during conversion from CVS
to Subversion.]]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 09 Jan 2003 22:59:22 +0000 |
| parents | |
| children | f0da50a17e3c |
comparison
equal
deleted
inserted
replaced
| 1242:3d0158c8c32b | 1356:83f33642d220 |
|---|---|
| 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 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.15 2002-12-09 02:43:21 richard Exp $ | |
| 19 | |
| 20 import unittest, time | |
| 21 | |
| 22 from roundup.date import Date, Interval | |
| 23 | |
| 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') | |
| 33 | |
| 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("2000-4-7") | |
| 39 ae(str(date), '2000-04-07.00:00:00') | |
| 40 date = Date("2000-4-17") | |
| 41 ae(str(date), '2000-04-17.00:00:00') | |
| 42 date = Date("01-25") | |
| 43 y, m, d, x, x, x, x, x, x = time.gmtime(time.time()) | |
| 44 ae(str(date), '%s-01-25.00:00:00'%y) | |
| 45 date = Date("2000-04-17.03:45") | |
| 46 ae(str(date), '2000-04-17.03:45:00') | |
| 47 date = Date("08-13.22:13") | |
| 48 ae(str(date), '%s-08-13.22:13:00'%y) | |
| 49 date = Date("11-07.09:32:43") | |
| 50 ae(str(date), '%s-11-07.09:32:43'%y) | |
| 51 date = Date("14:25") | |
| 52 ae(str(date), '%s-%02d-%02d.14:25:00'%(y, m, d)) | |
| 53 date = Date("8:47:11") | |
| 54 ae(str(date), '%s-%02d-%02d.08:47:11'%(y, m, d)) | |
| 55 | |
| 56 def testOffset(self): | |
| 57 ae = self.assertEqual | |
| 58 date = Date("2000-04-17", -5) | |
| 59 ae(str(date), '2000-04-17.00:00:00') | |
| 60 date = Date("01-25", -5) | |
| 61 y, m, d, x, x, x, x, x, x = time.gmtime(time.time()) | |
| 62 ae(str(date), '%s-01-25.00:00:00'%y) | |
| 63 date = Date("2000-04-17.03:45", -5) | |
| 64 ae(str(date), '2000-04-17.08:45:00') | |
| 65 date = Date("08-13.22:13", -5) | |
| 66 ae(str(date), '%s-08-14.03:13:00'%y) | |
| 67 date = Date("11-07.09:32:43", -5) | |
| 68 ae(str(date), '%s-11-07.14:32:43'%y) | |
| 69 date = Date("14:25", -5) | |
| 70 ae(str(date), '%s-%02d-%02d.19:25:00'%(y, m, d)) | |
| 71 date = Date("8:47:11", -5) | |
| 72 ae(str(date), '%s-%02d-%02d.13:47:11'%(y, m, d)) | |
| 73 | |
| 74 # now check calculations | |
| 75 date = Date('2000-01-01') + Interval('- 2y 2m') | |
| 76 ae(str(date), '1997-11-01.00:00:00') | |
| 77 date = Date('2000-01-01 - 2y 2m') | |
| 78 ae(str(date), '1997-11-01.00:00:00') | |
| 79 date = Date('2000-01-01') + Interval('2m') | |
| 80 ae(str(date), '2000-03-01.00:00:00') | |
| 81 date = Date('2000-01-01 + 2m') | |
| 82 ae(str(date), '2000-03-01.00:00:00') | |
| 83 | |
| 84 date = Date('2000-01-01') + Interval('60d') | |
| 85 ae(str(date), '2000-03-01.00:00:00') | |
| 86 date = Date('2001-01-01') + Interval('60d') | |
| 87 ae(str(date), '2001-03-02.00:00:00') | |
| 88 | |
| 89 # time additions | |
| 90 date = Date('2000-02-28.23:59:59') + Interval('00:00:01') | |
| 91 ae(str(date), '2000-02-29.00:00:00') | |
| 92 date = Date('2001-02-28.23:59:59') + Interval('00:00:01') | |
| 93 ae(str(date), '2001-03-01.00:00:00') | |
| 94 | |
| 95 date = Date('2000-02-28.23:58:59') + Interval('00:01:01') | |
| 96 ae(str(date), '2000-02-29.00:00:00') | |
| 97 date = Date('2001-02-28.23:58:59') + Interval('00:01:01') | |
| 98 ae(str(date), '2001-03-01.00:00:00') | |
| 99 | |
| 100 date = Date('2000-02-28.22:58:59') + Interval('01:01:01') | |
| 101 ae(str(date), '2000-02-29.00:00:00') | |
| 102 date = Date('2001-02-28.22:58:59') + Interval('01:01:01') | |
| 103 ae(str(date), '2001-03-01.00:00:00') | |
| 104 | |
| 105 date = Date('2000-02-28.22:58:59') + Interval('00:00:3661') | |
| 106 ae(str(date), '2000-02-29.00:00:00') | |
| 107 date = Date('2001-02-28.22:58:59') + Interval('00:00:3661') | |
| 108 ae(str(date), '2001-03-01.00:00:00') | |
| 109 | |
| 110 # now subtractions | |
| 111 date = Date('2000-01-01') - Interval('- 2y 2m') | |
| 112 ae(str(date), '2002-03-01.00:00:00') | |
| 113 date = Date('2000-01-01') - Interval('2m') | |
| 114 ae(str(date), '1999-11-01.00:00:00') | |
| 115 | |
| 116 date = Date('2000-03-01') - Interval('60d') | |
| 117 ae(str(date), '2000-01-01.00:00:00') | |
| 118 date = Date('2001-03-02') - Interval('60d') | |
| 119 ae(str(date), '2001-01-01.00:00:00') | |
| 120 | |
| 121 date = Date('2000-02-29.00:00:00') - Interval('00:00:01') | |
| 122 ae(str(date), '2000-02-28.23:59:59') | |
| 123 date = Date('2001-03-01.00:00:00') - Interval('00:00:01') | |
| 124 ae(str(date), '2001-02-28.23:59:59') | |
| 125 | |
| 126 date = Date('2000-02-29.00:00:00') - Interval('00:01:01') | |
| 127 ae(str(date), '2000-02-28.23:58:59') | |
| 128 date = Date('2001-03-01.00:00:00') - Interval('00:01:01') | |
| 129 ae(str(date), '2001-02-28.23:58:59') | |
| 130 | |
| 131 date = Date('2000-02-29.00:00:00') - Interval('01:01:01') | |
| 132 ae(str(date), '2000-02-28.22:58:59') | |
| 133 date = Date('2001-03-01.00:00:00') - Interval('01:01:01') | |
| 134 ae(str(date), '2001-02-28.22:58:59') | |
| 135 | |
| 136 date = Date('2000-02-29.00:00:00') - Interval('00:00:3661') | |
| 137 ae(str(date), '2000-02-28.22:58:59') | |
| 138 date = Date('2001-03-01.00:00:00') - Interval('00:00:3661') | |
| 139 ae(str(date), '2001-02-28.22:58:59') | |
| 140 | |
| 141 # local() | |
| 142 date = Date("02:42:20") | |
| 143 date = date.local(10) | |
| 144 ae(str(date), '%s-%02d-%02d.12:42:20'%(y, m, d)) | |
| 145 | |
| 146 def testInterval(self): | |
| 147 ae = self.assertEqual | |
| 148 ae(str(Interval('3y')), '+ 3y') | |
| 149 ae(str(Interval('2 y 1 m')), '+ 2y 1m') | |
| 150 ae(str(Interval('1m 25d')), '+ 1m 25d') | |
| 151 ae(str(Interval('-2w 3 d ')), '- 17d') | |
| 152 ae(str(Interval(' - 1 d 2:50 ')), '- 1d 2:50') | |
| 153 ae(str(Interval(' 14:00 ')), '+ 14:00') | |
| 154 ae(str(Interval(' 0:04:33 ')), '+ 0:04:33') | |
| 155 | |
| 156 # __add__ | |
| 157 # XXX these are fairly arbitrary and need fixing once the __add__ | |
| 158 # code handles the odd cases more correctly | |
| 159 ae(str(Interval('1y') + Interval('1y')), '+ 2y') | |
| 160 ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m') | |
| 161 ae(str(Interval('1y') + Interval('2:40')), '+ 1y 2:40') | |
| 162 ae(str(Interval('1y') + Interval('- 1y')), '+') | |
| 163 ae(str(Interval('1y') + Interval('- 1m')), '+ 1y -1m') | |
| 164 | |
| 165 def suite(): | |
| 166 return unittest.makeSuite(DateTestCase, 'test') | |
| 167 | |
| 168 | |
| 169 # vim: set filetype=python ts=4 sw=4 et si |
