The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by skass]

On page 120, the author proposes to find the date of the previous Saturday
(from today) by subtracting 2 from the date on which Monday of the current
week falls. On the following page, the author proposes to find the first
Monday of they year as the Monday during the week containing January 7.

Suppose today is Sunday, January 7. "Monday of the current week" and "the
Monday of the week containing January 7" must be the same. Call that date
"mystery Monday." Since today is Sunday, January 7, mystery Monday is either
January 1 or January 8.

If mystery Monday is January 1, the "previous Saturday" calculation yields
December 30 (but should yield January 6). If mystery Monday is January 8, the
"first Monday of the year" calculation yields January 8 (but should yield
January 1).

Additional erratum:
If today is Saturday, the "previous Saturday calculation on pages 117-18
return today, but the calculation on page 121 returns the date 7 days ago.


The author is correct, as he states on page 121, that "this isn't as simple as
it sounds." Have I missed something, or has he?

Steve
import-bot (20211) [Avatar] Offline
#2
Re: Erratum?
[Originally posted by dave]

> On page 120, the author proposes to find the date of the previous Saturday
> (from today) by subtracting 2 from the date on which Monday of the current
> week falls. On the following page, the author proposes to find the first
> Monday of they year as the Monday during the week containing January 7.
>
> Suppose today is Sunday, January 7. "Monday of the current week" and "the
> Monday of the week containing January 7" must be the same. Call that date
> "mystery Monday." Since today is Sunday, January 7, mystery Monday is either
> January 1 or January 8.
>
> If mystery Monday is January 1, the "previous Saturday" calculation yields
> December 30 (but should yield January 6). If mystery Monday is January 8, the
> "first Monday of the year" calculation yields January 8 (but should yield
> January 1).

Steve,

You're absolutely right. Thanks for pointing out the errors.

In this case, it's the previous Saturday calculation that is wrong. For Sunday
Jan 7th 2000, it yields Dec 30th. Your "mystery Monday" is therefore Jan 1st.

I need to give some thought to fixing the problem.

> Additional erratum:
> If today is Saturday, the "previous Saturday calculation on pages 117-18
> return today, but the calculation on page 121 returns the date 7 days ago.

Right again. In this case the fix is quite simple. Simply add the line

$diff = 7 unless $diff;

once you've calculated $diff.

> The author is correct, as he states on page 121, that "this isn't as simple as
> it sounds." Have I missed something, or has he?

I have. Thanks for being so on the ball smilie

Cheers,

Dave...