Skip to content

Commit 7cdecd5

Browse files
author
Richard Jones
committed
fixed the date module so that Date(". - 2d") works
1 parent c8ee937 commit 7cdecd5

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

roundup/admin.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.16 2002-07-09 04:19:09 richard Exp $
19+
# $Id: admin.py,v 1.17 2002-07-14 06:05:50 richard Exp $
2020

2121
import sys, os, getpass, getopt, re, UserDict, shlex, shutil
2222
try:
@@ -956,9 +956,7 @@ def do_pack(self, args):
956956
raise ValueError, _('Invalid format')
957957
m = m.groupdict()
958958
if m['period']:
959-
# TODO: need to fix date module. one should be able to say
960-
# pack_before = date.Date(". - %s"%value)
961-
pack_before = date.Date(".") + date.Interval("- %s"%value)
959+
pack_before = date.Date(". - %s"%value)
962960
elif m['date']:
963961
pack_before = date.Date(value)
964962
self.db.pack(pack_before)
@@ -1125,6 +1123,11 @@ def main(self):
11251123

11261124
#
11271125
# $Log: not supported by cvs2svn $
1126+
# Revision 1.16 2002/07/09 04:19:09 richard
1127+
# Added reindex command to roundup-admin.
1128+
# Fixed reindex on first access.
1129+
# Also fixed reindexing of entries that change.
1130+
#
11281131
# Revision 1.15 2002/06/17 23:14:44 richard
11291132
# . #569415 ] {version}
11301133
#

roundup/date.py

Lines changed: 24 additions & 23 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.21 2002-05-15 06:32:46 richard Exp $
18+
# $Id: date.py,v 1.22 2002-07-14 06:05:50 richard Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -91,29 +91,17 @@ def __init__(self, spec='.', offset=0):
9191
self.year, self.month, self.day, self.hour, self.minute, \
9292
self.second, x, x, x = time.gmtime(ts)
9393

94-
def applyInterval(self, interval):
95-
''' Apply the interval to this date
94+
def addInterval(self, interval):
95+
''' Add the interval to this date, returning the date tuple
9696
'''
97-
t = (self.year + interval.year,
98-
self.month + interval.month,
99-
self.day + interval.day,
100-
self.hour + interval.hour,
101-
self.minute + interval.minute,
102-
self.second + interval.second, 0, 0, 0)
103-
self.year, self.month, self.day, self.hour, self.minute, \
104-
self.second, x, x, x = time.gmtime(calendar.timegm(t))
105-
106-
def __add__(self, other):
107-
"""Add an interval to this date to produce another date.
108-
"""
10997
# do the basic calc
110-
sign = other.sign
111-
year = self.year + sign * other.year
112-
month = self.month + sign * other.month
113-
day = self.day + sign * other.day
114-
hour = self.hour + sign * other.hour
115-
minute = self.minute + sign * other.minute
116-
second = self.second + sign * other.second
98+
sign = interval.sign
99+
year = self.year + sign * interval.year
100+
month = self.month + sign * interval.month
101+
day = self.day + sign * interval.day
102+
hour = self.hour + sign * interval.hour
103+
minute = self.minute + sign * interval.minute
104+
second = self.second + sign * interval.second
117105

118106
# now cope with under- and over-flow
119107
# first do the time
@@ -148,8 +136,18 @@ def __add__(self, other):
148136
# re-figure the number of days for this month
149137
if month == 2 and calendar.isleap(year): month_days = 29
150138
else: month_days = mdays[month]
139+
return (year, month, day, hour, minute, second, 0, 0, 0)
151140

152-
return Date((year, month, day, hour, minute, second, 0, 0, 0))
141+
def applyInterval(self, interval):
142+
''' Apply the interval to this date
143+
'''
144+
self.year, self.month, self.day, self.hour, self.minute, \
145+
self.second, x, x, x = self.addInterval(interval)
146+
147+
def __add__(self, interval):
148+
"""Add an interval to this date to produce another date.
149+
"""
150+
return Date(self.addInterval(interval))
153151

154152
# XXX deviates from spec to allow subtraction of dates as well
155153
def __sub__(self, other):
@@ -440,6 +438,9 @@ def test():
440438

441439
#
442440
# $Log: not supported by cvs2svn $
441+
# Revision 1.21 2002/05/15 06:32:46 richard
442+
# . reverting to dates for intervals > 2 months sucks
443+
#
443444
# Revision 1.20 2002/02/21 23:34:51 richard
444445
# Oops, there's 24 hours in a day, and subtraction of intervals now works
445446
# properly.

test/test_dates.py

Lines changed: 9 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: test_dates.py,v 1.11 2002-02-21 23:34:52 richard Exp $
18+
# $Id: test_dates.py,v 1.12 2002-07-14 06:05:50 richard Exp $
1919

2020
import unittest, time
2121

@@ -74,8 +74,12 @@ def testOffset(self):
7474
# now check calculations
7575
date = Date('2000-01-01') + Interval('- 2y 2m')
7676
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')
7779
date = Date('2000-01-01') + Interval('2m')
7880
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')
7983

8084
date = Date('2000-01-01') + Interval('60d')
8185
ae(str(date), '2000-03-01.00:00:00')
@@ -150,6 +154,10 @@ def suite():
150154

151155
#
152156
# $Log: not supported by cvs2svn $
157+
# Revision 1.11 2002/02/21 23:34:52 richard
158+
# Oops, there's 24 hours in a day, and subtraction of intervals now works
159+
# properly.
160+
#
153161
# Revision 1.10 2002/02/21 23:11:45 richard
154162
# . fixed some problems in date calculations (calendar.py doesn't handle over-
155163
# and under-flow). Also, hour/minute/second intervals may now be more than

0 commit comments

Comments
 (0)