Hi ajhops;
I did some testing in regards to your above questions.
1. "The ReportDate field appears to be auto generated with a DateTime.Now.Date
(midnight of today on the client *LOCAL* time). Can anybody verify that this is the designed behavior?"
I believe this happens if you don't set your ReportDate field as nullable. In my test, my DateTime field is nullable and upon new entity creation, my DateTime field is set to null. I can then set it to any DateTime object I want.
2. A few lines later I try setting ReportDate to a different DateTime (midnight of today on the client *UTC*)
time, this set does nothing. PropertyMetadata.ReportDate.SetValue(this, value); appears to determine that the
setter is trying to set the value to what it already is and ignores it (even though datetimekind are
different). Can anybody verify this?"
I did the same test and encountered the same behavior. As you have verified, it looks like when comparing 2 different DateTime objects, .NET ignores the DateTimeKind and only compares the date and time. In this case, since the midnight part of the DateTime objects are the same, the set does nothing.
3. "I found the problem.
DateTime.Today == DateTime.SpecifyKind(DateTime.Today, System.DateTimeKind.Utc) evaluates to True.
I did not expect this.
Again, it seems that the DateTime object comparison (==) operator ignores the DateTimeKind part of the DateTime object. The following tests below seem to confirm it.
DateTime utcDt = DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc);
DateTime localDt = DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Local);
DateTime unspecDt = DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Unspecified);
bool isTrue1 = (DateTime.Today == utcDt); //true
bool isTrue2 = (DateTime.Today == localDt); //true
bool isTrue3 = (DateTime.Today == unspecDt); //true
bool isTrue4 = (DateTime.Today.Kind == utcDt.Kind); //false
bool isTrue5 = (DateTime.Today.Kind == localDt.Kind); //true
bool isTrue6 = (DateTime.Today.Kind == unspecDt.Kind); //false