Why datetime module is so complicated?

Z

Zeynel

It's about a week now I've been trying to convert a datetime object to
seconds since epoch; the object is set to current time by class Rep()
in Google App Engine:

class Rep(db.Model):
...
mCOUNT = db.IntegerProperty()
mDATE0 = db.DateTimeProperty(auto_now_add=True)
mWEIGHT = db.FloatProperty()

I want to divide mDATE0 by the integer mCOUNT. I asked the same
question here previously and also at stackoverflow. So far, I still
cannot make it work. I would greatly appreciate if someone who is an
expert in datetime operation in Python could help me understand this
issue. Thank you.

Latest question in Stackoverlow with link to my original question
there: http://stackoverflow.com/questions/4178125/datetime-and-utctimetuple

Previous discussions at comp.lang.python:

http://groups.google.com/group/comp...67869/28c7c7b8d48f3805?hl=en#28c7c7b8d48f3805

http://groups.google.com/group/comp...08450/fd9b42e0c403380e?hl=en#fd9b42e0c403380e
 
D

Diez B. Roggisch

Zeynel said:
It's about a week now I've been trying to convert a datetime object to
seconds since epoch; the object is set to current time by class Rep()
in Google App Engine:

class Rep(db.Model):
...
mCOUNT = db.IntegerProperty()
mDATE0 = db.DateTimeProperty(auto_now_add=True)
mWEIGHT = db.FloatProperty()

I want to divide mDATE0 by the integer mCOUNT. I asked the same
question here previously and also at stackoverflow. So far, I still
cannot make it work. I would greatly appreciate if someone who is an
expert in datetime operation in Python could help me understand this
issue. Thank you.
from datetime import *
d = datetime.now()
dir(d) ['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__str__', '__sub__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']
d.time() datetime.time(17, 50, 54, 778159)
d.ctime() 'Sun Nov 14 17:50:54 2010'
d.time
d.timetuple() (2010, 11, 14, 17, 50, 54, 6, 318, -1)
import time
dir(time) ['__doc__', '__file__', '__name__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname', 'tzset']
help(time.mktime)
time.mktime(d.timetuple()) 1289753454.0

Not that hard.

Diez
 
V

Vlastimil Brom

2010/11/14 Zeynel said:
It's about a week now I've been trying to convert a datetime object to
seconds since epoch; the object is set to current time by class Rep()
in Google App Engine:

class Rep(db.Model):
   ...
   mCOUNT = db.IntegerProperty()
   mDATE0 = db.DateTimeProperty(auto_now_add=True)
   mWEIGHT = db.FloatProperty()

I want to divide mDATE0 by the integer mCOUNT. I asked the same
question here previously and also at stackoverflow. So far, I still
cannot make it work. I would greatly appreciate if someone who is an
expert in datetime operation in Python could help me understand this
issue. Thank you.

Latest question in Stackoverlow with link to my original question
there: http://stackoverflow.com/questions/4178125/datetime-and-utctimetuple

Previous discussions at comp.lang.python:

http://groups.google.com/group/comp...67869/28c7c7b8d48f3805?hl=en#28c7c7b8d48f3805

http://groups.google.com/group/comp...08450/fd9b42e0c403380e?hl=en#fd9b42e0c403380e

Hi,
just a try, as it is not completely clear to me, what you are trying
to achieve, as I don't have experiences with the mentioned framework.
It seems to me, that you can only reasonably divide timedeltas, not
the absolute timestamps, it might be something like the following:

hth,
vbr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top