mgholam / fastJSON

Smallest, fastest polymorphic JSON serializer
https://www.codeproject.com/Articles/159450/fastJSON-Smallest-Fastest-Polymorphic-JSON-Seriali
MIT License
479 stars 147 forks source link

fastJSON.deserializer.CreateDateTime(String value) throws exception when ms is not 3 digits #23

Closed B9Tony closed 7 years ago

B9Tony commented 8 years ago

If a date contains a 2 digit or 1 digit number of milliseconds an exception is thrown by CreateInteger, called by CreateDate, it can be fixed by checking for 'Z' first then calculating the length of milliseconds:

            hour = CreateInteger(value, 11, 2);
            min = CreateInteger(value, 14, 2);
            sec = CreateInteger(value, 17, 2);

            if (value[value.Length - 1] == 'Z')
                utc = true;
            if (value.Length > 21 && value[19] == '.')
                ms = CreateInteger(value, 20, (value.Length - (utc ? 21:20)));

Data Example:

webServiceResults.txt

RiPont commented 7 years ago

This also applies to CreateDateTimeOffset.

skottmckay commented 7 years ago

45 should handle DateTimeOffset better. Allows for 'Z' and the ISO8601 roundtrip format.