Roundup Tracker - Issues

Message569

Author anonymous
Recipients
Date 2003-01-09.22:32:15
Message-id
In-reply-to
I am working on reporting function for roundup.
Interval math 
and printing seems a bit off and
is really making things 
difficult.

I will show the problems, and describe how I 
would
like it to work.

If I create an interval of 1 hour and 45 
minutes and
add it to another interval of 1 hour and 45 
minutes,
I get an interval of 2 hours and 90 minutes. This 
is
incorrect. It should be 3 hours and thirty minutes.
This is 
with roundup 0.5.3. Here is the test code:

from roundup 
import instance, 
date
a=date.Interval("1:45")
b=date.Interval("1:45")
c 
= a + b
print a
print b
print c

I get:

+ 
1:45
+ 1:45
+ 2:90

If I change the interval to 1d 20:10 I 
get:

>>> a=date.Interval("1d 20:10")
>>> 
b=date.Interval("1d 20:10")
>>> c=a+b
>>> print c
+ 
2d 40:20

it should be 3d 16:20.

Also addition of a 
negative interval doesn't work well
either.
>>> 
a=date.Interval("-1d 20:10")
>>> print a
- 1d 20:10
>>> 
print b
+ 1d 20:10
>>> print a + b
+ 2d 40:20
>>> print 
b + a
+

b+a = a+b and both should report 
00:00:00.

Also adding two negative intervals is an 
issue:

>>> print a; print b; print a+b
- 1d 20:10
- 1d 
20:10
+
Should be -3d 16:20.

Subtraction 
(multiplication and division) of intervals 
isn't
supported:
>>> a=date.Interval("1d 20:10")
>>> 
b=date.Interval("1d 20:10")
>>> print a-b
Traceback (most 
recent call last):
  File "<stdin>", line 1, in ?
TypeError: 
unsupported operand type(s) for -: 'instance'
and 
'instance'

print a/5
Traceback (most recent call 
last):
  File "<stdin>", line 1, in ?
TypeError: unsupported 
operand type(s) for /: 'instance' and 'int'

For summary 
reports (average intervals) division is
required.

Also the 
string form of intervals isn't constistent in form.

>>> 
b=date.Interval("00:00"); print b
+

should print '+ 
00:00:00'.

I claim that all intervals should be presented 
as
     (+|-) [y] [d] hh:mm:ss
Where the number of days and 
years (365d 6h/ year)
are shown only if they are not 
zero.

I suggest that hours, minutes and seconds always 
be
shown because their interpretation is not based on 
a
label (y or d) but on position so there is an ambiguity
in 
displaying an interval like: 10:20
Is that
   00:10:20
or
   
10:20:00

By displaying all three entities, the ambiguity 
is
resolved for the viewer. Also it makes manipulation
of the 
interval easier. If the programmer wishes to
remove the number 
of seconds from an interval, it can
easily be done by removing 
the last three characters.
Currently, you have to determine if 
the interval has any
seconds and remove them if 
present.

Some alternate function may be provided to 
print
intervals that use weeks. The default code should 
be
able to handle week intervals (being equivalent to 
7
days/week).

Months should not be created unless 
the original
interval incldues months. Months should be rolled 
into
years at a rate of 12 months/year. Days should not 
be
rolled into months unless the user defines the 
ratio
between days and months. E.G.

   date.Interval('1y 
2m 3d 4:50:10", 30.44)

would result in 30.44 days/month. 
Or

  date.ConvertInterval("1y 45d 4:10", 30.44)

as 
an alternate way of dealing with it.

One way to handle most 
of this is to convert intervals
to  integer seconds and use regular 
integer arithmetic on them and the convert back to component 
form.

-- rouilj

History
Date User Action Args
2009-02-03 14:20:11adminlinkissue665357 messages
2009-02-03 14:20:11admincreate