- marked as critical
Teacher Date of Birth recorded in Database with Time part
We are headed towards a world of pain editing teacher date of birth via the web ui, due to javascript default handling of date objects.
In the md-date-picker I have entered 10/22/1958
Since the client computer is in UTC+10
this gets sent to the server as
tDOB=1958-10-21T14:00:00.000Z
and saved in the DB as
1958-10-21 14:00:00.000
Next time the record is read, it is sent from the server to the client as
tDOB=1958-10-21T14:00:00
and displayed in the client as 10/21/1958 !!! And viewers in different time zones may see something different. This is ok for the starttime of a football match, but not useful for a date of birth, which should be the same everywhere.
There are a number of components that influence this workflow, from the sql (date/DateTime/DateTimeOffset) to .NET DateTime type, Newtownsoft serialization settings etc;
The only relaible way I have found to overcome this is to prevent the value being encoded as UTC on the client, by changing the Date prototype:
Date.prototype.toJSON = function () {
var m = moment(this);
return m.format("YYYY-MM-DDTHH:mm:ss");
}
As well, incoming dates read from JSON should get converted to Date objects - this artice discussed the issues:
http://aboutcode.net/2013/07/27/json-date-parsing-angularjs.html
Until now, we have tried to manage this field by field; e.g. in Teacher.ts:
public _transform(newData) {
// convert these incoming data values
this._transformDates(newData, ["tDOB", "tDateRegister", "tDateRegisterEnd", "tDatePSAppointed"]);
return super._transform(newData);
}
But - global solution implemented by an interceptor in the http pipeline is better - set and forget.
It seems incredible to me that this is as hard as it is, but, there you have it...
Unless you've got better ideas, I think this infrastructure really has to be there.
Comments (5)
-
-
-
assigned issue to
-
assigned issue to
-
reporter - changed status to open
-
reporter Pull Request #190 resolves
-
reporter - changed status to resolved
Pull Request #190 resolves this and other date related issues
- Log in to comment
This needs to be sorted if every time someone opens a teacher in the web UI corrupts the data. Changing this to critical and please go ahead with your proposed solution as part of current teacher work.