Skip to content

Commit 58cb2fe

Browse files
author
Richard Jones
committed
New tests for range searching by specifying just a month.
Currently some of them fail. _add_granularity is broken - needs tests and complete fix.
1 parent bcc7090 commit 58cb2fe

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

roundup/date.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: date.py,v 1.92 2007-03-14 15:07:24 schlatterbeck Exp $
18+
# $Id: date.py,v 1.93 2007-12-21 11:21:08 richard Exp $
1919

2020
"""Date, time and time interval handling.
2121
"""
@@ -33,13 +33,18 @@
3333

3434
from roundup import i18n
3535

36-
def _add_granularity(src, order, value = 1):
36+
def _add_granularity(src, order, value=1):
3737
'''Increment first non-None value in src dictionary ordered by 'order'
3838
parameter
3939
'''
4040
for gran in order:
4141
if src[gran]:
4242
src[gran] = int(src[gran]) + value
43+
# XXX test and handle other cases
44+
if gran == 'm' and src['m'] > 12:
45+
y, m = divmod(src['m'], 12)
46+
src['m'] = m
47+
src['y'] = int(src['y']) + y
4348
break
4449

4550
# no, I don't know why we must anchor the date RE when we only ever use it

test/db_test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.93 2007-12-20 01:01:49 richard Exp $
18+
# $Id: db_test_base.py,v 1.94 2007-12-21 11:21:08 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint, sets, base64, os.path
2121

@@ -1184,6 +1184,7 @@ def testFilteringRangeTwoSyntaxes(self):
11841184
ae(filt(None, {'deadline': '2003-02-16;'}), ['1', '3', '4'])
11851185

11861186
def testFilteringRangeYearMonthDay(self):
1187+
ae, filt = self.filteringSetup()
11871188
ae(filt(None, {'deadline': '2002'}), [])
11881189
ae(filt(None, {'deadline': '2003'}), ['1', '2', '3'])
11891190
ae(filt(None, {'deadline': '2004'}), ['4'])

test/test_dates.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,29 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_dates.py,v 1.42 2007-12-20 01:01:49 richard Exp $
18+
# $Id: test_dates.py,v 1.43 2007-12-21 11:21:09 richard Exp $
1919
from __future__ import nested_scopes
2020

2121
import unittest
2222
import time
2323
import datetime
24+
import calendar
25+
26+
from roundup.date import Date, Interval, Range, fixTimeOverflow, \
27+
get_timezone, _add_granularity
2428

25-
from roundup.date import Date, Interval, Range, fixTimeOverflow, get_timezone
2629

2730
class DateTestCase(unittest.TestCase):
31+
def testAddGranularity(self):
32+
def d(m=None, d=None, H=None, M=None, S=None, value=1):
33+
d = dict(y='2006', m=m, d=d, H=H, M=M, S=S)
34+
_add_granularity(d, 'SMHdmy', value)
35+
return d
36+
ae = self.assertEqual
37+
ae(d(), dict(y=2007, m=None, d=None, H=None, M=None, S=None))
38+
ae(d(m='1'), dict(y='2006', m=2, d=None, H=None, M=None, S=None))
39+
ae(d(m='12'), dict(y=2007, m=1, d=None, H=None, M=None, S=None))
40+
2841
def testDateInterval(self):
2942
ae = self.assertEqual
3043
date = Date("2000-06-26.00:34:02 + 2d")
@@ -472,13 +485,11 @@ def testRange(self):
472485
r = Range('2006', Date)
473486
ae(str(r.from_value), '2006-01-01.00:00:00')
474487
ae(str(r.to_value), '2006-12-31.23:59:59')
475-
# XXX this is probably in the calendar module
476-
days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
477488
for i in range(1, 13):
478-
print i
479489
r = Range('2006-%02d'%i, Date)
480490
ae(str(r.from_value), '2006-%02d-01.00:00:00'%i)
481-
ae(str(r.to_value), '2006-%02d-%02d.23:59:59'%(i, days[i-1]))
491+
ae(str(r.to_value), '2006-%02d-%02d.23:59:59'%(i,
492+
calendar.mdays[i]))
482493

483494

484495
def test_suite():

0 commit comments

Comments
 (0)