Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Leap Years 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

ok I know I could go an get the Leap Year module and use
Code:
  use Date::Leapyear;
  if ( isleap(yyyy) ) {
    ...
  }

is Date a default loaded module?

anyways I was thinking, is it just as easy to use the MOD operator (%) and divide by 4?

if there is a decimal point remainder then it isn't a leap year, is that correct?



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
nope , just thought , Rodney!!!!

decimal remainder only if using divide!

MOD would be either 0,1,2,3 isn't it?

So
Code:
2000 % 4 = 0
2001 % 4 = 1
2002 % 4 = 2
2003 % 4 = 3
2004 % 4 = 0

is that right?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
You could always cheat and see how they did it in the module or you could study the isleap sub routine from the module
Code:
sub isleap {
    my ($year) = @_;
    return 1 if (( $year % 400 ) == 0 ); # 400's are leap
    return 0 if (( $year % 100 ) == 0 ); # Other centuries are not
    return 1 if (( $year % 4 ) == 0 ); # All other 4's are leap
    return 0; # Everything else is not
}

Keith
 
Cheers, Keith.

thought it was something simple with the MOD operator!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Is not only one dividing.

It is for my working life time ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Tsk, tsk, so unprofessional...

I like it!

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
I'm still confused over the calcualtion, why is it not one simple divide.

ok , i've done my homework,


But I don't get it, every 4 years is a leap year nes pas?

So why is 2100 not a leap year it's divisible by 4 without a remainder, so should be a leap year...

does that mean in 2100 it will be 8 years before they get a leap year...

2096 then 2104 , so a leap year is not every 4 years... I'm very confused.

Can any one explain please?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
All these links seem to say is evey 4 years is a leap year unless except those years when someone in power decides that it isn't.

I thought the whole point in a leap year was to adjust the calendar on a scientific / mathematical equation because it actually takes 365.25 days to rotate the sun. so evey 4 years the quter of a day adds up to an extra day.

So why in between 2096 and 2104 all of a sudden it's going to take the world 365.125 days per year to circle the sun?








"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Hi

1MDF said:
it actually takes 365.25 days to rotate the sun.
Negative.

Solar year said:
The number of mean solar days in a vernal equinox year has been oscillating between 365.2424 and 365.2423 for several millennia and will likely remain near 365.2424 for a few more.
( See Solar year in Wikipedia. )

So the four-yearly +1 full day correction is not a complete solution, more fine tuning is needed. Even more, neither the currently used Gregorian calendar's plus/minus day manipulations give correct solution.

Feherke.
 
Thanks feherke.

So like usual we don't do the job properly and make additional adjustments , which again are not accurate.

Not sure why i'm bothered it's not liek it really is the year 2009 , or Jesus was born in December , and a whole host of other date innacuracies.

Like I said, for my lifetime divide by 4 will do just nicely!



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top