True story:

I got a request from our economy guy, he asked me if I knew some online service to give him the number of work days for a given month. Turned out that he was manually counting the number on his calendar (probably several times to be sure), and then used this as a basis for calculating salaries.

Not surprisingly, this guy was not happy about the situation, and asked me if I knew some online service to give him the number of work days for a given month. After five minutes of unrewarded Googling, I decided to make it myself.

Arbeidsdager = Work days
Helligdager = Holidays

Definition of a work day

In Norway, it's a day that's not a weekend (Saturday or Sunday), and not a holiday. Easy peasy.


The norwegian holidays are pretty straightforward. It's either a fixed date (Consitution day, Christmas etc.) or a moveable date based on Easter (Pentecost, Ascension day).

So, when is easter?

The definition is "The first Sunday after the ecclesiastical full moon that occurs on or soonest after 21 March", but you have to be a werewolf to know when that is.

Enter Spencer Jones, which in 1922 published a computer friendly formula for calculating Easter Sunday. Hooray!

This is the formula using MomentJS (copied from Wikipedia):

function EasterSunday (InputYear) {
        var a = InputYear % 19;
        var b = Math.floor(InputYear/100); var c = InputYear % 100;
        var d = Math.floor(b/4); var e = b % 4;
        var f = Math.floor((b+8)/25);   
        var g = Math.floor((b-f+1)/3);
        var h = (19*a+b-d-g+15) % 30;      
        var i = Math.floor(c/4); var k = c % 4;
        var l = (32 + 2*e + 2* i - h - k) % 7;
        var m = Math.floor((a+11*h+22*l)/451);
        var n = Math.floor((h+l-7*m+114)/31); var p = (h+l-7*m+114) % 31;
        var es = moment(p+"-"+n+"-"+InputYear, "DD-MM-YYYY");   
        return es;

Fair to say that Spencer was a clever little werewolf.

The result

Knowing the holidays, the rest of the job was trivial.

I made a web site (in Norwegian):

The source code on GitHub:

Our economy guy was very happy with the web site, and this shows that automating tasks isn't always complex and expensive.