![]() |
Math + Leap Years = Frustration
Mathematically, a leap year is a year that can be divided by 4, but not by 100 OR can be divided by 400. This can be represented by
Code:
( ( (year % 4) == 0) && ( (year % 100) != 0) ) || ( (year % 400) == 0)However there seems to be something off about it.. Take year 700 for example. 700 is divisible by both 4 and 100, and not by 400, so therefore it's not a leap year. However year 704 is divisible by 4, and not by 100, so therefore it should be a leap year. But since leap years occur every 4 years, and 704 - 4 = 700, shouldn't 700 also be a leap year? So, anyone got an idea how that works out? :confused: |
Quote:
You correctly explained the Gregorian convention for leap years at the beginning of your post. It clearly implies that leap years usually occur every 4 years - but not always! More details if needed: http://en.wikipedia.org/wiki/Leap_year |
You can use the built-in OS function to determine this, that way, if Apple has to update tha algorithm, your code doesn't need to change.
http://developer.apple.com/documenta...ibexslt.3.html |
Our calendar is so bizarre.
We need a metric calendar.:D And cpragman had the right idea. Don't try to reinvent the wheel unless you have to, this logic has already been figured out. Most OS's will have some way to grab this programmatically. |
Since the next 'leap year that isn't' doesn't occur until 2100, I don't think any of us need to worry, but here it is using both methods describe in http://en.wikipedia.org/wiki/Leap_year ;)
PHP Code:
2009 is not a leap year --- 2009 is not a leap year 2010 is not a leap year --- 2010 is not a leap year 2011 is not a leap year --- 2011 is not a leap year 2012 is a leap year! --- 2012 is a leap year! 2013 is not a leap year --- 2013 is not a leap year 2014 is not a leap year --- 2014 is not a leap year 2015 is not a leap year --- 2015 is not a leap year 2016 is a leap year! --- 2016 is a leap year! 2017 is not a leap year --- 2017 is not a leap year 2018 is not a leap year --- 2018 is not a leap year 2019 is not a leap year --- 2019 is not a leap year 2020 is a leap year! --- 2020 is a leap year! 2021 is not a leap year --- 2021 is not a leap year 2022 is not a leap year --- 2022 is not a leap year 2023 is not a leap year --- 2023 is not a leap year 2024 is a leap year! --- 2024 is a leap year! 2025 is not a leap year --- 2025 is not a leap year 2026 is not a leap year --- 2026 is not a leap year 2027 is not a leap year --- 2027 is not a leap year 2028 is a leap year! --- 2028 is a leap year! 2029 is not a leap year --- 2029 is not a leap year 2030 is not a leap year --- 2030 is not a leap year 2031 is not a leap year --- 2031 is not a leap year 2032 is a leap year! --- 2032 is a leap year! 2033 is not a leap year --- 2033 is not a leap year 2034 is not a leap year --- 2034 is not a leap year 2035 is not a leap year --- 2035 is not a leap year 2036 is a leap year! --- 2036 is a leap year! 2037 is not a leap year --- 2037 is not a leap year 2038 is not a leap year --- 2038 is not a leap year 2039 is not a leap year --- 2039 is not a leap year 2040 is a leap year! --- 2040 is a leap year! 2041 is not a leap year --- 2041 is not a leap year 2042 is not a leap year --- 2042 is not a leap year 2043 is not a leap year --- 2043 is not a leap year 2044 is a leap year! --- 2044 is a leap year! 2045 is not a leap year --- 2045 is not a leap year 2046 is not a leap year --- 2046 is not a leap year 2047 is not a leap year --- 2047 is not a leap year 2048 is a leap year! --- 2048 is a leap year! 2049 is not a leap year --- 2049 is not a leap year 2050 is not a leap year --- 2050 is not a leap year 2051 is not a leap year --- 2051 is not a leap year 2052 is a leap year! --- 2052 is a leap year! 2053 is not a leap year --- 2053 is not a leap year 2054 is not a leap year --- 2054 is not a leap year 2055 is not a leap year --- 2055 is not a leap year 2056 is a leap year! --- 2056 is a leap year! 2057 is not a leap year --- 2057 is not a leap year 2058 is not a leap year --- 2058 is not a leap year 2059 is not a leap year --- 2059 is not a leap year 2060 is a leap year! --- 2060 is a leap year! 2061 is not a leap year --- 2061 is not a leap year 2062 is not a leap year --- 2062 is not a leap year 2063 is not a leap year --- 2063 is not a leap year 2064 is a leap year! --- 2064 is a leap year! 2065 is not a leap year --- 2065 is not a leap year 2066 is not a leap year --- 2066 is not a leap year 2067 is not a leap year --- 2067 is not a leap year 2068 is a leap year! --- 2068 is a leap year! 2069 is not a leap year --- 2069 is not a leap year 2070 is not a leap year --- 2070 is not a leap year 2071 is not a leap year --- 2071 is not a leap year 2072 is a leap year! --- 2072 is a leap year! 2073 is not a leap year --- 2073 is not a leap year 2074 is not a leap year --- 2074 is not a leap year 2075 is not a leap year --- 2075 is not a leap year 2076 is a leap year! --- 2076 is a leap year! 2077 is not a leap year --- 2077 is not a leap year 2078 is not a leap year --- 2078 is not a leap year 2079 is not a leap year --- 2079 is not a leap year 2080 is a leap year! --- 2080 is a leap year! 2081 is not a leap year --- 2081 is not a leap year 2082 is not a leap year --- 2082 is not a leap year 2083 is not a leap year --- 2083 is not a leap year 2084 is a leap year! --- 2084 is a leap year! 2085 is not a leap year --- 2085 is not a leap year 2086 is not a leap year --- 2086 is not a leap year 2087 is not a leap year --- 2087 is not a leap year 2088 is a leap year! --- 2088 is a leap year! 2089 is not a leap year --- 2089 is not a leap year 2090 is not a leap year --- 2090 is not a leap year 2091 is not a leap year --- 2091 is not a leap year 2092 is a leap year! --- 2092 is a leap year! 2093 is not a leap year --- 2093 is not a leap year 2094 is not a leap year --- 2094 is not a leap year 2095 is not a leap year --- 2095 is not a leap year 2096 is a leap year! --- 2096 is a leap year! 2097 is not a leap year --- 2097 is not a leap year 2098 is not a leap year --- 2098 is not a leap year 2099 is not a leap year --- 2099 is not a leap year 2100 is not a leap year --- 2100 is not a leap year |
So according to that php code, Felix's IF statement is perfectly valid.
It is that easy. |
I remember I had to write a program for a class once that had to find out if a year was a leap year, but then it also had to take the date and figure out what day of the week it was as well... Finding the day of the week was an interesting problem...
|
Quote:
I am writing a calendar program in C++ that amongst other thing will take any date in time (ex. Jan 5, 1623) and tell you what day of the week it is. I needed to know which years are leap years to balance out my functions, but it turns out I can get around it by using the Doomsday Rule. :rolleyes: |
Quote:
|
Quote:
Besides, I like reinventing the wheel if it's challenging enough :rolleyes: Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
I have to say that the OS X NSCalendar and related objects are really useful. I recently wrote a little app that calculates Easter and all moveable Christian feasts for any given year. (Niche market!) |
Quote:
Day of the week? iDayOfWeek = DatePart(DateInterval.Weekday, today) :p |
Quote:
|
|
Quote:
|
Beats the heck out of me.
|
is this the thread for calendar antics
$ cal 9 1752 |
Translation please? Someone?
|
Quote:
|
Quote:
|
Quote:
Code:
September 1752And that from and after the said first Day of January 1752, the several Days of each Month shall go on, and be reckoned and numbered in the same Order; and the Feast of Easter, and other moveable Feasts thereon depending, shall be ascertained according to the same Method, as they now are, until the 2nd Day of September in the said Year 1752 inclusive; Here's a link with TMI (too much information): The Best of Dates, The Worst Of Dates-HI- |
Wow, my day finder didn't account for that madness. I guess that means that I'm way off at this point. I should point that out to my professor though so that all CS students following in my footsteps can suffer...
@fazstp -- Where did that thread go anyway? :D |
| All times are GMT -5. The time now is 12:35 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.