I tested the workingDiff function and looks like it's not working probable when there is two segment like
moment.locale('en', {
workinghours: {
0: null,
1: ['08:00:00', '12:00:00', '13:00:00', '17:00:00'],
2: ['08:00:00', '12:00:00', '13:00:00', '17:00:00'],
3: ['09:00:00', '12:00:00', '13:00:00', '17:00:00'],
4: ['08:00:00', '12:00:00', '13:00:00', '17:00:00'],
5: ['09:00:00', '12:00:00', '13:00:00', '17:00:00'],
6: null
}
});
and when the start and end time are between the first segment only. for example:
moment('2020-02-10T08:00:00Z').workingDiff(moment('2020-02-10T09:00:00Z'), 'hours', false);
this is should be return 1 hours but it's return -3.
I investigated about the issue and I have a fix:
inside workingDiff function,
if (from.isAfter(segment[1]) ) {
should be
if (from.isAfter(segment[1]) || to.isBefore(segment[0])) {
Please review
I tested the workingDiff function and looks like it's not working probable when there is two segment like
moment.locale('en', {
workinghours: {
0: null,
1: ['08:00:00', '12:00:00', '13:00:00', '17:00:00'],
2: ['08:00:00', '12:00:00', '13:00:00', '17:00:00'],
3: ['09:00:00', '12:00:00', '13:00:00', '17:00:00'],
4: ['08:00:00', '12:00:00', '13:00:00', '17:00:00'],
5: ['09:00:00', '12:00:00', '13:00:00', '17:00:00'],
6: null
}
});
and when the start and end time are between the first segment only. for example:
moment('2020-02-10T08:00:00Z').workingDiff(moment('2020-02-10T09:00:00Z'), 'hours', false);
this is should be return 1 hours but it's return -3.
I investigated about the issue and I have a fix:
inside workingDiff function,
if (from.isAfter(segment[1]) ) {should be
if (from.isAfter(segment[1]) || to.isBefore(segment[0])) {Please review