img

PaperCut Print Script of the Month #2 – Days until Christmas


PaperCut Print Script – Days until Christmas

 

It is almost that time of year again where we get some time off work and eat until we nearly explode and watch whatever James Bond film happens to be on the TV. This month we are going to create a PaperCut Print Script to tell the users how many days there are to go until the big day, so grab a cup of coffee or tea and let’s begin.

We begin our script this month by creating a new Date object this will make it easier to work with dates which are usually done by converting the date to a number and working from there, this is called Unix Time or POSIX / Epoch Time.

var objDate = new Date();

Next up is to set the date we want to use for our countdown and convert it to Unix Time using the Date.parse() method and also set a variable to today’s date that we will use later.

xmas = Date.parse( "Dec 25, " + objDate.getFullYear() );
today = Date.parse( objDate );

So now we need to do a little bit of math to work out what difference is between today and 25th December then convert it to a number that will actually mean something to a user and also round it to the nearest whole number.

daysToGo = Math.round( ( xmas - today ) / ( 1000 * 60 * 60 * 24 ) );

All we need to do now is add in a few if statements to handle the three possible outcomes, then send the user a message that is relevant. We only have three possible cases to take into consideration here; Christmas has not yet happened, Christmas has happened and today is Christmas (We don’t recommend working on Christmas day unless something important is on fire).

if ( daysToGo == 0 ) {
    actions.client.sendMessage( "Merry Christmas!" );
    return;
}
if ( daysToGo < 0 ) {
    actions.client.sendMessage( "We hope you had a good Christmas" );
    return;
}
if ( daysToGo > 0 ) { 
    actions.client.sendMessage( "Christmas is only " + daysToGo + " days away" );
    return;
}

That is it now you have a script you can use to let your users know how many days there are until Christmas, you could restrict this to certain groups of users or even use it to remind people of any events you have coming up.

As always the complete print script is below and if you have your own requirements for a print script and you don’t have the time or in-house experience to make it you can find out how we can help you by sending an email to our sales team at sales@selectec.com

/*
 * Days until Christmas
 *
 * Show the users how many days there are until Christmas
 *
 * Read more at http://selectec.com/script-of-the-month-2-days-until-christmas
 */
function printJobHook( inputs, actions ) {
    if ( !inputs.job.isAnalysisComplete ) {
        // No job details yet so return.
        return;
    }

    var objDate = new Date(); // New date object
    xmas = Date.parse( "Dec 25, " + objDate.getFullYear() ); // This is the date we want
    today = Date.parse( objDate ); // What is todays date again?
    daysToGo = Math.round( ( xmas - today ) / ( 1000 * 60 * 60 * 24 ) ); // Little bit of math

    if ( daysToGo == 0 ) {
        // It must be xmas today
        actions.client.sendMessage( "Merry Christmas!" );
        return;
    }

    if ( daysToGo < 0 ) {
        // Xmas has gone
        actions.client.sendMessage( "We hope you had a good Christmas" );
        return;
    }

    if ( daysToGo > 0 ) {
        // It is almost xmas time
        actions.client.sendMessage( "Christmas is only " + daysToGo + " days away" );
        return;
    }
 }
PaperCut Print Script
Latest News from Jonathan Bennetts
img

PaperCut and Access Management

Access Management and Identity as a Service (IDaaS) solutions for PaperCut...

Written by: Jonathan Bennetts

More
img

PaperCut ends client support for 32-bit operating syst...

A long time ago, in a country far far away... PaperCut announced they were...

Written by: Jonathan Bennetts

More

img

Fastek Consultancy have worked on many large scale PaperCut projects with Selectec over the last few years. The level of expertise and support from Selectec is of the highest standard. Fastek have been approached by a number of other software companies wanting to work with us on machine management projects and we have turned them all down, purely because of the strength of our relationship with Selectec

Gary Whitaker Fastek Consultancy
Back to Top ↑