Knowledge (XXG)

Leap year problem

Source 📝

450:
The following code is an example of a leap year bug that is seen in many languages. It may cause either a Category 1 or Category 2 impact, depending on what the result is used for. It incorrectly assumes that a leap year occurs exactly every four years.
530:, Tasmania, Australia, each of the 660 computers controlling the smelting potlines shut down at midnight since the computers were not programmed to handle the 366th day of the year. Repair costs were estimated at more than 564:
and the way the device handles a leap year. It automatically fixed itself 24 hours later, but an intermediate "fix" for those who did not wish to wait was to drain the device's battery and then recharge after noon
549:
trains failed to run because their onboard computers did not recognize the date as the 366th day of the year. As an interim measure, engineers restarted the trains by resetting their clocks back by a month.
519:. Microsoft has written an article about this bug, explaining the reasons for treating 1900 as a leap year. This bug has been promoted into a requirement in the Ecma Office Open XML (OOXML) specification. 605:
was taken offline by the leap year bug on February 28. At 5:45 PM PST the Windows Azure team became aware of an issue, apparently due to a time calculation that was incorrect for the leap year.
1247: 507:
has, since its earliest versions, incorrectly considered 1900 to be a leap year, and therefore that February 29 comes between February 28 and March 1 of that year. The bug originated from
167:
The following Windows C++ code is an example of a Category 1 leap year bug. It will work properly until the current date becomes February 29 of a leap year. Then, it will modify
38:) is a problem for both digital (computer-related) and non-digital documentation and data storage situations which results from errors in the calculation of which years are 1290: 945: 1432: 648:
In 2024, a leap year bug with the self-payment machines caused pay-at-pump fuelling stations in New Zealand to go offline for more than 10 hours.
1170: 1283: 1372: 1367: 1331: 1326: 924: 658: 186:
call shown here will return an error code. Since that return value is unchecked (which is extremely common), this will result in
383:
becomes February 29, such as on 2020-02-29. Then it will attempt to set the year to 2021. Since 2021-02-29 doesn't exist, the
1276: 1036: 523: 967: 838: 576:
incorrectly treated 2010 as a leap year, so the non-existent February 29, 2010, was shown on March 1, 2010, and caused a
684: 1447: 54:
Those that lead to error conditions, such as exceptions, error return codes, uninitialized variables, or endless loops
50:
Leap year bugs typically fall into two categories, based on the amount of impact they may have in real-world usage:
527: 278:
becomes February 29. Then, it will attempt to create a February 29 of a common year, which does not exist. The
75:
becomes February 29. Then, it will attempt to create a February 29 of a common year, which does not exist. The
1401: 561: 1442: 516: 1357: 993: 850: 620: 379:
The following JavaScript code is an example of a Category 2 leap year bug. It will work properly until
1092: 862: 274:
The following .NET C# code is an example of a Category 1 leap year bug. It will work properly until
71:
The following Python code is an example of a Category 1 leap year bug. It will work properly until
1406: 1336: 42:, or from manipulating dates without regard to the difference between leap years and common years. 1437: 587:
satellite navigation devices malfunctioned due to a leap year bug that first emerged on March 31.
1411: 1388: 1362: 1321: 1316: 1311: 663: 512: 498: 57:
Those that lead to incorrect data, such as off-by-one problems in range queries or aggregation
602: 504: 20: 171:
to represent February 29 of a common year, a date which does not actually exist. Passing
1067: 1015: 1426: 1222: 1071: 638: 577: 573: 557: 1197: 1145: 627: 609: 876: 546: 906: 556:
models froze. Microsoft stated that the problem was caused by the internal clock
595: 508: 1118: 1044: 971: 814: 788: 762: 736: 710: 1040: 486: 39: 1248:"Petrol pumps back online after day-long outage blamed on leap year glitch" 594:'s chat history showed a date of December 31, 1969, for all chats saved on 623:
on February 29 caused over 1,200 pieces of luggage to miss their flights.
1268: 553: 387:
object will roll forward to the next valid date, which is 2021-03-01.
584: 538: 1016:"BREAKING: Zunes worldwide hit by mystery crash : Tech Digest" 591: 1272: 566: 637:
In 2024, a large number of leap year bugs were cataloged in
626:
In 2020, a large number of leap year bugs were cataloged in
608:
In 2016, a large number of leap year bugs were cataloged in
522:
In 1996, on December 31, at two aluminum smelting plants at
839:
Excel incorrectly assumes that the year 1900 is a leap year
619:
In 2016, a leap year bug in the luggage conveyor system at
542: 552:
At midnight on December 31, 2008, many first generation
499:
Year 2000 problem § On 29 February and 1 March 2000
877:"Leap-Year software bug gives "Million-dollar glitch"" 1381: 1350: 1304: 1171:"Airport hiccup leaves 100s of passengers pantless" 1119:"TomTom sat-nav devices hit by GPS 'leap year bug'" 887:(74). ACM Committee on Computers and Public Policy 83:with the message "day is out of range for month". 851:Standard ECMA-376 / Open Office XML File Formats 485:The correct leap year algorithm is explained at 946:"Y2K Bug Hits Norway's Railroad At End Of Year" 16:Issue resulting in miscalculation of leap years 1284: 8: 994:"30GB Zunes Failing Everywhere, All At Once" 863:ISO/IEC 29500 / Open Office XML File Formats 737:"Win32 / C++ SYSTEMTIME struct manipulation" 685:"What are some examples of leap year bugs?" 1291: 1277: 1269: 763:".NET / C# - Construction from date parts" 925:"7-Eleven Systems Hit by Y2k-like Glitch" 446:Bad leap year algorithm (many languages) 179:struct as a parameter will likely fail. 1196:Johnson-Pint, Matt (29 February 2020). 1144:Johnson-Pint, Matt (29 February 2016). 675: 815:"Determining if a Year is a Leap Year" 21:Julian calendar § Leap year error 7: 1066:Zadegan, Bryant (January 3, 2009). 1043:. December 31, 2008. Archived from 1014:Geere, Duncan (31 December 2008). 14: 970:. Forums.zune.net. Archived from 1433:Time formatting and storage bugs 1373:Years 32,768 and 65,536 problems 659:Time formatting and storage bugs 175:to any function that accepts a 1305:Decimal or BCD storage related 1093:"Sony fixes PS3 leap year bug" 875:Towler, Jim (7 January 1997). 541:the national railroad company 1: 789:"JavaScript - Adding Year(s)" 711:"Python - Replacing the year" 545:discovered all 29 of its new 1223:"List of 2024 Leap Day Bugs" 1198:"List of 2020 Leap Day Bugs" 1146:"List of 2016 Leap Day Bugs" 1068:"A lesson on infinite loops" 537:In 2000, on December 31, in 515:in Excel for the purpose of 1382:Hexadecimal storage related 992:John Herrman (2008-12-31). 284:ArgumentOutOfRangeException 1464: 968:"Home - Microsoft Answers" 907:"The last bite of the bug" 639:List of 2024 Leap Day Bugs 628:List of 2020 Leap Day Bugs 610:List of 2016 Leap Day Bugs 496: 282:constructor will throw an 190:being left uninitialized. 18: 1397: 79:constructor will raise a 865:. Retrieved 2016-09-10. 453: 389: 288: 192: 85: 19:Not to be confused with 1402:Time computing problems 853:. Retrieved 2016-09-10. 841:. Retrieved 2019-05-01. 1351:Binary storage related 517:backward compatibility 1299:Year-related problems 513:purposely implemented 813:Johnson-Pint, Matt. 787:Johnson-Pint, Matt. 761:Johnson-Pint, Matt. 735:Johnson-Pint, Matt. 709:Johnson-Pint, Matt. 683:Johnson-Pint, Matt. 243:SystemTimeToFileTime 184:SystemTimeToFileTime 1407:Time code ambiguity 1358:2036 NTP wraparound 1337:Year 10,000 problem 569:on January 1, 2009. 487:Leap Year Algorithm 30:(also known as the 1448:Technology hazards 1047:on January 2, 2009 974:on August 30, 2009 621:Düsseldorf Airport 526:, New Zealand and 1420: 1419: 1389:Year 2010 problem 1368:Year 2108 problem 1363:Year 2038 problem 1342:Leap year problem 1332:Year 2100 problem 1327:Year 2042 problem 1322:Year 2011 problem 1317:Year 2000 problem 1312:Year 1900 problem 913:. 5 January 2001. 664:Year 2100 problem 182:For example, the 28:leap year problem 1455: 1293: 1286: 1279: 1270: 1263: 1262: 1260: 1259: 1244: 1238: 1237: 1235: 1234: 1219: 1213: 1212: 1210: 1208: 1193: 1187: 1186: 1184: 1182: 1167: 1161: 1160: 1158: 1156: 1141: 1135: 1134: 1132: 1130: 1115: 1109: 1108: 1106: 1104: 1089: 1083: 1082: 1080: 1078: 1063: 1057: 1056: 1054: 1052: 1033: 1027: 1026: 1024: 1023: 1011: 1005: 1004: 1002: 1001: 989: 983: 982: 980: 979: 964: 958: 957: 955: 953: 948:. 1 January 2001 942: 936: 935: 933: 931: 921: 915: 914: 903: 897: 896: 894: 892: 881:The RISKS Digest 872: 866: 860: 854: 848: 842: 836: 830: 829: 827: 825: 810: 804: 803: 801: 799: 784: 778: 777: 775: 773: 758: 752: 751: 749: 747: 732: 726: 725: 723: 721: 706: 700: 699: 697: 695: 680: 533: 481: 478: 475: 472: 469: 466: 463: 460: 457: 441: 438: 435: 432: 429: 426: 423: 420: 417: 414: 411: 408: 405: 402: 399: 396: 393: 386: 382: 370: 367: 364: 361: 358: 355: 352: 349: 346: 343: 340: 337: 334: 331: 328: 325: 322: 319: 316: 313: 310: 307: 304: 301: 298: 295: 292: 285: 281: 277: 265: 262: 259: 256: 253: 250: 247: 244: 241: 238: 235: 232: 229: 226: 223: 220: 217: 214: 211: 208: 205: 202: 199: 196: 189: 185: 178: 174: 170: 158: 155: 152: 149: 146: 143: 140: 137: 134: 131: 128: 125: 122: 119: 116: 113: 110: 107: 104: 101: 98: 95: 92: 89: 82: 78: 74: 1463: 1462: 1458: 1457: 1456: 1454: 1453: 1452: 1423: 1422: 1421: 1416: 1393: 1377: 1346: 1300: 1297: 1267: 1266: 1257: 1255: 1246: 1245: 1241: 1232: 1230: 1221: 1220: 1216: 1206: 1204: 1195: 1194: 1190: 1180: 1178: 1169: 1168: 1164: 1154: 1152: 1143: 1142: 1138: 1128: 1126: 1117: 1116: 1112: 1102: 1100: 1091: 1090: 1086: 1076: 1074: 1065: 1064: 1060: 1050: 1048: 1035: 1034: 1030: 1021: 1019: 1018:. Techdigest.tv 1013: 1012: 1008: 999: 997: 991: 990: 986: 977: 975: 966: 965: 961: 951: 949: 944: 943: 939: 929: 927: 923: 922: 918: 905: 904: 900: 890: 888: 874: 873: 869: 861: 857: 849: 845: 837: 833: 823: 821: 812: 811: 807: 797: 795: 786: 785: 781: 771: 769: 760: 759: 755: 745: 743: 734: 733: 729: 719: 717: 708: 707: 703: 693: 691: 682: 681: 677: 672: 655: 641:at the website 630:at the website 612:at the website 603:Microsoft Azure 531: 505:Microsoft Excel 501: 495: 483: 482: 479: 476: 473: 470: 467: 464: 461: 458: 455: 448: 443: 442: 439: 436: 433: 430: 427: 424: 421: 418: 415: 412: 409: 406: 403: 400: 397: 394: 391: 384: 380: 377: 372: 371: 368: 365: 362: 359: 356: 353: 350: 347: 344: 341: 338: 335: 332: 329: 326: 323: 320: 317: 314: 311: 308: 305: 302: 299: 296: 293: 290: 283: 279: 275: 272: 267: 266: 263: 260: 257: 254: 251: 248: 245: 242: 239: 236: 233: 230: 227: 224: 221: 218: 215: 212: 209: 206: 203: 200: 197: 194: 187: 183: 176: 172: 168: 165: 160: 159: 156: 153: 150: 147: 144: 141: 138: 135: 132: 129: 126: 123: 120: 117: 114: 111: 108: 105: 102: 99: 96: 93: 90: 87: 80: 76: 72: 69: 64: 48: 24: 17: 12: 11: 5: 1461: 1459: 1451: 1450: 1445: 1440: 1435: 1425: 1424: 1418: 1417: 1415: 1414: 1409: 1404: 1398: 1395: 1394: 1392: 1391: 1385: 1383: 1379: 1378: 1376: 1375: 1370: 1365: 1360: 1354: 1352: 1348: 1347: 1345: 1344: 1339: 1334: 1329: 1324: 1319: 1314: 1308: 1306: 1302: 1301: 1298: 1296: 1295: 1288: 1281: 1273: 1265: 1264: 1239: 1214: 1188: 1175:The Local (de) 1162: 1136: 1125:. 3 April 2012 1110: 1099:. 2 March 2010 1084: 1058: 1028: 1006: 984: 959: 937: 916: 898: 867: 855: 843: 831: 819:Stack Overflow 805: 793:Stack Overflow 779: 767:Stack Overflow 753: 741:Stack Overflow 727: 715:Stack Overflow 701: 689:Stack Overflow 674: 673: 671: 668: 667: 666: 661: 654: 651: 650: 649: 646: 635: 624: 617: 606: 599: 588: 581: 570: 550: 535: 520: 494: 491: 454: 447: 444: 390: 376: 373: 289: 271: 268: 193: 164: 161: 86: 68: 65: 63: 60: 59: 58: 55: 47: 44: 15: 13: 10: 9: 6: 4: 3: 2: 1460: 1449: 1446: 1444: 1443:Software bugs 1441: 1439: 1436: 1434: 1431: 1430: 1428: 1413: 1410: 1408: 1405: 1403: 1400: 1399: 1396: 1390: 1387: 1386: 1384: 1380: 1374: 1371: 1369: 1366: 1364: 1361: 1359: 1356: 1355: 1353: 1349: 1343: 1340: 1338: 1335: 1333: 1330: 1328: 1325: 1323: 1320: 1318: 1315: 1313: 1310: 1309: 1307: 1303: 1294: 1289: 1287: 1282: 1280: 1275: 1274: 1271: 1253: 1249: 1243: 1240: 1228: 1224: 1218: 1215: 1203: 1199: 1192: 1189: 1176: 1172: 1166: 1163: 1151: 1147: 1140: 1137: 1124: 1120: 1114: 1111: 1098: 1094: 1088: 1085: 1073: 1072:AeroXperience 1069: 1062: 1059: 1046: 1042: 1038: 1037:"Zune 30 FAQ" 1032: 1029: 1017: 1010: 1007: 996:. Gizmodo.com 995: 988: 985: 973: 969: 963: 960: 947: 941: 938: 926: 920: 917: 912: 908: 902: 899: 886: 882: 878: 871: 868: 864: 859: 856: 852: 847: 844: 840: 835: 832: 820: 816: 809: 806: 794: 790: 783: 780: 768: 764: 757: 754: 742: 738: 731: 728: 716: 712: 705: 702: 690: 686: 679: 676: 669: 665: 662: 660: 657: 656: 652: 647: 644: 640: 636: 633: 629: 625: 622: 618: 615: 611: 607: 604: 600: 597: 593: 589: 586: 582: 579: 578:program error 575: 574:PlayStation 3 571: 568: 563: 559: 555: 551: 548: 544: 540: 536: 532:NZ$ 1 million 529: 525: 521: 518: 514: 510: 506: 503: 502: 500: 492: 490: 488: 452: 445: 388: 374: 287: 269: 213:GetSystemTime 191: 180: 162: 84: 66: 61: 56: 53: 52: 51: 45: 43: 41: 37: 33: 32:leap year bug 29: 22: 1341: 1256:. Retrieved 1254:. 2024-03-01 1251: 1242: 1231:. Retrieved 1229:. 2024-02-29 1227:Code of Matt 1226: 1217: 1205:. Retrieved 1202:Code of Matt 1201: 1191: 1179:. Retrieved 1177:. March 2016 1174: 1165: 1153:. Retrieved 1150:Code of Matt 1149: 1139: 1127:. Retrieved 1122: 1113: 1101:. Retrieved 1096: 1087: 1075:. Retrieved 1061: 1049:. Retrieved 1045:the original 1031: 1020:. Retrieved 1009: 998:. Retrieved 987: 976:. Retrieved 972:the original 962: 950:. Retrieved 940: 928:. Retrieved 919: 910: 901: 889:. Retrieved 884: 880: 870: 858: 846: 834: 822:. Retrieved 818: 808: 796:. Retrieved 792: 782: 770:. Retrieved 766: 756: 744:. Retrieved 740: 730: 718:. Retrieved 714: 704: 692:. Retrieved 688: 678: 643:Code of Matt 642: 632:Code of Matt 631: 614:Code of Matt 613: 484: 449: 378: 273: 270:Microsoft C# 181: 166: 70: 49: 36:leap day bug 35: 31: 27: 25: 720:29 February 596:February 29 560:written by 524:Tiwai Point 509:Lotus 1-2-3 493:Occurrences 428:getFullYear 416:setFullYear 163:Windows C++ 1427:Categories 1258:2024-02-29 1233:2024-02-29 1181:5 February 1155:5 February 1129:5 February 1103:10 October 1077:January 5, 1051:January 1, 1022:2011-07-27 1000:2011-07-27 978:2011-07-27 891:5 February 824:5 February 798:5 February 772:5 February 746:5 February 694:5 February 670:References 511:, and was 497:See also: 459:isLeapYear 375:JavaScript 195:SYSTEMTIME 177:SYSTEMTIME 81:ValueError 46:Categories 40:leap years 1438:Calendars 1252:NZ Herald 1041:Microsoft 601:In 2012, 590:In 2012, 583:In 2012, 562:Freescale 1123:BBC News 952:10 March 930:10 March 911:BBC News 653:See also 547:Signatur 528:Bell Bay 324:DateTime 312:DateTime 300:DateTime 291:DateTime 280:DateTime 204:FILETIME 91:datetime 62:Examples 1207:9 March 572:Sony's 554:Zune 30 130:replace 34:or the 585:TomTom 558:driver 539:Norway 315:result 94:import 67:Python 1412:Epoch 1097:Metro 592:Gmail 354:Month 258:& 249:& 234:wYear 219:& 142:today 124:today 118:later 112:today 100:today 73:today 1209:2020 1183:2020 1157:2020 1131:2020 1105:2019 1079:2009 1053:2009 954:2023 932:2023 893:2020 826:2020 800:2020 774:2020 748:2020 722:2020 696:2020 465:year 456:bool 404:Date 385:Date 336:Year 148:year 136:year 106:date 97:date 88:from 77:date 26:The 567:UTC 407:(); 401:new 392:var 366:Day 321:new 306:Now 1429:: 1250:. 1225:. 1200:. 1173:. 1148:. 1121:. 1095:. 1070:. 1039:. 909:. 885:18 883:. 879:. 817:. 791:. 765:. 739:. 713:. 687:. 543:Vy 489:. 474:== 440:); 431:() 422:dt 410:dt 395:dt 381:dt 369:); 360:dt 348:dt 330:dt 294:dt 286:. 276:dt 264:); 261:ft 252:st 237:++ 228:st 225:); 222:st 207:ft 198:st 188:ft 173:st 169:st 115:() 1292:e 1285:t 1278:v 1261:. 1236:. 1211:. 1185:. 1159:. 1133:. 1107:. 1081:. 1055:. 1025:. 1003:. 981:. 956:. 934:. 895:. 828:. 802:. 776:. 750:. 724:. 698:. 645:. 634:. 616:. 598:. 580:. 534:. 480:; 477:0 471:4 468:% 462:= 437:1 434:+ 425:. 419:( 413:. 398:= 363:. 357:, 351:. 345:, 342:1 339:+ 333:. 327:( 318:= 309:; 303:. 297:= 255:, 246:( 240:; 231:. 216:( 210:; 201:; 157:) 154:1 151:+ 145:. 139:= 133:( 127:. 121:= 109:. 103:= 23:.

Index

Julian calendar § Leap year error
leap years
Leap Year Algorithm
Year 2000 problem § On 29 February and 1 March 2000
Microsoft Excel
Lotus 1-2-3
purposely implemented
backward compatibility
Tiwai Point
Bell Bay
Norway
Vy
Signatur
Zune 30
driver
Freescale
UTC
PlayStation 3
program error
TomTom
Gmail
February 29
Microsoft Azure
List of 2016 Leap Day Bugs
Düsseldorf Airport
List of 2020 Leap Day Bugs
List of 2024 Leap Day Bugs
Time formatting and storage bugs
Year 2100 problem
"What are some examples of leap year bugs?"

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.