djc / couchdb-python

Python library for working with CouchDB
Other
202 stars 86 forks source link

Why not microsecond? #292

Closed rdbisme closed 8 years ago

rdbisme commented 8 years ago

Hello, for the purpose I'm using CouchDB and this library I would need the microseconds too in the DateTime field of a document. Why are you stripping them out?

https://github.com/djc/couchdb-python/blob/master/couchdb/mapping.py#L490

djc commented 8 years ago

@cmlenz hey, do you happen to remember why you put this in there? Thanks!

cmlenz commented 8 years ago

No, I don't remember the reason. If there's no problem with parsing the microsecond part, it really shouldn't be stripped out. Note that the inverse _to_json is also stripping them out, so that would need to be changed, too.

djc commented 8 years ago

@rubendibattista there's your answer! Do you want to contribute a fix for this?

@cmlenz thanks for the quick response.

rdbisme commented 8 years ago

Ok. Thanks to both of you. I will start working on that.

kxepal commented 8 years ago

Let me guess: because compatibility with else systems which expects datetime in %Y-%m-%d %H:%M:%S format and may be surprised by microseconds? Like JavaScript's Date.parse().

rdbisme commented 8 years ago

@kxepal So what then? We could add something like an optional argument (that defaults to "no microseconds") to allow the user to specify if he needs microseconds... What do you suggest?

kxepal commented 8 years ago

@rubendibattista mmm....probably just store such datetimes as timestamps with microsecond resolution? Like

>>> dt = datetime.datetime.now()
>>> ts = int(dt.timestamp() * 10**6)
>>> ts
1465330452610979
>>> doc.timestamp = ts
rdbisme commented 8 years ago

Well, I would prefer the ISO standard here with microseconds support instead of plain timestamp. It's easier when you look at it inside the database.