Re: It it now a leap year?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2007-08-08 at 12:31 -0400, Mike - EMAIL IGNORED wrote:
> Is there a system call or variable that will
> tell me if it is now a leap year, or should I
> do the arithmetic?

I don't know of one.  The calculation is fairly simple.  If the year is
evenly divisible by 100 (a "century year"), it must also be evenly
divisible by 400 to be a leap year.  For example, 1900 was a not a leap
year, while 2000 was.  The next century year that will be a leap year is
2400 (if we're still using the Gregorian calendar in the 25th century).

For non-century years, if it's evenly divisible by 4, it's a leap year.

Essentially, in C:

    if (year % 100 == 0) {
	if (year % 400 == 0)
	    printf("%d is a leap year\n", year);
	else
	    printf("%d is NOT a leap year\n", year);

    } else if (year % 4 == 0) {
	printf("%d is a leap year\n", year);

    } else {
	printf("%d is NOT a leap year\n", year);

    }

Sure seems as though it could be stuffed into the C library.  It's
pretty trivial.
----------------------------------------------------------------------
- Rick Stevens, Principal Engineer             rstevens@xxxxxxxxxxxx -
- CDN Systems, Internap, Inc.                http://www.internap.com -
-                                                                    -
-                       When in doubt, mumble.                       -
----------------------------------------------------------------------

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux