[go: up one dir, main page]

Menu

[82a575]: / test / test_dates.py  Maximize  Restore  History

Download this file

110 lines (100 with data), 3.9 kB

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