lennym/moment-business-time

subtractWorkingTime returns incorrect value

Closed this issue · 1 comments

var moment = require("moment-business-time");
moment.locale('en', {
  workinghours:{
    0: ["22:00:00", "24:00:00"],
    1: ["00:00:00", "24:00:00"],
    2: ["00:00:00", "24:00:00"],
    3: ["00:00:00", "24:00:00"],
    4: ["00:00:00", "24:00:00"],
    5: ["00:00:00", "22:00:00"],
    6: null
  },
  holidays:['2020-01-07','2020-01-08']
}); 
var date = moment.utc('2020-02-19T16:00:00Z');
var date = date.subtractWorkingTime(1, 'months');
console.log(date.format()); //got 2019-12-17T22:00:00Z

See the above code snippet. I am trying to subtract one month from Feb 19th. I get Dec 17 where I was expecting a date around Jan 17th.

Thanks for raising an issue.

If you're trying to subtract months then you should use the normal moment add/subtract functions. The concept of a "working month" isn't really a thing. You should see a warning in your console telling you that it's not supported and that you'll get unexpected results.

Admittedly I should also simply revert to using the underlying methods if passed an unsupported unit - that will go on my to do list.