ontehfritz / api.mtgdb.info

Project closing first of August 2015
http://www.mtgdb.info/
MIT License
36 stars 8 forks source link

Api date fields may have incorrect values when serialized #10

Closed ontehfritz closed 10 years ago

ontehfritz commented 10 years ago

On Sep 15, 2013, at 10:37 PM, Nick Hoffman nick@deadorange.com wrote:

Hey fritzcoder. I saw your post about your MTG API on Reddit. Awesome work! While poking around it, I noticed that date objects are being returned as odd strings. E.g. "/Date(1184284800000)/"

http://api.mtgdb.info/sets/10E http://api.mtgdb.info/cards/106368

Keep up the great work! Nick

ontehfritz commented 10 years ago

JSON is javascript and it follows JavaScript rules. JavaScript dates are composed from how many milliseconds from January 1, 1970 (maybe a date the world was suppose to end). In your example, Date(1184284800000). That is how many milliseconds from 1970 to the release date of the set or card. There is 86 400 000 milliseconds in a day, therefore, 1184284800000 / 86400000 = 13707 days 13707 / 365.242 = ~ 37 years, 1970 + 37 = 2007 then the leftovers result in the release date of July 13, 2007. Which is correct. "/Date(1184284800000)/" is a JavaScript function.

ontehfritz commented 10 years ago

The above works however non .net languages may have a problem see below: " This is because JSON doesn't specify how dates should be represented. Despite that, the best way to encode a date to JSON is in a format that JavaScript's Date() function accepts, which is either an integer representing the number of milliseconds since 1970, or as a string in the ISO-8601 standard, which is "YYYY-MM-DDTHH:mm:ss.sssZ".

Can you update mtgdb.info to encode dates in either of those 2 formats? Here's a helpful article: http://stackoverflow.com/questions/10286204/the-right-json-date-format

Cheers, Nick"

ontehfritz commented 10 years ago

I will convert it to the ISO format which seems to be the best idea. I will use JSON.Net to do this as it has ISO date converter.

nickhoffman commented 10 years ago

Hey @fritzcoder! Thanks for linking me to the repo.

ontehfritz commented 10 years ago

refer to #11