There are so many ways this could be done using Date::Manip, all of them slightly complex... ;)

But there is one other complexity to consider not related to manipulating the particular date module you use. And that is the concept of falling back to the starting date for a given week as the header for your week's summary.

What happens if the first day of the year is Wednesday, and you summarize everything that occurred in the first week of the year, given that the weeks begins on Sunday? You fall back to a previous year. Is this desired behavior?

What happens if the first day of the month is Wednesday, and you summarize everything that occurred in the first week of the month? ...same sort of problem. Things that happened on Wednesday April 1st will fall under the heading of the last Sunday in March. Again, is this desired behavior?

Some companies will actually use what they call a 4-5-4 calendar, where years always start on Sunday, and months always start on Sunday. This simplifies such problems. But then your company months start and end a day or two or three differently from real-world months. It takes a little getting used to, but ensures that when you're looking at everything that happened in week 1 of the year, week 1 started on a Sunday, and the entire week falls into the same year. And you can look at weeks of months in the same way; weeks never span months under such a calendar.


Dave


In reply to Re: Convert Week Of Year to Date by davido
in thread Convert Week Of Year to Date by ear

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.