Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Determining if I have a particular Friday off

by thmsdrew (Scribe)
on Oct 24, 2012 at 16:40 UTC ( #1000668=CUFP: print w/ replies, xml ) Need Help??

I am currently working an alternative work schedule, or a 9/80 work schedule. Not sure how well-known that is, but basically, one week I work 44 hours (9, 9, 9, 9, 8), and the next I work 36 (9, 9, 9, 9, 0).

I've often found myself wondering if I have a certain Friday off, so I go to a calendar and figure it out by counting up from a week that I know I have the Friday off. This is a pain, so I put together this little script that sort of does it for me.

#!/usr/bin/perl use strict; use warnings; use Date::Calc qw(check_date Add_Delta_Days Monday_of_Week Week_of_Yea +r Compress Today Date_to_Text); if (check_date(@ARGV)) { my @friday = Add_Delta_Days(Monday_of_Week(Week_of_Year(@ARGV)), 4 +); my ($week, $year) = Week_of_Year(@friday); my $present = Compress(@friday) > Compress(Today()); # It is an odd week, so I have Friday off. if ($week % 2) { my $do_verb = $present ? "DO" : "DID"; print "You $do_verb have " . Date_to_Text(@friday) . " off.\n" +; } else { my $dont_verb = $present ? "DON'T" : "DIDN'T"; print "You $dont_verb have " . Date_to_Text(@friday) . " off.\ +n"; } } else { print "Usage.\n"; }

This isn't terribly useful for anyone in particular, unless they are in the same exact situation as myself, but I figured I'd share it anyway.

Comment on Determining if I have a particular Friday off
Download Code
Re: Determining if I have a particular Friday off
by choroba (Abbot) on Oct 24, 2012 at 16:46 UTC
    Does not the following do the same?
    print +(localtime)[7] / 7 % 2 ? "Free\n" : "Work\n";
    (You might need to switch Free and Work).
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      No. No it doesn't.

      Is it true that this is telling me whether or not I work the Friday of this week? If so, it worked for me. However, I did have to swap "free/work".

      How does dividing the $yday by 7 with remainder of 2 get one to a Friday - or did I misunderstand?

      UPDATE: Ah, it provides the odd even week.

        I am generally aware of my schedule for the current week, so this isn't particularly helpful. (I need to know if I'm working the current week's Friday so I can record my time properly!)

Re: Determining if I have a particular Friday off
by hbm (Hermit) on Oct 24, 2012 at 18:51 UTC

    You can replace your if-else with printf:

    printf "You %s have %s off\n", ($present ? "DO" : "DID") . ($week % 2 ? "" : "N'T"), Date_to_Text(@friday);
Re: Determining if I have a particular Friday off
by Not_a_Number (Parson) on Oct 25, 2012 at 19:50 UTC

    There is a bug in your code.

    You assume that every year has 52 weeks. In fact, some are deemed to have have 53:

    Try this:

    D:\perl>junk.pl 2010 1 1 You DID have Fri 1-Jan-2010 off. D:\perl>junk.pl 2010 1 8 You DID have Fri 8-Jan-2010 off.

      Hey, been busy lately but I finally addressed the problem you pointed out as follows:

      #!/usr/bin/perl use strict; use warnings; use Date::Calc qw(check_date Add_Delta_Days Monday_of_Week Week_of_Yea +r Compress Today Date_to_Text Weeks_in_Year); if (check_date(@ARGV)) { # If there are 52 weeks in the year, I have odd Fridays off. # If there are 53, I have even Fridays off. my $mod = (Weeks_in_Year($ARGV[1]) eq 52) ? 2 : 1; my @friday = Add_Delta_Days(Monday_of_Week(Week_of_Year(@ARGV)), 4 +); my ($week, $year) = Week_of_Year(@friday); my $present = Compress(@friday) > Compress(Today()); printf "You %s have %s off.\n", ($present ? "DO" : "DID") . ($week % $mod ? "" : "N'T"), Date_to_Text(@friday); } else { print "Usage.\n"; }
        my $mod = (Weeks_in_Year($ARGV[1]) eq 52) ? 2 : 1; ... ($present ? "DO" : "DID") . ($week % $mod ? "" : "N'T")

        Hmmm. When $mod is 1, % is always zero - and you "DON'T/DIDN'T" have off.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1000668]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2014-08-28 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls