Skip to content

DateTime deserialization #91

@binis2

Description

@binis2

Latest changes changed (broke) ISO 8601 support. So now dates like "2015-11-21T12:45:00" are not supported.

And since we are on the DateTime subject, I would like to make a proposal for some changes that will improve the DateTime handling.

        public static DateTime FastStringToDate(string value) {
            ...
            //if (value == "\\/Date(-62135596800)\\/") - I think these checks are not needed because of the handling later on
            //    return DateTime.MinValue;
            //else if (value == "\\/Date(253402300800)\\/")
            //    return DateTime.MaxValue;
            //else 
            if (value[0] == '\\') {
               ... //Extract the value in Date()
               if (extractedValue > DateTime.MaxValue || extractedValue < DateTime.MinValue)
                  extractedValue /= 1000; //Some servers give the time stamp in milliseconds instead of seconds, this will catch most of the cases. This functionality can also be altered by attribute so solution of this problem to be complete
            } else {
                // get the format defined with attribute or use parser wide (thread local) one. (Attributes are prefered :)
                DateTime.ParseExact(...);
            }

In my use case I parse a lot of JSONs provided by a large number of providers. Each provider has different view how a date must be formatted and quite often the format violates any standards. You can't handle it all with code unless you implement DateTime.Parse() by yourself. So It will be nice if you consider to handle the problem in more generic way.

Regards and keep up the awesome work!

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions