Those related to the leap year and Bug

To 2020, and I wish you all a Happy New Year!

2020 is a leap year (Leap Year), is a leap year will be a failure. Eight years ago, February 29, 2012, I was in Azure when we went out a big fault:
https://azure.microsoft.com/en-us/blog/summary-of-windows-azure-service- disruption-on-feb-29th- 2012 /

Common misperceptions

1, 365 days a year is always
2, always 28 days of February
3, is a leap year every four years

In fact, not a leap year every four years. 2000 is a leap year, but 1900 and 2100 are not leap years.

Where is susceptible to leap-related Bug

1, in a time-value code date plus or minus. In particular plus or minus one month or one year code
2, according to various database query results generated reports and icons, monthly and annual statistics could count less one day
3, certificate / password / key / caching the expiration time It may be a day earlier than expected, or may set up an illegal expiration time
4, an array of fixed length. For example, an array of length 365 may experience a leap year is not enough, might array bounds.
5, UI components, such as a calendar, date selection component, and a client input parity associated code.

What day of the leap year to pay special attention

December 31, 2019: This is the last day of the leap year of the previous year. 2019 plus 365 days of the last day, not the last day of 2020, while 2020 will be the penultimate day (ie 30 December 2020).

2020 January 1: the first day of a leap year. The first leap year days plus 365 days, not next year January 1, but this year's December 31.

2020 January 31: The day plus 28 days, not next month (February) on the last day.
2020 February 1: The day plus 28 days, the first day of the next month is not (in March) is.
2020 February 28: This is the day before the February 29. The code in question might be wrong this day as the last day of February, trying to add one day to obtain March 1. But in fact this day plus one day is February 29th.
2020 February 29: This is the extra leap year day. If the code that is always only 28 days in February, the code that may arise various problems, such as:

Into the reference check will be considered a legitimate input (2020/2/29) is illegal, a { year+1 , month , day }way to add and subtract 1 year, then it will generate an illegal date.

2020, March 1: February 29 behind the day. Code if the reduction in the March 1 for 28 days will be February 2 (instead of 1 May is expected in February); minus 365 days, then will be March 2, 2019 (instead of the expected in March 1).

366 days of the year: 2020 December 31.

If the code does not correctly handle the first 366 days of the year, may also cause problems. For example, December 31, 2008, issue of third-party software has led Microsoft Zune device can not use all the details reference:
http://www.theguardian.com/technology/blog/2009/jan/01/zune-firmware -mistake

If the code is always assumed that a year is 365 days, we declare a fixed-size array 365, array bounds that may occur in the first 366 days of the year.

Array bounds when it occurs in the code written in C / C ++ language, may lead to memory overflow vulnerabilities.

Leap seconds

In addition to a leap year, there is a thing called leap seconds, details Reference:
https://en.wikipedia.org/wiki/Leap_second

However, because the code in the application layer are Alibaba economies, most of the students usually get along, the sun and the moon are in the process, most will be fine to the hour and minute, leap seconds impact on our relatively much smaller. For some bigger leap second time precision requirements are relatively high will affect GPS systems.

Author:
Zheng Ziying, South Gate nickname, now working ants gold dress, senior director of international business group quality and technical risks department. Master of Computer Department of Shanghai Jiaotong University joined Microsoft after graduating in 2018 joined the ants gold dress. Engaged in software development for 18 years, the main focus of the work revolves around testing, quality and engineering performance. At present, our team is more domestic and overseas recruitment test development jobs, professionals at home and abroad are welcome to join us Job Details:

https://hire.alibaba-inc.com/i18n/positionDetail.html?positionId=576717

Guess you like

Origin yq.aliyun.com/articles/742802