On Nov 28, 3:19 pm, JDT <[email protected]> wrote:
> Hello All,
>
> I have an application where I need store the difference in time
> between two events. Unfortunately the datastore only supports storing
> 'time' as a datetime.datetime object.
>
> In an attempt to circumvent this constraint, I am adding the interval
> to the smallest possible datetime.datetime object and saving to the
> datastore, then doing the reverse when recalling the interval.
>
> Before I implement this I though I would check to see that I wasn't
> reinventing the wheel.
>
> Does anyone know if there a better way to do this?
> Will datetime.min will ever change?
> I am stupidly creating a CPU intensive process?
>
> All comments/suggestions most appreciated.
>
> Thanks,
>
> David
>
> For example:
>
> Model:
> class Item(db.Model):
>         interval = db.DateTimeProperty()
>
> To save the interval :
> days = int(self.request.get("days"))
> hours = int(self.request.get("hours"))
> minutes = int(self.request.get("minutes")
> Item = db.Item()
>
> delay = timedelta(days = days, hours = hours, minutes = minutes)
> Item.interval = datetime.min +  delay
> Item.put()
>
> To recall the interval:
> Item = db.Item.get(key)
> delay = Item.interval - datetime.min


You could create your own IntervalProperty, which would store the
interval as integer seconds and convert to a python timedelta when you
access it:

    
http://googleappengine.blogspot.com/2009/07/writing-custom-property-classes.html

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.


Reply via email to