My users have been reporting since yesterday that dates they enter into the WebDataGrid are losing a day when saving to the database.
On closer inspection, these date/time fields are losing 1 hour. For example, if a user enters 11/7/2011 into the WebDataGrid, 11/6/2011 11:00PM will be stored to the database, and the users then sees 11/6/2011 displayed in the grid as his saved value. This occurs regardless of the EditorProvider used... This even happens if you use the TextBox provider.
And this began recently, oddly corresponding to Daylight Savings Time.
I have found a very clumsy workaround. If you change your SQL statement so that it converts DateTime fields to VarChars, the WebDataGrid won't corrupt the date.
I have opened a support ticket CAS-77072-NSTXZT, but have also posted the issue and the workaround here, for the benefit of other users.
I consider this issue to be critical, since it is corrupting data.
Whoops, forgot to include version number.
Version=11.1.20111.2064
Hi Rob,
You can thank Microsoft for the problem since they do not serialize dates properly. This was reported in bug 84041 and looks to be resolved in build 11.1.20111.2088, so it should be available in the next Service Release. We changed how the dates are sent back and forth to the client (as strings, like you) to account for time zones and day light savings.
regards,David Young
Question... I notice that when converting the string to a javascript Date object, it is passing the time zone with the date.
What happens if the user's machine is in a different time zone with the server? What will be saved to the database?
My intention is to work with whole dates (time is irrelevant).
Actually the intent of the bug fix was to solve an issue when the computer and server were in different time zones. By passing the dates as strings, it is whatever the date is regardless of the timezone. Day light saving and timezones won't adjust the date by hours or anything now. As for the issue you have where that code used to work, I will investigate it. I'll let you know if a bug ends up being submitted on it.
-Dave
Ok, it did used to work. It's in how we convert the dates. Right now the code expects a date. But we know it should be a date, so we'll try to convert it. It has been submitted as bug 95482. This may or may not make it into the upcoming Service Release.
Perfect, thanks! I am ok because I have already converted my code...
However, if it doesn't make it into this upcoming SR, everyone's CSOM code will break when they install the SR, and they'll have had to diagnose and convert the errors before you release a fix in the next SR. I am not sure it's a good idea to release a SR that you know will break someone's code, and inflict the pain on them of having to start from scratch figuring out what is wrong.
This is a workaround to deal with this problem of the grid changing editted date/time values. BTW, the bug has NOTHING to do with different time zones between browser and server. I am getting this bug while running locally against my server on same computer.
If you have a date only field (no time) to deal with, then this will work well.
Mine is a little more complex than Rob's as I am dealing with both a date only field and a time only field. I will depend on the date only field to be editted at the same time as the time only field. If not I am screwed, but better than nothing.
Here is the code behind code (podMaster is the List object I bind the grid to).
// There is a bug in the webdatagrid, where it will subtract an hour at times. Possible daylight savings time issue.// To remedy this, interrogate the date (since we know we just wanted the date), and if there is a time component,// we assume it is due to this bug. Adjust the date field and the time field accordingly. The problem with this// workaround is that if the do not edit both date and time, then we are going to corrupt the unedited field.// My dates are nullable so need to typecast them
var delDate = (DateTime)podMaster.DeliveryDate; var delTime = (DateTime) podMaster.DeliveryTime;var tsTimeFromMidnight = new TimeSpan(24, 0, 0) - delDate.TimeOfDay;if (tsTimeFromMidnight != new TimeSpan(0, 0, 0)){// We have an unexpected difference - the bug has bitten
if (tsTimeFromMidnight < new TimeSpan(11, 30, 0)){// Assuming that the bug subtracted tsTimeFromMidnight from date, so we need to add this back.// Also assuming that if this field has the bug, then all datetime fields have the bug
delDate = delDate.Add(tsTimeFromMidnight);delTime = delTime.Add(tsTimeFromMidnight);
}
else{// Assuming that the bug added tsTimeFromMidnight to date, so we need to back this out.// Also assuming that if this field has the bug, then all datetime
delDate = delDate.Subtract(tsTimeFromMidnight);delTime = delTime.Subtract(tsTimeFromMidnight);
// Combine the seperate date and time fieldsvar actualDeliveryDate = delDate.Date.Add(delTime.TimeOfDay);
Hope that helps someone until this bug is fixed.
I am very lucky that my application doesn't call for storing time values.
Have you submitted a ticket so that they know about the issue that persists with time values?
The same happens to time columns, but for some reason, the date value of the time is changed. Arghh! Quite frustrating. Will have to strip out the time portion in javascript and compare them to see if they really changed! Just tabbing through a time field, the _Editing_CallValueChanging() event has these values:
? eventArgs.get_currentValue().toString()
"Wed Nov 30 10:21:00 PST 2011"
? eventArgs.get_newValue().toString()
"Thu Nov 10 10:21:00 PST 2011"
Very odd that webdatagrid chose to change the date portion of the time column form Nov 30 to Nov 10. Happens to be my wife's birthday!
They still need to do some more work on the date and time column editing.
One side effect I have noticed is that for date columns, the CellValueChanged Event gets triggered by just tabbing through a date field.
Evaluating the _Editing_CellValueChanging event, the eventArgs.get_currentValue() and eventArgs.get_newValue() are equal. I imagine this is a side effect of the change that was made.
I am currently using this code to bypass this behavior
function
wdg_Editing_CellValueChanging(sender, eventArgs) {
if (eventArgs.get_currentValue().toString() == eventArgs.get_newValue().toString())
eventArgs.set_cancel(
true);
Thanks for reporting back! Glad to hear it!
Just wanted to confirm that I upgraded to 11.2 and this is no longer an issue.
Thanks
Jorge