By now, you probably have already heard that this year is a leap year. And you have a good understanding of what a leap year is and why we have them. But if you hadn’t already heard about 2012 being a leap year, or didn’t have a calendar handy, would you know how to determine which years have an extra day in February? If your answer is, “That’s simple! Just divide the year by 4 and if there is no remainder, it’s a leap year,” you would be right…most of the time. But there’s more to it than that.
Leap years are needed to keep our calendar in alignment with the earth’s revolutions around the sun. In the Gregorian calendar, a normal year consists of 365 days. But the actual length of time it takes for the Earth to revolve once about the sun is 365.2422 days. Therefore, a “leap year” of 366 days is used once every four years to “catch up” for the three years between leap years that have only 365 days and are short by about 6 hours. However, the deficit is not precisely 6 hours per year. It’s slightly less than that — about 11 minutes per year. So, eventually, that difference in time needs to be accounted for as well.
To eliminate that extra fraction of a year that gets added back in every 4 years, the Gregorian calendar skips the leap year when the year is evenly divisible by 100 but is not evenly divisible by 400. For example, 1900, 2100, and 2200 are not leap years, but 2000 and 2400 are leap years.
The IBM i operating system uses this same method to determine which years have 365 days and which ones have 366 for you, so you don’t have to worry about remembering the rules. And it’s all handled automatically without having to set anything up for leap year. But you may be left wondering “then why is there a Leap Year Adjustment (QLEAPADJ) system value and what is it used for?”
The QLEAPADJ system value is used to adjust the system calendar algorithm for the leap year in different calendar systems. For the Gregorian calendar system, the leap-year adjustment is 0 (meaning that no adjustment is needed). But other calendar systems may require an adjustment. For example, the Thai Buddhist calendar year of 2555 is the same as 2012 in the Gregorian calendar. Because 2555 is a leap year, you divide 2555 by 4; this leaves a remainder of 3. Therefore to adjust the system calendar for the Thai Buddhist calendar, the QLEAPADJ system value should be set to 3. For systems running with V5R4 or earlier, this system value can be changed to the value determined by this calculation above. But in 6.1 and later releases, you can no longer change this system value. Instead, the system calculates the QLEAPADJ value for you, based on the Year Offset (YEAROFS) defined in the system time zone (QTIMZON).
The year offset is the number of years difference between the current year in the calendar system used with a time zone and the current Gregorian year. For example, if the current Gregorian year is 2012 and the current year in the Thai Buddhist calendar is 2555, the year offset (in theory) would be +543 (2555 minus 2012). But the year 2555 is well out of the range of supported dates in the IBM i operating system, so a system in Thailand would need to choose a different base year that is in the supported range, such as 1955. The system will run in the current Gregorian year (2012) and will set the year offset in the QTIMZON time zone object to -57 (1955 minus 2012). The last 2 digits of the year will still appear correctly (55).
The operating system then uses the year offset when calculating various date-time related values, such as the formatted date and the day-of-week. To determine the correct date for a specific time zone, the system takes a date-time value stored in Coordinated Universal Time (UTC) and applies the time zone offset (the time difference between the time zone and UTC), adjusted for Daylight Saving Time, if necessary, and applies the year offset.
With the year offset support added in 6.1, the system automatically sets the QLEAPADJ system value by using the current year and the Year offset to calculate it. The formula ((Current Year + Year Offset) // 4 = QLEAPADJ) is used to get the leap days to coincide with the Gregorian leap days. The day of week calculations will also now appear correctly (i.e., 2/15 is a Wednesday in 2012 in the Gregorian calendar and 2/15 should still look like a Wednesday in 1955 in Thai-Buddhist) as long as the year offset is set correctly. (Before 6.1, without a year offset, 2/15/1955 would look like a Tuesday, even if the QLEAPADJ was set to 3).
Calendar systems can be quite complex and difficult to work with, but the IBM i helps simplify things for you by creating time zone objects for many of the most commonly used time zones around the world, and it knows just which years have a leap day and which ones do not without any input from you at all!
This week’s blog was written by Angela Newton from the IBM i Work Management team. Thanks, Angela!
This blog post was originally published on IBMSystemsMag.com and is reproduced here by permission of IBM Systems Media.