1.
Ok, for the first question I have a question about Moment. It doesn't calculate the time right(I think?) This is my script:
function CalculateTime() {
try {
var originalStartTime = $('#startTime').val(),
originalEndTime = $('#endTime').val(),
originalBreakTime = $('#breakTime').val();
// breaking hours and minutes. needed format: HH:mm
var startHours = originalStartTime.substring(0, 2).replace(':', ''),
startMinutes = originalStartTime.substring(3, 5),
endHours = originalEndTime.substring(0, 2).replace(':', ''),
endMinutes = originalEndTime.substring(3, 5);
// momentJs variables
var mStart = moment().hour(startHours).minute(startMinutes),
mEnd = moment().hour(endHours).minute(endMinutes),
mBreak = moment.duration(originalBreakTime);
var result = moment( mEnd - mStart - mBreak).format('HH:mm');
$('#workedHours').val(result + " timmar");
} catch (err) {
$('#workedHours').val(err);
}
startTime: 07:00, endTime: 16:00, breakTime 00.00 That will result with workedHours being 10.00. This is from the chrome console:
You need to use the subtract method
I think a more momentjs way is