Syntactic Confectionery Delight PerlMonks

### 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??

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.

Cheers,
Matt

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!

Cheers,
Matt

Create A New User
Node Status?
node history
Node Type: note [id://864920]
help
Chatterbox?
 [LanX]: yeah too far for someone who can't even make it to Amsterdam LanX looking for a good magit tutorial LanX ... and git in general [erix]: I've been to Amsterdam before you were born [LanX]: 1899? [chacham]: Just paint the white house black again. dbander snorts LanX Gesundheit! :) talexb wonders about dividing developers in those born before the Unix timestamp of zero .. and after. Spoiler: I'm before. chacham remebers I am a mad scientist

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2017-08-18 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (302 votes). Check out past polls.

Notices?