finding Day code based on date.
-
Hai friends, Here is my logic to find the day code. if any body can please suggest a better logic, or if any body can validate the logic and find any bugs there, i would apprieciate it.
int offset[12]={0,31,59,90,120,151,181,212,243,273,304,334},l=0; if((((curyear%4==0) && (curyear%100!=0)) || (curyear%400==0)) && (curmonth>1)) l=1; daycode=offset[curmonth]+curdate+l;
opinions please.Why not just use DateTime.DayOfYear?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
-
the main important thing how to prove the correctness of ur function
researche in mobile databases
-
Why not just use DateTime.DayOfYear?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
-
of course, but the user will supply date month and year separately. if i had to use CTime class, then, i had to copy these values to that CTime right? but i think even that can be possible. thanks for your suggestion.
int d=new DateTime(2007, 10, 26).DayOfYear;
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
-
I also recomend testing invalid values and testing for proper failures as well. Quite often we just test for success and don't test for failure. Failing in a predictable manner of often times more important than being correct. Correct is always predictable. Failing often times is not.
-
int d=new DateTime(2007, 10, 26).DayOfYear;
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
-
I also recomend testing invalid values and testing for proper failures as well. Quite often we just test for success and don't test for failure. Failing in a predictable manner of often times more important than being correct. Correct is always predictable. Failing often times is not.
-
chandu004 wrote:
just supply some valid values to it and see.
Don't let Prof. Knuth know your secret. :rolleyes:
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
century years rules (of course if you need to deal with): (1) Century years aren't leap years (though they're divisible by 4). (2) Century years divisible by 400 (as 2000, for instance) are leap years. Maybe you have to further strain your brain. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
The Gregorian calender doesn't have any leapyear exception rules for above 400. IF they did, IIRC the next toggle points would have been 2000 and 10,000. Instead we're adding single leap seconds as needed at new years to keep everything in sync.
-- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
-
The Gregorian calender doesn't have any leapyear exception rules for above 400. IF they did, IIRC the next toggle points would have been 2000 and 10,000. Instead we're adding single leap seconds as needed at new years to keep everything in sync.
-- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
dan neely wrote:
IIRC the next toggle points would have been 2000 and 10,000
I doubt that; Wikipedia[^] gives some arguments for a leapyear correction every 4000 or 8000 years.
dan neely wrote:
Instead we're adding single leap seconds as needed at new years to keep everything in sync
That can not be correct: with a one second correction every year you would need 60 * 60 * 24 = 86400 years to shift time by one day, not quite sufficient. [added] Again Wikipedia[^] explains the purpose of leap seconds.[/added] :) -- modified at 18:06 Thursday 1st November, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google