Skip to content

Commit 0ddda7f

Browse files
author
Richard Jones
committed
stop Interval from displaying an empty string [SF#934022]
1 parent 790e80f commit 0ddda7f

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Fixed:
2929
- roundup scripts may now be asked for their version (sf rfe 798657)
3030
- sqlite backend had stopped using the global lock
3131
- better check for anonymous viewing of user items (sf bug 933510)
32+
- stop Interval from displaying an empty string (sf bug 934022)
3233

3334

3435
2004-03-27 0.7.0b2

roundup/date.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: date.py,v 1.65 2004-04-06 22:43:59 richard Exp $
18+
# $Id: date.py,v 1.66 2004-04-13 05:28:00 richard Exp $
1919

2020
"""Date, time and time interval handling.
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

2424
import time, re, calendar, types
25+
from types import *
2526
from i18n import _
2627

2728
def _add_granularity(src, order, value = 1):
@@ -433,7 +434,9 @@ class Interval:
433434
'''
434435
def __init__(self, spec, sign=1, allowdate=1, add_granularity=0):
435436
"""Construct an interval given a specification."""
436-
if type(spec) == type(''):
437+
if type(spec) in (IntType, FloatType, LongType):
438+
self.from_seconds(spec)
439+
elif type(spec) in (StringType, UnicodeType):
437440
self.set(spec, allowdate=allowdate, add_granularity=add_granularity)
438441
else:
439442
if len(spec) == 7:
@@ -533,6 +536,8 @@ def __str__(self):
533536
l.append('%d:%02d'%(self.hour, self.minute))
534537
if l:
535538
l.insert(0, {1:'+', -1:'-'}[self.sign])
539+
else:
540+
l.append('00:00')
536541
return ' '.join(l)
537542

538543
def __add__(self, other):
@@ -680,6 +685,42 @@ def serialise(self):
680685
return '%s%04d%02d%02d%02d%02d%02d'%(sign, self.year, self.month,
681686
self.day, self.hour, self.minute, self.second)
682687

688+
def as_seconds(self):
689+
'''Calculate the Interval as a number of seconds.
690+
691+
Months are counted as 30 days, years as 365 days. Returns a Long
692+
int.
693+
'''
694+
n = self.year * 365L
695+
n = n + self.month * 30
696+
n = n + self.day
697+
n = n * 24
698+
n = n + self.hour
699+
n = n * 60
700+
n = n + self.minute
701+
n = n * 60
702+
n = n + self.second
703+
return n * self.sign
704+
705+
def from_seconds(self, val):
706+
'''Figure my second, minute, hour and day values using a seconds
707+
value.
708+
'''
709+
if val < 0:
710+
self.sign = -1
711+
val = -val
712+
else:
713+
self.sign = 1
714+
self.second = val % 60
715+
val = val / 60
716+
self.minute = val % 60
717+
val = val / 60
718+
self.hour = val % 24
719+
val = val / 24
720+
self.day = val
721+
self.month = self.year = 0
722+
723+
683724
def fixTimeOverflow(time):
684725
""" Handle the overflow in the time portion (H, M, S) of "time":
685726
(sign, y,m,d,H,M,S)

0 commit comments

Comments
 (0)