praekeltfoundation / vumi

Messaging engine for the delivery of SMS, Star Menu and chat messages to diverse audiences in emerging markets and beyond.
BSD 3-Clause "New" or "Revised" License
421 stars 131 forks source link

Standardize internal date format on ISO 8601 #148

Open smn opened 12 years ago

smn commented 12 years ago

Not our own funny format. Allow for the old version to remain working but deprecated for 0.4 with 0.5 removing it completely.

hodgestar commented 12 years ago

A related problem is that vumi.message.from_json and .to_json don't correctly roundtrip. Currently

now = datetime.datetime.now() from_json(to_json(now)) != now

The issue is that .to_json encodes all datetime objects as strings but .from_json only converts strings that are values of keys in hashes (i.e. Javascript objects).

piet-praekelt commented 12 years ago

To be more precise, we should probably standardize on something like RFC 3339, which is a subset / profile of ISO 8601 intended for Internet protocols. Atom uses it, among others.

piet-praekelt commented 12 years ago

(The reason for a subset like RFC 3339 is that full ISO 8601 actually includes a number of format variations which are not really desirable for Internet use, such ordinal weeks and days.)

piet-praekelt commented 12 years ago

@hodgestar: With json.JSONDecoder, at least, the only way to do it seems to be to recurse from within our object_hook. There's one example of doing that here.

Alternatively, we could investigate a more flexible third-party JSON library?

hodgestar commented 12 years ago

@piet-praekelt My plan was not to allow any keys to be datetime.datetime objects (i.e. don't support them in the JSON encoder) but have a convenience method for accessing timestamp values as datetime objects if needed.

piet-praekelt commented 12 years ago

@hodgestar: Ah, that sounds good.