It it now a leap year?
Karl Larsen
k5di at zianet.com
Thu Aug 9 00:57:13 UTC 2007
Antonio Olivares wrote:
>> ----- Original Message ----
>> From: Karl Larsen <k5di at zianet.com>
>> To: For users of Fedora <fedora-list at redhat.com>
>> Sent: Wednesday, August 8, 2007 5:07:49 PM
>> Subject: Re: It it now a leap year?
>>
>> Mike - EMAIL IGNORED wrote:
>>> On Thu, 09 Aug 2007 06:02:27 +0930, Tim wrote:
>>>
>>>> Andrew Parker:
>>>>>> For bash the following will display 061 if its currently a leap year,
>>>>>> 060 otherwise
>>>>>>
>>>>>> date -d "$(date +%Y)/03/01" +%j
>>>> Kevin J. Cummings:
>>>>> It doesn't work with dates after 2037/03/01 ....
>>>> Leaving you with thirty years to develop a solution, or spend a few
>>>> minutes pondering whether to bother... ;-)
>>>>
>>>> But seriously, although some might think you don't need to worry about
>>>> such things, there are programs that will need to do some work using a
>>>> date from the future. The matter is more urgent than immediately
>>>> obvious.
>>>>
>>> [...]
>>>
>>> My program deals only with the present and the immediate past.
>>> Since in 30 years I hope to celebrate (?) my 98th, it would be
>>> quite interesting to see if the problem still concerns me. :)
>>>
>>> Mike.
>>>
>>>
>> In a terminal type $cal 2 2008 and you will see February has 29 days
>> when it is leap year according to Google. Do $cal 2 2007 and you will
>> see this:
>>
>> [karl at k5di ~]$ cal 2 2007
>> February 2007
>> Su Mo Tu We Th Fr Sa
>> 1 2 3
>> 4 5 6 7 8 9 10
>> 11 12 13 14 15 16 17
>> 18 19 20 21 22 23 24
>> 25 26 27 28
>>
>> So no leap year in 2007
>>
>>
>> --
>>
>> Karl F. Larsen, AKA K5DI
>> Linux User
>> #450462 http://counter.li.org.
>>
>> --
>
> I like your solution Karl. Not to make less of the other answers provided. Rick provided a C+ program which is awesome. I like all the answers. But Karl's way of looking at it, in a leap year February has 29 days, so check by generating a calendar for the month of February month 2 and the year and if it has 29 days, it is a leap year, if it does not then no leap year. No need to worry about if the year ends in two zeros, which is divisibe by 100 without a remainder. If the number of the year ends in a 4,8,12,16,20,24, any multiple of 4, it is a leap year. There is a rule
> cal 2 year where year is a number from 1 to 9999 after that the program does not work.
>
> 1700 is a leap year, 1704,1708,1712,1716, ... and so on
>
> The rule
> if year modulo 400 is 0 then leap
> else if year modulo 100 is 0 then no_leap
> else if year modulo 4 is 0 then leap
> else no_leap
> where modulo is the remainer when the year divided by 400 is 0, leap year
> else if the remainder is zero when the year is divided by a 100, leap year
> else if the remainder is zero when the year is divided by 4, then leap yaer
> else no leap year
>
> [olivares at localhost ~]$ cal --help
> cal: invalid option -- -
> usage: cal [-13smjyV] [[month] year]
> [olivares at localhost ~]$ cal 99999
> cal: illegal year value: use 1-9999
> [olivares at localhost ~]$ cal 2 1700
> February 1700
> Su Mo Tu We Th Fr Sa
> 1 2 3
> 4 5 6 7 8 9 10
> 11 12 13 14 15 16 17
> 18 19 20 21 22 23 24
> 25 26 27 28 29
>
> [olivares at localhost ~]$ cal 2 1704
> February 1704
> Su Mo Tu We Th Fr Sa
> 1 2 3 4 5
> 6 7 8 9 10 11 12
> 13 14 15 16 17 18 19
> 20 21 22 23 24 25 26
> 27 28 29
>
> [olivares at localhost ~]$ cal 2 1708
> February 1708
> Su Mo Tu We Th Fr Sa
> 1 2 3 4 5 6 7
> 8 9 10 11 12 13 14
> 15 16 17 18 19 20 21
> 22 23 24 25 26 27 28
> 29
>
> [olivares at localhost ~]$ cal 2 1712
> February 1712
> Su Mo Tu We Th Fr Sa
> 1 2
> 3 4 5 6 7 8 9
> 10 11 12 13 14 15 16
> 17 18 19 20 21 22 23
> 24 25 26 27 28 29
>
> [olivares at localhost ~]$
>
> ..., every 4 years, there is a guaranted leap year! Unless we die of course, there is no leap year for us.
>
> Great solution Karl!
>
> Regards,
>
> Antonio
>
>
>
>
>
>
> ____________________________________________________________________________________
> Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out.
> http://answers.yahoo.com/dir/?link=list&sid=396545433
>
glad you like it. The cal program is VERY powerful.
--
Karl F. Larsen, AKA K5DI
Linux User
#450462 http://counter.li.org.
More information about the fedora-list
mailing list