I ran it through dates from 01 Jan 13 to 31 Dec 2099 and it works
perfectly.  Now I just need to adjust it to include the date in the format
yyyy-ww.


On Sat, Dec 14, 2013 at 12:54 PM, Wols Lists <antli...@youngman.org.uk>wrote:

> On 14/12/13 19:44, Kevin King wrote:
> > I'll have to run this through some testing, as it's definitely simpler
> than
> > the solution I came up with.
> >
> Read the notes at the top, explaining the logic. Satisfy yourself that's
> correct (it is :-), then satisfy yourself that the code actually
> implements it.
>
> What did you come up with?
>
> Cheers,
> Wol
> >
> > On Sat, Dec 14, 2013 at 12:40 PM, Wols Lists <antli...@youngman.org.uk
> >wrote:
> >
> >> On 14/12/13 19:20, Kevin King wrote:
> >>> The 8601 week is based on the count of Thursdays but the week starts on
> >> the
> >>> Monday and ends on the following Sunday.  I haven't tested this, but is
> >>> this accounted for in your logic?  And what about the situation where
> >> Jan 1
> >>> (on a Fri, Sat, Sun) is in the 52nd or 53rd week of the prior year?
> >>>
> >> YES IT IS :-)
> >>
> >> If you read my code, it takes the given date, goes back to the start of
> >> the week, then goes forward to the Thursday. It then works out where in
> >> its year that Thursday falls. This is guaranteed (if the maths is
> >> correct) to give the correct answer.
> >>
> >> Cheers,
> >> Wol
> >>>
> >>> On Sat, Dec 14, 2013 at 12:14 PM, Wols Lists <antli...@youngman.org.uk
> >>> wrote:
> >>>
> >>>> On 14/12/13 18:53, Kevin King wrote:
> >>>>> The most challenging date math we've faced recently (a real project)
> is
> >>>> the
> >>>>> ISO 8601 week calculation.  Extremely easy to introduce an off-by-one
> >>>> error!
> >>>>>
> >>>> THAT'S MY CODE!
> >>>>
> >>>> And how long has it been on Pickwiki? Absolutely ages!
> >>>>
> >>>> How does your solution compare with mine? Six lines of code :-)
> >>>> http://www.pickwiki.com/cgi-bin/wiki.pl?IsoWeekNum
> >>>>
> >>>> I think my code was lifted for this ...
> >>>> http://www.pickwiki.com/cgi-bin/wiki.pl?DateUtility
> >>>> Which had the "off by one" introduced :-)
> >>>>
> >>>> Cheers,
> >>>> Wol
> >>>>>
> >>>>> On Sat, Dec 14, 2013 at 11:13 AM, Wols Lists <
> antli...@youngman.org.uk
> >>>>> wrote:
> >>>>>
> >>>>>> On 14/12/13 16:48, Dan Fitzgerald wrote:
> >>>>>>> Kevin: I'd take the month (verifying; gigo), then run it through a
> >> case
> >>>>>> statement to determine the number of days in that month (sounds
> like a
> >>>>>> handy subroutine to have in the toolbox). Then I'd convert to get
> the
> >>>> day
> >>>>>> of the week, another case statement to get the number of days past
> >>>>>> Thursday, do the math from the last DOM internal date, oconv the
> >> result,
> >>>>>> and grab a cup of dark roast. There are probably more efficient
> ways,
> >>>> but
> >>>>>> that's how I'd work it through my head in an interview.
> >>>>>>
> >>>>>> This is pretty much the same problem as "current week of the year"
> :-)
> >>>>>>
> >>>>>> Can't remember off the top of my head, but it's *extremely* easy to
> >> make
> >>>>>> an "off by one" error - I remember someone copying my Pickwiki code
> >> and
> >>>>>> getting it wrong, introducing the very error I'd fixed.
> >>>>>>
> >>>>>> Cheers,
> >>>>>> Wol
> >>>>>> _______________________________________________
> >>>>>> U2-Users mailing list
> >>>>>> U2-Users@listserver.u2ug.org
> >>>>>> http://listserver.u2ug.org/mailman/listinfo/u2-users
> >>>>>>
> >>>>> _______________________________________________
> >>>>> U2-Users mailing list
> >>>>> U2-Users@listserver.u2ug.org
> >>>>> http://listserver.u2ug.org/mailman/listinfo/u2-users
> >>>>>
> >>>>
> >>>> _______________________________________________
> >>>> U2-Users mailing list
> >>>> U2-Users@listserver.u2ug.org
> >>>> http://listserver.u2ug.org/mailman/listinfo/u2-users
> >>>>
> >>> _______________________________________________
> >>> U2-Users mailing list
> >>> U2-Users@listserver.u2ug.org
> >>> http://listserver.u2ug.org/mailman/listinfo/u2-users
> >>>
> >>
> >> _______________________________________________
> >> U2-Users mailing list
> >> U2-Users@listserver.u2ug.org
> >> http://listserver.u2ug.org/mailman/listinfo/u2-users
> >>
> > _______________________________________________
> > U2-Users mailing list
> > U2-Users@listserver.u2ug.org
> > http://listserver.u2ug.org/mailman/listinfo/u2-users
> >
>
> _______________________________________________
> U2-Users mailing list
> U2-Users@listserver.u2ug.org
> http://listserver.u2ug.org/mailman/listinfo/u2-users
>
_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to