[DB-SIG] Re: ANN: DateTime type, version 0.1

M.-A. Lemburg lemburg@uni-duesseldorf.de
Sat, 13 Dec 1997 22:40:05 +0100


Some questions regarding further developements:

1. I'd like to make the DateTime instances pickleable. Unfortunately
the pickle mechanism doesn't include a default method for unknown
objects. This means we have to provide ur own pickling routines.
A generic method in pickle/cPickle wouldn't be a bad idea either,
since all that is needed are ways to deduct the name of the module
where the instance's constructor can be found and the constructor's
name, ie. if an object provides __module__ and __name__ plus optionally
the pickle methods __getinitargs__, __getstate__, __setstate__,
there should be no problem having a standard mechanism much like
save_inst do the job without having to provide explicit pickle/unpickle
routines.

2. Though not needed for DB interfacing, it would be nice to have
a way to express deltas in time (e.g. +2 months, -3 seconds, etc.).
These objects will hold relative data, so calculating a specific
fixed number of seconds/days as internal basis is not possible,
because e.g. a month can have 28,29,30 or 31 days. Example:

t1 = maketime(1997,12,12)
t2 = maketime(1998,2,1)
d = DateTimeDelta(month=+2)

Possible keywords for the constructor:
 relative:
  year,month,day,hour,minute,second - add values to resp. fields
 absolute difference:
  absdate - add value to absdate, fractions are added to abstime
  abstime - add value to abstime, overflow is added to absdate

(The two categories mutually exclude each other, e.g. if you use
 month=+2,day=+2 you can't use absdate=+30)

t1 + d will point to 1998,2,12
t2 + d will point to 1998,4,1

Questions:
- What is the outcome of maketime(1997,12,31) + d ? Since february
  doesn't have 31 days the new date is not well defined. I guess
  an exception should be raised to indicate this.
- What should t2 - t1 result in ? There are two options:
  a) it returns a relative result like DateTimeDelta(year=+1,month=-10,
     day=-11)
  b) it returns an absolute difference, DateTimeDelta(absdate=+51)
  I think arithmetic should always use option b). Option a) could
  be returned by a special reldifftime() function.
- Is there a need for addition of deltas ? 
- Would having seperate types for the two flavors (relative and
  absolute) be a better approach. [actually while writing this, I
  tend to think so].

-- 
Marc-Andre Lemburg


_______________
DB-SIG  - SIG on Tabular Databases in Python

send messages to: db-sig@python.org
administrivia to: db-sig-request@python.org
_______________