[Tutor] Shifts and DateTime problems

mikalzet@libero.it mikalzet@libero.it
Wed, 6 Feb 2002 23:17:44 +0100 (CET)

All right, so I keep on toying around with my idea on a program for
managing complex shifting schedules.
I have a small example postgres database (5 lines); 4 columns:
the workers name (char), hour at which shift begins (timestamp), hour at
which it ends (timestamp) {...actually I suspect I might as well use just
one column of DateTime interval type, because postgres operators are
available for extracting the beginning and end of an interval....}
and type of shift (text).

If I run this code everything works ok:

import pgdb
db = pgdb.connect(database = 'exampledatabase')
cursor = db.cursor()
cursor.execute('select time("Begin") from shift where
"Type" = \'Automedica\' ;')              # backslashes needed to protect '

I get what I want ... but this is a string I believe, not a DateTime
variable or even an int. I would like to obtain the time as an mx.DateTime
variable which could be passed on to my Shift class.

How do I do that ?

If I do something like:

b = DateTimeFrom(cursor.fetchone())
( with an aim to calling Shift(begin=b) in future )

python sneers at me:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.1/site-packages/mx/DateTime/DateTime.py", line
228, in
    value = int(arg)
TypeError: object can't be converted to int

(My problem is going to be how to extract all the values to be fed to
Shift() from my database ... but let's go one step at a time ...  Shift()
is also going to undergo profound changes no doubt .... in fact, if instead
of using begin and end in the database I used an interval it would make sense
to use one in Shift() too...)

Do I have to specify in the class init method that the variables are of
DateTime type ?

If anyone cares here's what I had written for class Shift():

class Shift:

    def __init__(self, name="None", worker="None", begin="None",
        self.name = name
        self.worker = worker
        self.begin = begin
        self.end = end

    def __str__(self):
        return str(self.name) + "\n" + str(self.worker)  + "\n" +
str(self.begin) + str(self.end)

Any hints wwelcome !!

Michele Alzetta