I am working on binding both the date and the time to two separate controls using Knockout and HTML5 elements. Each of the binding is working independent of the other, but I am struggling to get them to update / display the same values of their respective portions of the property (date show date, time show time of same day)
I used the datepicker from jQuery and RP's custom binding handler and I can bind to the HTML5 time input element but I am having a problem on updating the date observable properly when you change the time -
http://jsfiddle.net/NAgNV/1263/
The problem appears to be here -
ko.utils.registerEventHandler(element, "change", function() {
var observable = valueAccessor();
console.log($(element).value);
observable($(element).value);
});
If I select the first object in the array (why is it returning an array?) like this - $(element)[0].valueAsDate
it appears to update the observable, but oddly enough it changes the date to 1970 and doesn't update the datepicker.
EDIT
WHOA!
So I have been using this in a production application with no problems until this weekend - on Saturday oddly enough it started to decrement the hour every time you changed anything in the time picker. Check out the example for proof -
http://jsfiddle.net/NAgNV/1339/
What changed? Get ready for this one...
The adjusted time is being set as the time on January 1st, 1970. The adjusted date is correctly set to the proper date. When the date picker is set to any day that is Central Standard Time, no problem. When it is Central Daylight Time it starts going nuts. The problem is that getting the time from one time zone and setting it to the value of another time zone decrements the hour.
It also makes it impossible to set the time by manually typing it in.
Bounty Time!
I updated Joseph's answer below and awarded the bounty since he put in extra time up front anyway