diff --git a/roundup/date.py b/roundup/date.py
index d6feb4f260e66b3c92805af2918275064fa6d09c..ef65d87f86fb7c1c099777fc8910f11f13094d26 100644 (file)
--- a/roundup/date.py
+++ b/roundup/date.py
-# $Id: date.py,v 1.4 2001-07-25 04:09:34 richard Exp $
+#
+# 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: date.py,v 1.13 2001-09-18 22:58:37 richard Exp $
import time, re, calendar
>>> Date("14:25", -5)
<Date 2000-06-25.19:25:00>
'''
- isDate = 1
-
def __init__(self, spec='.', offset=0):
"""Construct a date given a specification and a time zone offset.
1. an interval from this date to produce another date.
2. a date from this date to produce an interval.
"""
- if other.isDate:
+ if isinstance(other, Date):
# TODO this code will fall over laughing if the dates cross
# leap years, phases of the moon, ....
a = calendar.timegm((self.year, self.month, self.day, self.hour,
def __str__(self):
"""Return this date as a string in the yyyy-mm-dd.hh:mm:ss format."""
- return time.strftime('%Y-%m-%d.%T', (self.year, self.month, self.day,
- self.hour, self.minute, self.second, 0, 0, 0))
+ return '%4d-%02d-%02d.%02d:%02d:%02d'%(self.year, self.month, self.day,
+ self.hour, self.minute, self.second)
def pretty(self):
''' print up the date date using a pretty format...
info = m.groupdict()
# get the current date/time using the offset
- y,m,d,H,M,S,x,x,x = time.gmtime()
+ y,m,d,H,M,S,x,x,x = time.gmtime(time.time())
# override year, month, day parts
if info['m'] is not None and info['d'] is not None:
>>> Date(". + 2d") - Interval("3w")
<Date 2000-06-07.00:34:02>
'''
- isInterval = 1
-
def __init__(self, spec, sign=1):
"""Construct an interval given a specification."""
if type(spec) == type(''):
< 1 day
otherwise, return None (so a full date may be displayed)
'''
- if self.year or self.month or self.day > 5:
+ if self.year or self.month > 2:
return None
+ if self.month or self.day > 13:
+ days = (self.month * 30) + self.day
+ if days > 28:
+ if int(days/30) > 1:
+ return '%s months'%int(days/30)
+ else:
+ return '1 month'
+ else:
+ return '%s weeks'%int(days/7)
+ if self.day > 7:
+ return '1 week'
if self.day > 1:
return '%s days'%self.day
if self.day == 1 or self.hour > 12:
return '1 minute'
if self.minute < 15:
return '%s minutes'%self.minute
- quart = self.minute/15
+ quart = int(self.minute/15)
if quart == 2:
return '1/2 an hour'
return '%s/4 hour'%quart
#
# $Log: not supported by cvs2svn $
+# Revision 1.12 2001/08/17 03:08:11 richard
+# fixed prettification of intervals of 1 week
+#
+# Revision 1.11 2001/08/15 23:43:18 richard
+# Fixed some isFooTypes that I missed.
+# Refactored some code in the CGI code.
+#
+# Revision 1.10 2001/08/07 00:24:42 richard
+# stupid typo
+#
+# Revision 1.9 2001/08/07 00:15:51 richard
+# Added the copyright/license notice to (nearly) all files at request of
+# Bizar Software.
+#
+# Revision 1.8 2001/08/05 07:46:12 richard
+# Changed date.Date to use regular string formatting instead of strftime -
+# win32 seems to have problems with %T and no hour... or something...
+#
+# Revision 1.7 2001/08/02 00:27:04 richard
+# Extended the range of intervals that are pretty-printed before actual dates
+# are displayed.
+#
+# Revision 1.6 2001/07/31 09:54:18 richard
+# Fixed the 2.1-specific gmtime() (no arg) call in roundup.date. (Paul Wright)
+#
+# Revision 1.5 2001/07/29 07:01:39 richard
+# Added vim command to all source so that we don't get no steenkin' tabs :)
+#
+# Revision 1.4 2001/07/25 04:09:34 richard
+# Fixed offset handling (shoulda read the spec a little better)
+#
# Revision 1.3 2001/07/23 07:56:05 richard
# Storing only marshallable data in the db - no nasty pickled class references.
#
# Revision 1.1 2001/07/22 11:58:35 richard
# More Grande Splite
#
+#
+# vim: set filetype=python ts=4 sw=4 et si