We've been having some real confusion about how to handle dates between Angularjs and WebAPI. We only care about the date,don't care about the time or timezone. The angular site posts a date object back to our api but the date object still has the timezone on it so, depending on where the user is, the date that gets saved is off by one day.
I'd rather not have to deal with these dates on a one by one basis so we put in an http interceptor for all puts and posts that is looping thru all form fields and stripping timezone off dates and just returning the date but this doesn't feel right.
Any suggestions on the best way to handle this?
UPDATE:
More details if it helps. We are using kendo date pickers and setting the model values with k-ng-model. This helps us get a valid Date object. Today I removed the interceptor and added the following:
kendo.ui.DatePicker.prototype.valueOld = kendo.ui.DatePicker.prototype.value;
kendo.ui.DatePicker.prototype.value = function (e) {
var val = this._value;
if (val != null) {
this._value = moment(val).format("YYYY-MM-DD");
}
return this.valueOld(e);
}
Now when a user changes a date the model value will be only the date and the time zone is ignored when sent back to the API.
In the API when dates are sent to the front end we have a formatter that strips off the timezone as well:
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd" });
I don't want our devs to handle dates on an individual basis. We were originally doing this and there was no consistency in the code.