[Qt-interest] Iterate over weeks of a timespan
Thiago Macieira
thiago.macieira at trolltech.com
Wed Jan 21 19:07:23 CET 2009
Em Quarta-feira 21 Janeiro 2009, às 13:59:55, Sven Grunewaldt escreveu:
> The first problem is:
> I can't figure out the last Week of a year.
>
> The second problem is:
> If the startMonth or endMonth happens to be at the very beginning or end
> of a year, the week could 53 for the startMonth or 1 for the endMonth,
> which breaks the whole for-loop.
> I think I can solve this for myself, I only mention it to avoid confusion.
>
> Sadly I'm at a complete loss how to solve this puzzle.
> It would be great if someone could give me a pointer how to do it
> correctly.
Hi Sven
I don't think this is a C++ problem. I think the problem is the problem not
being defined well-enough.
As you said yourself, a year can have 52 or 53 weeks. Also, the first 3 days of
a year can be part of the last year and the last 3 days of a year can be part
of the next.
Note that January 4 of any year is always on Week 1. If that January 4 is a
Sunday, then the year has 53 weeks (and all days in December belong to that
year). If January 4 is Monday, Tuesday, or Wednesday, the days before it are
in the previous year; if it's Thursday, Friday or Saturday (any year) or
Wednesday (leap year), there are days in December belonging to the next year.
You should read http://en.wikipedia.org/wiki/ISO_week_date for more
information. You could also choose to implement a simplified date system, by
having partial weeks at the beginning and end of the year (week 0 and week
53).
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Software Engineer - Nokia, Qt Software
Qt Software is hiring - ask me
Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090121/6993dc7e/attachment.bin
More information about the Qt-interest-old
mailing list