Skip to content

workingDiff is not working probable when there is two segment  #42

@fathi-hindi

Description

@fathi-hindi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions