Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Determining if I have a particular Friday off

by Not_a_Number (Parson)
on Oct 25, 2012 at 19:50 UTC ( #1000925=note: print w/ replies, xml ) Need Help??


in reply to Determining if I have a particular Friday off

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.


Comment on Re: Determining if I have a particular Friday off
Download Code
Re^2: Determining if I have a particular Friday off
by thmsdrew (Scribe) on Nov 06, 2012 at 14:55 UTC

    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.

        Hmm yeah, I wasn't thinking. This is a weird case, I'll have to think more about it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2015-07-06 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (84 votes), past polls