 |
|
 |
There are at least three methods of calculating week number:
1) first weeks starts on the 1 Jan
2) ISO 8601 standard, with weeks starting Sunday or Monday
3) And good old bill gates method..
Look at: weekOfYear at www.codecogs.com
|
|
|
|
 |
|
 |
Hi!
The nitpicker is here.
I'm Swedish, so I don't exactly have any syntactical problems reading the source code documentation and comments. But it sure looks strange when you are used to read code and comments in English.
My first tip for you on your future programming trip is to never, ever again write comments in any other language than English (or, perhaps, in a meta-programming language...). That is mainly for your own sake. You need to get used to formulate yourself in English to be able to define precise questions on programming problems for others to solve, if that issue ever comes up - which it will. Writing code comments in English will help you with this. I know you have it in a TODO. But, the next time, don't use a TODO for it, rather do it right immediately.
To my second tip: Without mentioning anything about the correctness of your leap year algorithm, writing
if((nYear%4)==0)
bIsLeapYear = true;
else
bIsLeapYear = false;
instead of
bIsLeapYear = (nYear % 4) == 0;
will not make the code easier to read when the statement is as short as that. For longer statements and complex boolean evaluations, I agree that your version can make the code more readable, but not here.
Finishing off with a third advice - translated from Swedish:
if(bIsLeapYear && nMonth > 2)
nNumDaysOfYear++;
That's not a documented statement. You've just wasted some electrons on the row above the code, which is perfectly self documenting - a school example of such a thing, really. But, please, only add comments that add something beyond what the code clearly says. If you had written the code as bad as this:
if(l&&m>2)n++;
Then your comment would probably be needed, but as you wrote it self documenting, there was no need to!
--
Dad, how strange it is that the pig can speak. *thoughtful pause* It must have lost its "oink". (my 3-year old daughter Moa, while watching Babe)
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. (Douglas Adams)
|
|
|
|
 |
|
 |
Thank you for your feedback.
Currently I'm working on rewriting the whole class, so all comments are welcome. It's always nice to learn something new.
/ Patrik
”If knowledge can create problems, it is not through ignorance that we can solve them.”
Isaac Asimov
|
|
|
|
 |
|
 |
Why not base your class on CDateTime or COleDateTime, that way you get all that extra functionality.
Unless you have a problem with MFC?
Gerard
|
|
|
|
 |
|
 |
A few extra things.
Is the first week of the year the first complete week, or the first incomplete week.
Say for instance the 1st January is a Saturday, is the 2nd of January in week 2, or Week 1. Many calendars show it as week 2.
Also, why do all the maths yourself, use the C time functions, so to get the date for week 10 of the year:
Fill in a struct tm with the year, then fill in the month as January and the day as 7*10, then use mktime to create your time_t.
You should never have to worry about leapyear code if you use time_t and struct tm.
Gerard
|
|
|
|
 |
|
 |
The first week of the year is country dependent. For some it's the week containing the first day of the year, for some others the week containing at least 4 days of january and for some others it's the first full week of january.
Eric
|
|
|
|
 |
|
 |
For running it on an embedded device without resources adequate for MFC?
--
Dad, how strange it is that the pig can speak. *thoughtful pause* It must have lost its "oink". (my 3-year old daughter Moa, while watching Babe)
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. (Douglas Adams)
|
|
|
|
 |
|
 |
English, just like for you is not my primary language, but I read it more easily than swedish...So I'm unable to read any comment from your code!
Beside that, I saw two problems:
First, the way used to calculate the leap year is wrong (just check for 2000!) The correct way is:
(Year % 4 = 0) AND ((Year % 100 <> 0) OR (Year % 400 = 0))
Second, the way to calculate the first week of the year is country dependent (search for example in then MSDN with the keywords GetLocaleInfo LOCALE_IFIRSTWEEKOFYEAR).
Could you correct these points?
Eric
|
|
|
|
 |
|
 |
Thanks for the feedback. I will look into these matters as soon as I get the time.
”If knowledge can create problems, it is not through ignorance that we can solve them.”
Isaac Asimov
|
|
|
|
 |
|
 |
To answer one of your messages, just search for the keyword GetLocaleInfo and follow the link "see Locale Information".
Eric
|
|
|
|
 |
|
 |
Very nice, and brave in today's environment. I appreciate the simplicity and directness of the code. I like the comment "TODO: Translate to english" which I was going to suggest but obviously don't need to. Some may say, "Where is the demo project?", I for one don't need one. I can use your work as it is. Thanks for saving me the trouble of figuring out the algorithms.
BTW, I have no complaint about your English. Good luck against the radical flesh-renders who may respond with their usual crap, just ignore them. You did fine.
Hot number, week date.
|
|
|
|
 |
|
 |
Thank you for your kind words. It feels encouraging to hear as this is my first article.
”If knowledge can create problems, it is not through ignorance that we can solve them.”
Isaac Asimov
|
|
|
|
 |