nop has asked for the wisdom of the Perl Monks concerning the following question:

It seems like Date::Manip puts December 31, 2000 into the first week of *2000*, rather than week 52 of 2000. Am I missing something obvious here?
use strict; use Date::Manip qw(UnixDate Date_Init); my @test = qw( 2000-12-29 2000-12-30 2000-12-31 2001-01-01 2001-01-02 2001-01-03); &Date_Init("TZ=EST"); print join ("\n", map {&UnixDate($_,"%F \t --> %a --> %Gw%W")} @test);

Replies are listed 'Best First'.
(jcwren) RE: Date::Manip week-of-year
by jcwren (Prior) on Oct 04, 2000 at 07:05 UTC
    Output I get (Version 6.0 of Date::Manip):
    Friday, December 29, 2000 --> Fri --> 2000w52 Saturday, December 30, 2000 --> Sat --> 2000w52 Sunday, December 31, 2000 --> Sun --> 2000w52 Monday, January 1, 2001 --> Mon --> 2001w01 Tuesday, January 2, 2001 --> Tue --> 2001w01 Wednesday, January 3, 2001 --> Wed --> 2001w01
    --Chris

    e-mail jcwren
(kudra: 4 jan is in week 1) RE: Date::Manip week-of-year
by kudra (Vicar) on Oct 04, 2000 at 15:55 UTC
    Just a side note--I realize the problem is solved, so this is more of a response to runrig's 'arbitrary' comment--by definition, the first week of the year is whatever week includes 4 January, so it's possible for the 31st of December to be part of week 1 of the new year, or for 1 January to be part of the last week of the old year. You won't notice this with 2000-1, but 2001-2 doesn't divide as neatly.
      Ok, question:
      <dunce cap> Why is the first week defined that way? </dunce cap>
      eerrr.... maybe I had best leave it on....

      Roy Alan

        I believe Date::Manip treats the first week of the year as the week that January 1st is in. A week is still Sunday -> Saturday (or Monday -> Sunday?), so if January 1st is on a Friday, several of the days at the end of December will be treated as being part of the first week of that year.

        How would you define it? With varying "week" boundaries? One year a week starts on a Wednesday, the next it starts on a Friday? Would you break up a week into two pieces, calling the first piece week 52 and the 2nd piece week 1?

        It makes sense in a weird sort of way.

RE: Date::Manip week-of-year
by nop (Hermit) on Oct 04, 2000 at 07:02 UTC
    Output I get:
    Saturday, December 30, 2000 --> Sat --> 2000w52 Sunday, December 31, 2000 --> Sun --> 2000w01 Monday, January 1, 2001 --> Mon --> 2001w01
Re: Date::Manip week-of-year
by nop (Hermit) on Oct 04, 2000 at 07:12 UTC
    Thanks jcwren -- seems I had an older version Date::Manip -- got a newer one from ActiveState (5.39) and the problem went away -- Thanks!
RE: Date::Manip week-of-year
by runrig (Abbot) on Oct 04, 2000 at 06:29 UTC
    It's sort of arbitrary which week you want to call it. Since most of that week is in the new year, you may as well call it the first week of the new year.

    Update: I just noticed, is that '*2000*' in your post a typo, or should it be '*2001*'?

    Another update: ok, nevermind...
      Nope, I mean 2000, as I typed. :(
RE: Date::Manip week-of-year
by nop (Hermit) on Oct 04, 2000 at 07:05 UTC
    Output I get:
    Saturday, December 30, 2000 --> Sat --> 2000w52 Sunday, December 31, 2000 --> Sun --> 2000w01 Monday, January 1, 2001 --> Mon --> 2001w01