in reply to Re: Calculating latest 'Sunday' date on the first of the month
in thread Calculating latest 'Sunday' date on the first of the month

hey that code is again causing problem now... instead of calculating starting of this week its calculating last Sunday i.e, 29/08/2010 as the starting of the week. help!!
  • Comment on Re^2: Calculating latest 'Sunday' date on the first of the month

Replies are listed 'Best First'.
Re^3: Calculating latest 'Sunday' date on the first of the month
by roboticus (Chancellor) on Sep 06, 2010 at 10:26 UTC

    Cicatrix:

    The code ikegami gave you, and the result you reported are what I'd expect from the specifications you gave in your original post. So if you're getting something incorrect, you need to be more clear in specifying the problem.

    Also, you report the problem several days after accepting the answer provided. I suspect that you didn't adequately test the code before reporting success. Normally, you want to test code against all the different types of input cases that will be encountered. So rather than setting $d = DateTime->today() only, you'd initialize $d to various dates, and compare the results of the code with the date you'd expect.

    I suggest you try Test::More and related packages (if you don't use them now), and use them to build tests for code before accepting it. You'll find that the tests, if written well, can also serve as documentation for your code, as it will show future programmers what behaviour to expect for the unusual cases.

    ...roboticus

Re^3: Calculating latest 'Sunday' date on the first of the month
by ikegami (Patriarch) on Sep 06, 2010 at 16:27 UTC
    I've found your original post very unclear. (It's filled with grammar errors for starters.) I specified what I thought you meant and I provided a solution for that. If you want something else, specify what you want.