Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError datetime #68

Closed
jdearl opened this issue Apr 4, 2012 · 10 comments
Closed

ValueError datetime #68

jdearl opened this issue Apr 4, 2012 · 10 comments

Comments

@jdearl
Copy link

jdearl commented Apr 4, 2012

I have an SQLite database which has a DateTimeField() with a few different datetime formats (not on purpose). I will probably fix my datetime values, but I thought I'd post this in case you feel peewee should handle this gracefully?

2011-11-15 21:53:59.759451+0000
2011-11-28 20:12:03
2009-01-01 (error)

http://paste.pocoo.org/show/aH7tITRfn9mhczxgWq3u/

Thanks for Peewee (and Flask-Peewee)!

@coleifer
Copy link
Owner

coleifer commented Apr 4, 2012

I think the first 2 should probably work as expected with the existing DateTimeField, but the last should probably be given its own "DateField" a-la django (and maybe a TimeField as well for times). Thanks for reporting

@jdearl
Copy link
Author

jdearl commented Apr 4, 2012

Is it possible to cast them to a DateTime with 0's? That's sorta what I'd expect to happen. I'm coming from Ruby, and Sequel or the Ruby SQLite adapter appears to do be doing this.

I also added that the field is defined as a peewee DateTimeField().

@coleifer
Copy link
Owner

coleifer commented Apr 4, 2012

Totally, if the DateTimeField encounters something like example 3 it should zero out the times.

@jdearl
Copy link
Author

jdearl commented Apr 4, 2012

Great!

@jdearl
Copy link
Author

jdearl commented Apr 6, 2012

Thanks for fixing :)

@bwghughes
Copy link

Would be really good if we could pass in the format string into the field constructor. I have dates in a sqlite db of '9 January 2009' so I'd like to pass the format in:

transaction_date = DateField(format='%d %B %Y')

I'll fork and suggest something....

@coleifer
Copy link
Owner

Thanks for suggesting this fix, I've added it here:

@coleifer
Copy link
Owner

here's the commit: 0d9708a

the way it works is you can pass in "formats" kwarg in the field constructor containing a list of various formats to try.

@bwghughes
Copy link

Legend Charles - you beat me to it :)

Love Peewee btw - its my ORM of choice. In fact I don't choose any
other these days - solid.

Thanks for the rapid help.

Ben

On Mon, May 14, 2012 at 5:30 PM, Charles Leifer
reply@reply.github.com
wrote:

here's the commit: 0d9708a

the way it works is you can pass in "formats" kwarg in the field constructor containing a list of various formats to try.


Reply to this email directly or view it on GitHub:
#68 (comment)

Ben Hughes
Change & Innovation Lead
Bright Approach Ltd.
Tel: +447427600266
Twitter: @bwghughes
http://about.me/bwghughes

@coleifer
Copy link
Owner

No problem, glad to hear you're liking peewee!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants