Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^3: Determing Week Ranges between given date range?

by ikegami (Pope)
on Oct 12, 2010 at 18:16 UTC ( #864920=note: print w/replies, xml ) Need Help??

in reply to Re^2: Determing Week Ranges between given date range?
in thread Determing Week Ranges between given date range?

If you want the first day of the week to be something besides Sunday

He wants it to be Monday.

you can do this:

You have an off-by-one error.

my $first_dow = 1; # 0=Sun, 1=Mon, ..., 7=Sun ... # Day before first $first_dow after $week_s ->add( days => ((7 - $week_s->dow()) + ($first_dow + 6)) % 7 );

Replies are listed 'Best First'.
Re^4: Determing Week Ranges between given date range?
by mojotoad (Monsignor) on Oct 12, 2010 at 21:54 UTC
    Sort of...actually, I cribbed that code from something I had lying around -- that code was designed around the convention of 0=Mon, 1=Tue, etc. But I forgot, oops.

    After fixing that assumption, this also works (closer to the form I originally used). 0=Sun, 1=Mon ... :

    days => ($first_dow + (6 - $week_s->dow())) % 7
    Thanks for spotting it.


      Yeah, that's functionally equivalent, but I wanted to keep the two halves of the equation separate (calculating the last day of the week and calculating the number of days until the last day of the week). In mine, ($first_dow + 6) can be replaced with $last_dow.
        How dare you introduce clarity!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://864920]
[jdporter]: one prog I have has a UI which allows to input a bit mask
[jdporter]: currently it expects the bitmask to be in the form of a hex number, e.g. 0x0101
[jdporter]: but I'd like to let the user specify it as individual bits, i.e. 0b0000000100000001
[jdporter]: there is no bit/binary equivalent of hex, right?
[jdporter]: I guess that the most direct way of doing it is with some magical incantation involving unpack or whatever
[jdporter]: let me google that for me ;-)
[jdporter]: hex points explicitly to oct, which does the job. :-D
[jdporter]: omg, I f love Perl!
[choroba]: say unpack 'H*', pack 'B*', $mask =~ /0b([01]+)/;

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2018-02-20 16:32 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (272 votes). Check out past polls.