While activating my Edit view page, I am trying to get the entities from different tables using foreign keys, Which I am getting but I think its not the correct way of fetching and updating the entities, which is not saving the updated attribute "modification_date" and another problem which I am facing is time issue, as I have one attribute "startDate" which is datetime type, So when I am hosted my application to some VM then its showing the time which is +5:30 more from the original value because the database is storing the value in GMT +00:00. How can I solve this problem? My question is:
- Why "modification_date" is not saving current date, whenever entity is updated.
<input data-bind="value: modificationDate = $root.md, visible: false"
>
Javascript
vm.md = ko.dependentObservable(function () {
var y = new Date();// should assign current to modification date but its not persisting the changes to database.
return y;
}, vm);
How can I show the correct time which is in GMT +00:00 to client side when my current is GMT +5:30. While editing and fetching the data from SqlServer.
Please comment how we use the navigation key to access the other table as what I am doing is getting a 'Job' observable and in that different attributes are there and another table is 'job_Schedule', so how should I access the property startDate which is under 'job_Schedule' table. As currently I am accessing is like
job_Schedule._latestValue[0].startDate
which is probably not the right way to fetch the entity.
Here is piece of my code:
<div data-bind="with: job">
<label>Start Date :</label>
<input data-bind="kendoDateTimePicker: $root.temp3" />
<input data-bind="value: job_Schedule._latestValue[0].startDate = $root.tempSD1, visible: false" />
<input data-bind="value: modificationDate = $root.md, visible: false" >
//I kept visible: false because modified date should be updated automatically
// some more attributes................
</div>
Javascript code
vm.md = ko.dependentObservable(function () {
var y = new Date();// should assign current to modification date but its not persisting the changes to database.
return y;
}, vm);
vm.tempSD = ko.dependentObservable(function () {
var y = ko.unwrap(this.tempx());// tempx containing the current value of startDate
if (y === null || y === '""') { y = new Date(); }
y = new Date(y);
var utc = y.getTime() + (y.getTimezoneOffset() * 60000);
temp3(new Date(utc));
return new Date(utc);
}, vm);
vm.tempSD1 = ko.computed(function () {
var y = vm.temp3();
if (y === null || y === '""') {y = new Date();}
y = new Date(y);
var utc = y.getTime() - (y.getTimezoneOffset() * 60000);
return new Date(utc);
},vm);
Dates manipulation is a long-standing challenge for everyone in every technology.
Timezone manipulation is particularly tricky, especially when the client and server are in different time zones.
This can be less of a problem when you can ensure that all dates are created and stored in UTC. I don't think you want to be relying exclusively upon calls to new Date()
.
I recommend looking into the momentjs date/time library.
I don't know how to address your question about navigating to a related entity as you have not provided any information about the entity types involved or their relationships. Is this a separate question? Or is there a connection between your navigation property and your date issue?