Postman / moment.js Weekend and Bank Holidays


I am using moment.js to generate dates, and it works flawlesly. However, I was wondering if there was a way to generate a date in moment,js like so:

const date = require('moment');
const myNewDate = date().add(5, 'days').format("DD-MMM-YYYY");

but if the date fell on a weekend or bank holiday, it would generate a the next working day?

If this is not possible in moment.js, does postman support momentjs-business ?

ideally something like

var momentBusinessDays = require("moment-business-days")
momentBusinessDays('20-09-2018', 'DD-MM-YYYY').businessAdd(3)._d 


Hey @JBird20, I haven’t used this extended functionality of the library but I did take a look at what it’s doing and copied over the code from it into the request.

Check out the pre-request script of this request: Postman

Try running this request by forking the collection into your personal/team workspace, you should see it in action. :slight_smile:

1 Like

To additionally answer the Bank Holiday portion of the question (as even momentjs-business won’t help with that): you’ve got two main approaches - either dynamically load the list of bank holidays via this endpoint (adds an extra call into every request, but shouldn’t require any future maintenance) or hardcode an array of bank holidays into your script (and maintain it annually).

Once you have an array of bank holidays, you’ll need to utilise something like a while loop to check whether myNewDate is within that list, and then keep adding one business day until you find the next business day which isn’t a bank holiday (as sometimes they’ll run consecutively, e.g. Christmas)

1 Like