This project has moved and is read-only. For the latest updates, please go here.

DateTime unit test fails

Oct 6, 2012 at 8:34 AM

In the DateTime unit test it first tries on {10/11/2012 09:08:07} local time (I am in Jerusalem Standard Time at the moment), and the ValueConverter.TryGetValue returns a value of {10/11/2012 07:08:07} UTC. This is the same actual time, but of course the assertion fails.

I looked into the ValueConverter.TryGetValue implementation, and saw that it assumes universal time, so I changed the test to use

DateTime.TryParse(formatted, out parsed);

which assumes local time. This time the parsed value is the "correct" {10/11/2012 09:08:07} local time, which the assert sees as equals. However, later on the test it tries to compare {10/11/2012 09:08:07} UTC with the result of the DateTime.TryParse, which is now {10/11/2012 11:08:07} local time, so again - assertion error.

What exactly does this assert checks? that after parsing the formatted text we get the same exact DateTime (including Kind?) or just the same actual time (In which case maybe it should compare date.ToUniversalTime() and parsed.ToUniversalTime())?

Why does it use ValueConverter.TryGetValue and not DateTime.TryParse? Any special reason?

And another point - I think this unit test should be split to at least 3 tests - one for each Kind. I had a failure, and I had to debug it manually in order to see which of the 3 kinds fails. It later also has two different asserts. One for the formatting and one for the parsing. Maybe those two should also be split to two.

I have just started looking into your library, so thanks for making it available, and I hope to use it in my fiddling around KML.

Oct 6, 2012 at 11:31 AM

I assume this is the KmlFormatterTest that is failing? The test is there to ensure that a DateTime will round-trip correctly. It is important that the dates stored in a Kml file are in universal time, hence the need to use ValueConverter to parse the value as this is what would be used when parsing the value from a Kml file.

I'll need to take a closer look but thanks so much for actually running the tests!

Oct 6, 2012 at 11:34 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.