[PYTHON DB-SIG] [comp.lang.python] Date-Time requirements (esp. for databases)

Anthony Baxter Anthony Baxter <arb@connect.com.au>
Thu, 31 Oct 1996 10:02:36 +1100


>>> Jim Fulton wrote
> Oops.  In my earlier note I agreed with this without reading it 
> carefully enough.  DateTime("1 week") doesn't make any sense to me.  
> DateTime objects refer to specific points in time, not time units.

Yep, so we need something else, instead...

> I think that DateTime objects should support addition/subtraction of
> numbers to/from date-time objects.  I think we should decide what units 
> are used for this.  IMO the units should be either days or seconds.
> I'd vote for days myself, but I could live with seconds.

I'd say that "DateTime(now) + 3" should be an error. Either specify the
units you're talking about, or lose to ambiguity. What's a reasonable
default for you is not going to be reasonable for the next person
along. And in this case, a settable default would make code yucky to
read.

> In addition, the DateTime class should have attributes that give the
> lengths of various units of time.  Perhaps these attributes should be:
> lengthOfYear(year), lengthOfMonth(year,month), lengthOfWeek,
> lengthOfDay, lengthOfHour, lengthOfMinute, lengthOfSecond.  So the above
> expression would become:
>   DateTime(now) + DateTime.lengthOfWeek

That's ok for addition and subtraction of an interval to a date, but
what should 'DateTime(now) - DateTime("03 Mar 1996 13:45:23")' return? The
only options I can see are:

  return an int, of some fixed type (seconds difference? what happens if 
  they want milliseconds?) 

  return some new type, which can be queried for seconds, hours, days, 
  whatever.

Anthony

=================
DB-SIG  - SIG on Tabular Databases in Python

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