Using a plugin i have 2 custom pickerfields where you can select a date(but without the year) and time. This way you can say that for example on 22 of april, i've started working on 09:05 and ended at 17:35. When these fields are initiated the get a value of new Date(), so it will be set to the current time and date.
timeEnd and timeStart are both Date objects and in the first console.log i notice there is a small difference between them: start: 1398147960000 end: 1398151585216. When i calculate the difference between them and create new Date objects from this calculated result the elapsed time is always the correct time but +1 hour.
I want to calculate the worked time, but for some reason the calculated time is always off by +1 hour.
The code from a pickerfield:
Code:
{ xtype: 'datetimefield',
itemId: 'startTimeField',
label: 'Start tijd',
value: new Date(),
dateTimeFormat : 'd-m-Y H:i',
picker: {
useTitles: true,
yearFrom: 1980,
ampm : false,
slotOrder: ['day', 'month', 'hour', 'minute'],
listeners: {
change: function(me, value){
var endTimeField = this.getParent().down('#endTimeField');
var timeEnd = endTimeField.getValue();
var timeStart = value;
console.log('start: '+timeStart.getTime()+' end: '+timeEnd.getTime());
var diff = Math.abs(timeStart.getTime() - timeEnd.getTime())
var time = Ext.Date.format(new Date(diff), 'H:i');
console.log(time);
var elapsed = Ext.Date.getElapsed(timeStart, timeEnd);
var time2 = Ext.Date.format(new Date(elapsed), 'H:i');
console.log(time2);
}
}
}
},
timeEnd and timeStart are both Date objects and in the first console.log i notice there is a small difference between them: start: 1398147960000 end: 1398151585216. When i calculate the difference between them and create new Date objects from this calculated result the elapsed time is always the correct time but +1 hour.
So when i set the first picker field to 09:05 and the second to 10:10 the calculated difference will be 02:05. The minutes always seem correct but the hours are always off. As you can see i tried using the Sencha method Elapsed but also the math version of it, but both with the same result.
Is this a bug or something?
Aucun commentaire:
Enregistrer un commentaire