in reply to Run if weekend

It might be relevant how your script is run. A script that is aware of temporal concerns seems like code smell to me. A crontab or other scheduling daemon makes it easy to slot for only weekends, for example, leaving the script to only care about what it is supposed to do, not when it is supposed to do it.

Replies are listed 'Best First'.
Re^2: Run if weekend
by BillKSmith (Monsignor) on Jun 14, 2016 at 18:22 UTC
    I had a perl script which I ran every day for several years. It had to form a URL which included the current date. The format was slightly different on Sunday. It made perfect sense to use localtime to get the date and day-of-week and to use strftime (FUNCTIONS) to format it.
    Bill

      That's cromulent but, at least from the limited original description, quite different from the OP's problem; a script specifically to write temporal output versus a script only intended (for the time being at least) to run within a temporal window. The second is the sort of thing that is harder to debug and circumvent on demand as well. Taking date args in the invocation would be better than hardcoding the date in all invocations. So I say. :P

        I think that better than taking date args, taking behavior-shaping args is probably preferable. Let the caller decide what behavior is desired for a given date, alignment of the stars, unforeseen business need, or temperature in Bermuda.

        Of course this is only an opinion, and one that has been formulated with less than the full set of facts for this specific use case. :)


        Dave

Re^2: Run if weekend
by FloydATC (Deacon) on Jun 14, 2016 at 19:32 UTC

    Indeed, a script that refuses to do anything during weekends sounds like a lot of fun to maintain in your spare time :-D

    -- FloydATC

    Time flies when you don't know what you're doing