Working days in calendar month

As a user I would like to calculate the number of working days in a month so I can effectively forecast revenue (amongst other things :grin:)

1 Like

Useful?

Quick follow up with another suggestion for how to calculate the number of working days in a month (or any period).

There is a commercial API that supports queries for determining the working days in a given time period (taking into account weekends and public holidays for a specific country).

A simple script can therefore be used in an automation to send a query to the API which will return the number of days in a given period. As an example…

const fibery = context.getService('fibery');
const http = context.getService('http');

for (const entity of args.currentEntities) {
    const start = entity['Start'];
    const end = entity['End'];
    const countryCode = entity['Country'];

    const url = `https://api.workingdays.org/1.2/analyse?key=MYPERSONALKEY&country_code=${countryCode}&start_date=${start}&end_date=${end}`;
    const response = await http.getAsync(url);
    const respObj = JSON.parse(response);

    await fibery.updateEntity(entity.type, entity.id, { 'Working days': respObj.result.working_days.total });
    console.log(respObj);
}

You will need to pay for an API key (but you can test for free for the year 2013).

Note: the country codes used are the two letter codes which are currently included in the World template that Fibery has, so you could make things easy on yourself by leveraging that template.

There is no error handling in the code, so it will fail if the field values are empty, if the start date is before the end date, or if you try to calculate for a country that is not supported, but hopefully the concept is useful to someone :crossed_fingers: