Get the next and previous business day - Node.js Date

Node.js examples for Date:Day

Description

Get the next and previous business day

Demo Code

Date.prototype.nextBizDay = function() {
    var dayOfWeek = this.getDay();
    if (dayOfWeek == 5)
        this.setTime(this.getTime()+3*1000*60*60*24);
    else if (dayOfWeek == 6)
        this.setTime(this.getTime()+2*1000*60*60*24);
    else/*from  w w w.j  av  a 2s .  c o  m*/
        this.setTime(this.getTime()+1*1000*60*60*24);
    return this;
};

Date.prototype.prevBizDay = function() {
    var dayOfWeek = this.getDay();
    if (dayOfWeek == 1)
        this.setTime(this.getTime()-3*1000*60*60*24);
    else if (dayOfWeek == 0)
        this.setTime(this.getTime()-2*1000*60*60*24);
    else
        this.setTime(this.getTime()-1*1000*60*60*24);
    return this;
};

Related Tutorials