%3CLINGO-SUB%20id%3D%22lingo-sub-1157620%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1157620%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20Sharing%20with%20the%20Community%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fsmile_40x40.gif%22%20alt%3D%22%3Asmile%3A%22%20title%3D%22%3Asmile%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1157631%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1157631%22%20slang%3D%22en-US%22%3E%3CP%3ENice%20one!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1158481%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1158481%22%20slang%3D%22en-US%22%3E%3CP%3EGreat%20Information!%20thanks%20for%20sharing%20this%20with%20the%20community%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fsmile_40x40.gif%22%20alt%3D%22%3Asmile%3A%22%20title%3D%22%3Asmile%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1160496%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1160496%22%20slang%3D%22en-US%22%3E%3CP%3EGreat%20post%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F289185%22%20target%3D%22_blank%22%3E%40MattJohnson-Pint%3C%2FA%3E%26nbsp%3B%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1169051%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1169051%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F289185%22%20target%3D%22_blank%22%3E%40MattJohnson-Pint%3C%2FA%3E%26nbsp%3BExcellent%20post.%26nbsp%3B%20Thank%20you%20for%20sharing.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1180079%22%20slang%3D%22es-ES%22%3ERe%3A%20It's%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1180079%22%20slang%3D%22es-ES%22%3E%3CP%3EThank%20you%20for%20the%20Information%2C%20it's%20very%20valuable.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1186751%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1186751%22%20slang%3D%22en-US%22%3E%3CP%3ERandom%20question.%3C%2FP%3E%3CP%3EWith%20regards%20to%20the%20calculation%20of%20leap%20years.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EIs%20the%20year%20evenly%20divisible%20by%204%3F%20Then%20it%20is%20a%20leap%20year.%20(Examples%3A%202012%2C%202016%2C%202020%2C%202024)%3C%2FLI%3E%3CLI%3E%E2%80%A6%20Unless%20it%20is%20also%20evenly%20divisible%20by%20100.%20Those%20are%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3Enot%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eleap%20years.%20(Examples%3A%201800%2C%201900%2C%202100)%3C%2FLI%3E%3CLI%3E%E2%80%A6%20Except%20that%20year%20that%20are%20evenly%20divisible%20by%20400%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eare%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eleap%20years.%20(Examples%3A%201600%2C%202000%2C%202400)%3C%2FLI%3E%3C%2FUL%3E%3CP%3EWhat%20happens%20if%20the%20year%20is%2010000.%3C%2FP%3E%3CP%3Eit%20can%20be%20divisible%20by%204.%20(2500)%3C%2FP%3E%3CP%3Eit%20can%20be%20divisible%20by%20100.%20(100)%3C%2FP%3E%3CP%3Eit%20can%20be%20divisible%20by%20400.%20(25)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1187230%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1187230%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F565013%22%20target%3D%22_blank%22%3E%40Dhivek_Sewpersad%3C%2FA%3E%26nbsp%3BBecause%20it%20is%20evenly%20divisible%20by%20400%2C%20then%20year%2010000%20is%20indeed%20a%20leap%20year.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1198147%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1198147%22%20slang%3D%22en-US%22%3E%3CP%3EI%20read%20somewhere%20every%20400%20years%2C%20FEB%20gets%2030%20days%20..%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20reason%20why%20FEB%20has%2028%20days%20(%2B1%20or%20%2B2%20days)%20it%20is%20not%20even%20at%20start%20or%20end%20of%20a%20calendar%20year%20to%20be%20adjusted%20..%3C%2FP%3E%3CP%3EOnly%20reason%20i%20can%20think%20is%20because%20as%20per%20Zodiac%20(solar)%20in%20north%20hemisphere%2C%20spring%20starts%20at%20March%2020%20(ideally%20this%20should%20be%20the%20new%20year%2C%20not%20Jan%201)%20as%20everyone%20considered%20spring%20to%20be%20start%20of%20new%20things%20%2F%20new%20year%20in%20old%20days%20...%20so%20i%20guess%20they%20adjusted%20%2B1%20day%20just%20before%20March%20started...%20which%20happened%20to%20be%20FEB.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1198308%22%20slang%3D%22en-US%22%3ERe%3A%20It%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1198308%22%20slang%3D%22en-US%22%3E%3CP%3Ethanks%20for%20valuable%20information%20sir%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1157279%22%20slang%3D%22en-US%22%3EIt%E2%80%99s%202020.%20Is%20your%20code%20ready%20for%20leap%20day%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1157279%22%20slang%3D%22en-US%22%3E%3CP%3E%222020%20is%20the%20start%20of%20a%20new%20decade%20%E2%80%93%20or%20does%20it%20start%20in%202021%3F%22%20That%20was%20the%20debate%20on%20social%20media%20as%20we%20crossed%20over%20into%20the%20new%20year.%20There%20was%20also%20a%20lot%20of%20talk%20about%20remembering%20Y2K%20twenty%20years%20later%2C%20which%20inevitably%20led%20to%20speculation%20about%20how%20computers%20will%20behave%20in%20Y2038.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20what's%20more%20interesting%20to%20me%20is%20just%20how%20little%20we%20discuss%20software%20bugs%20related%20to%20leap%20years%2C%20which%20occur%20much%20more%20frequently%20than%20any%20of%20these%20grand%20events.%20In%20an%20attempt%20to%20remedy%20this%2C%20I'd%20like%20to%20tell%20you%20a%20little%20about%20leap%20year%20bugs%2C%20how%20you%20can%20spot%20them%20in%20your%20code%2C%20and%20what%20we%20have%20been%20doing%20here%20at%20Microsoft%20to%20prevent%20them%20from%20impacting%20our%20products%20and%20services.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EWhat%20are%20leap%20years%2C%20and%20why%20do%20we%20have%20them%3F%3CP%3EA%20leap%20year%20is%20a%20year%20which%20contains%20an%20extra%20day%20which%20we%20observe%20on%20February%2029th%20and%20call%20a%20leap%20day.%20Because%20of%20the%20extra%20day%2C%20there%20are%20366%20days%20in%20the%20year%20instead%20of%20the%20usual%20365.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20think%20leap%20years%20occur%20every%20four%20years%2C%20but%20the%20exact%20algorithm%20is%20slightly%20more%20complicated%3A%3C%2FP%3EIs%20the%20year%20evenly%20divisible%20by%204%3F%20Then%20it%20is%20a%20leap%20year.%20(Examples%3A%202012%2C%202016%2C%202020%2C%202024)%20%E2%80%A6%20Unless%20it%20is%20also%20evenly%20divisible%20by%20100.%20Those%20are%20not%20leap%20years.%20(Examples%3A%201800%2C%201900%2C%202100)%20%E2%80%A6%20Except%20that%20year%20that%20are%20evenly%20divisible%20by%20400%20are%20leap%20years.%20(Examples%3A%201600%2C%202000%2C%202400)%3CP%3ELeap%20years%20are%20an%20important%20part%20of%20our%20calendar%20system%2C%20as%20they%20keep%20seasons%20and%20astronomical%20events%20from%20drifting%20from%20one%20year%20to%20the%20next.%20This%20is%20because%20the%20mean%20time%20it%20takes%20for%20the%20Earth%20to%20actually%20go%20around%20the%20sun%20is%20slightly%20more%20than%20365%20days%2C%20but%20not%20quite%20366%20days.%20The%20leap%20year%20algorithm%20approximates%20this%20as%20365.2425%20days%20%E2%80%93%20though%20it's%20important%20to%20note%20than%20no%20given%20year%20has%20a%20fractional%20number%20of%20days%20in%20it.%20Rather%2C%20we%20decide%20when%20to%20add%20an%20extra%20whole%20day%20and%20when%20not%20to.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20more%20detail%20on%20the%20science%20and%20history%20behind%20leap%20years%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FLeap_year%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ethe%20leap%20year%20article%20on%20Wikipedia%3C%2FA%3E%2C%20or%20watch%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DxX96xng7sAE%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ECGP%20Grey's%20excellent%20short%20video%20on%20YouTube%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENote%20that%20this%20information%20refers%20to%20the%20proleptic%20Gregorian%20calendar%2C%20which%20is%20the%20primary%20calendar%20system%20used%20in%20business%20and%20computing%20today.%20Other%20calendar%20systems%20(such%20as%20the%20Buddhist%20calendar%2C%20Hebrew%20calendar%2C%20Hijri%20calendar%2C%20and%20others)%20have%20different%20rules%20for%20observing%20leap%20days%20or%20months.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EWhat%20about%20leap%20seconds%2C%20time%20zones%2C%20daylight%20saving%20time%2C%20time%20on%20Mars%2C%20relativity%2C%20etc.%3F%3CP%3EWhile%20all%20fascinating%20topics%2C%20none%20are%20related%20to%20leap%20years.%20Even%20leap%20seconds%20%E2%80%93%20despite%20having%20the%20word%20%22leap%22%20in%20them%2C%20are%20related%20to%20a%20completely%20different%20phenomenon%2C%20and%20thus%20I%20won't%20dive%20into%20them%20in%20this%20post.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EOk%20then%2C%20What%20is%20a%20leap%20year%20bug%3F%3CP%3EA%20leap%20year%20bug%20is%20what%20happens%20in%20software%20when%20programs%20that%20work%20with%20dates%20do%20not%20correctly%20take%20leap%20years%20into%20account.%20They%20might%20simply%20misapply%20the%20leap%20year%20algorithm%2C%20or%20they%20might%20ignore%20the%20difference%20between%20leap%20years%20and%20common%20years%20when%20manipulating%20dates.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can%20demonstrate%20this%20without%20any%20code%20at%20all.%20Let%20me%20ask%20you%20a%20simple%20question%3A%20What%20date%20will%20it%20be%20a%20year%20from%20today%3F%20Let's%20say%20that%20%22today%22%20is%20January%201st%2C%202020.%20Got%20the%20answer%3F%20Now%20think%20about%20how%20you%20figured%20that%20out.%20Likely%20you%20did%20something%20like%20this%3A%3C%2FP%3E2020%20plus%201%20year%20is%202021%20Today%20is%20January%201st%20The%20result%20is%20January%201st%2C%202021%3CP%3EIf%20you%20did%20that%2C%20congratulations!%20You%20have%20just%20created%20a%20leap%20year%20bug!%20Don't%20feel%20bad%2C%20even%20the%20very%20best%20software%20engineers%20sometimes%20do%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20getting%20it%3F%20Ok%20%E2%80%93%20let's%20try%20that%20exact%20same%20process%20again%2C%20but%20this%20time%20let's%20say%20that%20%22today%22%20is%20leap%20day%20%E2%80%93%20February%2029th%2C%202020%3A%3C%2FP%3E2020%20plus%201%20year%20is%202021%20Today%20is%20February%2029th%20The%20result%20is%20February%2029th%2C%202021%3CP%3ESee%20the%20problem%3F%20The%20resulting%20date%20does%20not%20exist.%202021%20is%20not%20a%20leap%20year%2C%20it%20is%20a%20common%20year%20and%20thus%20February%20only%20has%2028%20days%20in%20that%20year.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20a%20human%20being%2C%20if%20you%20were%20looking%20for%20February%2029th%20on%20the%20calendar%20and%20it%20wasn't%20there%2C%20likely%20you%20would%20just%20pick%20February%2028th%20and%20move%20on%20to%20better%20things.%20Computers%2C%20however%2C%20only%20do%20exactly%20what%20we%20tell%20them%20to%20do%2C%20and%20in%20many%20programing%20languages%20invalid%20input%20is%20expected%20to%20return%20an%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EWhat%20kind%20of%20impact%20can%20leap%20year%20bugs%20have%3F%3CP%3ELeap%20year%20bugs%20typically%20fall%20into%20two%20impact%20categories%3A%3C%2FP%3ECategory%201%3A%20Those%20that%20lead%20to%20error%20conditions%2C%20such%20as%20exceptions%2C%20error%20return%20codes%2C%20uninitialized%20variables%2C%20or%20endless%20loops%20Category%202%3A%20Those%20that%20lead%20to%20incorrect%20data%2C%20such%20as%20off-by-one%20problems%20in%20range%20queries%20or%20aggregation%3CP%3EIt's%20generally%20Category%201%20bugs%2C%20such%20as%20the%20one%20described%20above%2C%20that%20are%20the%20most%20concerning.%20These%20are%20the%20type%20that%20are%20responsible%20for%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fblog%2Fsummary-of-windows-azure-service-disruption-on-feb-29th-2012%2F%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ecloud%20service%20outages%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.computerworld.com%2Farticle%2F2529992%2Fzune-chokes-on-leap-year-bug.html%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ebricked%20personal%20media%20players%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.thelocal.de%2F20160301%2Fdsseldorf-airport-hick-ups-leave-hundreds-of-customers-without-underwear%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eairport%20baggage%20handling%20mishaps%3C%2FA%3E%2C%20and%20%3CA%20href%3D%22https%3A%2F%2Fcatless.ncl.ac.uk%2FRisks%2F18.74.html%23subj5%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ecatastrophic%20industrial%20equipment%20failures%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECategory%202%20bugs%20do%20not%20typically%20lead%20to%20outages%2C%20but%20that%20doesn't%20mean%20they%20aren't%20important.%20They%20occur%20when%20%22365%20days%22%20is%20substituted%20in%20place%20of%20a%20year%20%E2%80%93%20akin%20to%20calling%20a%20month%20%2230%20days%22.%20Most%20of%20us%20know%20that%20not%20every%20month%20has%2030%20days.%20It%20may%20suffice%20as%20an%20approximation%2C%20but%20is%20no%20good%20when%20you%20need%20a%20precise%20answer.%20Likewise%2C%20adding%20365%20days%20is%20fine%20if%20you%20need%20%22about%20a%20year%22%2C%20perhaps%20for%20an%20expiration%20date.%20However%2C%20it%20won't%20lead%20to%20correct%20results%20if%20you're%20calculating%20financial%20reports%20or%20figuring%20out%20how%20many%20years%20old%20someone%20is.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EWhat%20is%20Microsoft%20doing%20to%20protect%20me%20from%20leap%20year%20bugs%3F%3CP%3ELeap%20year%20bugs%20can%20be%20incredibly%20challenging%20to%20find%2C%20especially%20in%20large%20projects.%20It's%20even%20harder%20if%20you%20need%20to%20sift%20through%20billions%20of%20lines%20of%20source%20code%20across%20many%20different%20divisions%20of%20a%20company%20like%20Microsoft.%20However%20daunting%20the%20task%2C%20we've%20been%20taking%20leap%20year%20readiness%20quite%20seriously%20in%20order%20to%20reduce%20the%20risk%20of%20impact%20to%20our%20customers%20on%20Feb%2029th.%20Over%20the%20past%209%20months%20or%20so%2C%20I've%20been%20working%20with%20a%20small%20team%20of%20engineers%20in%20Azure%20to%20prepare%20the%20company%20for%20leap%20year.%20We've%20been%20searching%20through%20source%20code%20looking%20for%20potential%20leap%20year%20bugs%2C%20through%20both%20manual%20and%20automated%20approaches.%20We%20started%20within%20Azure%2C%20building%20upon%20some%20of%20the%20efforts%20from%202016's%20leap%20year%2C%20then%20expanded%20our%20scope%20to%20include%20a%20much%20larger%20portion%20of%20Microsoft.%20Tens%20of%20thousands%20of%20source%20code%20repositories%20have%20now%20been%20scanned%2C%20and%20are%20continually%20being%20scanned%20as%20new%20code%20is%20written%20by%20product%20teams.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20large%20part%20of%20the%20challenge%20is%20positive%20identification.%20Many%20of%20the%20items%20we%20find%20may%20match%20patterns%20associated%20with%20leap%20year%20bugs%2C%20but%20turn%20out%20to%20be%20benign.%20For%20example%2C%20we%20might%20detect%20that%20a%20year%20of%20a%20date%20is%20being%20incremented%20but%20miss%20that%20the%20day%20is%20always%20the%201st%20of%20a%20month%20%E2%80%93%20in%20which%20case%20there%20is%20no%20problem.%20We%20also%20tend%20to%20find%20more%20issues%20in%20test%20code%20than%20in%20code%20that%20makes%20its%20way%20into%20a%20product%20or%20service.%20Tests%20can%20still%20be%20important%2C%20as%20many%20teams%20depend%20on%20passing%20tests%20in%20order%20to%20build%20and%20release%20updates.%20In%20order%20to%20address%20these%20challenges%2C%20we've%20enlisted%20the%20aid%20of%20thousands%20of%20Microsoft%20engineers%20on%20each%20of%20the%20product%20or%20service%20teams.%20They%20examine%20our%20findings%2C%20triage%20them%2C%20and%20take%20action%20where%20necessary.%20Through%20this%20tedious%20process%2C%20we%20have%20identified%20and%20repaired%20many%20leap%20year%20bugs%20well%20before%20they%20can%20become%20an%20issue%20for%20customers.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAzure%20Engineering%20has%20fully%20audited%20the%20Azure%20services%20and%20supporting%20services%2C%20libraries%2C%20and%20operating%20systems%20for%20leap%20year%20issues.%20While%20the%20code%20has%20been%20reviewed%20extensively%2C%20we%20also%20recognize%20that%20this%20is%20not%20a%20foolproof%20process%20and%20one%20approach%20is%20not%20enough.%20As%20we%20want%20to%20protect%20our%20customers%20in%20every%20way%20possible%2C%20we%20have%20prepared%20the%20company%20through%20multiple%20avenues%20including%3A%3C%2FP%3ECode%20scanning%2C%20testing%2C%20and%20manual%20review%20where%20necessary%20Documentation%20of%20the%20leap%20year%20risk%2C%20the%20code%20patterns%20involved%2C%20testing%20approaches%2C%20and%20past%20occurrences%20Training%20sessions%20and%20presentations%2C%20both%20to%20existing%20engineers%20and%20to%20new%20hires%20Participation%20in%20internal%20events%20to%20raise%20awareness%20among%20engineers%20and%20product%20managers%20Broad%20internal%20communications%20of%20our%20efforts%20through%20both%20email%20and%20physical%20posters%20hung%20around%20campus%20External%20communications%2C%20such%20as%20the%20blog%20post%20you're%20reading%20now%20An%20action%20plan%20for%20the%20leap%20day%20weekend%2C%20including%20heightened%20awareness%2C%20monitoring%2C%20and%20escalation%20channels%3CP%3E%26nbsp%3B%3C%2FP%3EI'm%20a%20developer.%20What%20does%20a%20leap%20year%20bug%20look%20like%20in%20code%3F%3CP%3EHere%20is%20an%20example%20of%20.NET%20code%20containing%20a%20leap%20year%20bug%2C%20written%20in%20C%23%2C%20that%20uses%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fdotnet%2Fapi%2Fsystem.datetime%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EDateTime%3C%2FA%3E%20structure.%20It%20is%20trying%20to%20add%20a%20year%20to%20today%2C%20but%20it%20is%20doing%20it%20in%20a%20way%20that%20doesn't%20account%20for%20February%2029th.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EDateTime%20dt%20%3D%20DateTime.Today%3B%20DateTime%20result%20%3D%20new%20DateTime(dt.Year%20%2B%201%2C%20dt.Month%2C%20dt.Day)%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20are%20variations%20of%20this%20of%20course.%20Perhaps%20the%20data%20type%20is%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fdotnet%2Fapi%2Fsystem.datetimeoffset%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EDateTimeOffset%3C%2FA%3E%20structure.%20Perhaps%20the%20date%20doesn't%20originate%20with%20Now%20or%20Today%20but%20comes%20from%20a%20stored%20value.%20Perhaps%20the%20number%20of%20years%20being%20added%20or%20subtracted%20is%20variable.%20In%20all%20variations%2C%20the%20problem%20is%20the%20same%20%E2%80%93%20when%20the%20result%20is%20a%20date%20that%20doesn't%20exist%2C%20an%20exception%20is%20thrown.%20(Specifically%2C%20an%20ArgumentOutOfRangeException.)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20.NET%2C%20the%20solution%20is%20simple.%20Just%20use%20the%20AddYears%20method%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EDateTime%20dt%20%3D%20DateTime.Today%3B%20DateTime%20result%20%3D%20dt.AddYears(1)%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20AddYears%20method%20is%20built%20in%2C%20and%20works%20by%20doing%20what%20I%20said%20a%20human%20might%20do.%20It%20extends%20the%20logic%20to%20ensure%20the%20resulting%20value%20is%20valid.%20If%20not%2C%20it%20adjusts%20to%20the%20last%20day%20of%20the%20month%20(February%2028th).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20let's%20take%20a%20look%20at%20some%20C%2B%2B%20code%20that%20exhibits%20the%20same%20problem%2C%20using%20the%20Windows%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fwindows%2Fwin32%2Fapi%2Fminwinbase%2Fns-minwinbase-systemtime%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESYSTEMTIME%3C%2FA%3E%20structure.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3ESYSTEMTIME%20st%3B%20GetSystemTime(%26amp%3Bst)%3B%20st.wYear%2B%2B%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAt%20this%20point%2C%20the%20st%20variable%20could%20contain%20an%20invalid%20date%2C%20such%20as%20February%2029%2C%202021.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnlike%20.NET's%20DateTime%20structure%2C%20the%20Windows%20SYSTEMTIME%20structure%20doesn't%20care%20if%20it%20represents%20a%20valid%20date%20or%20not.%20It%20is%20just%20a%20plain%20data%20type%20containing%20separate%20integers%20for%20year%2C%20month%2C%20day%2C%20and%20so%20on.%20It%20is%20not%20until%20the%20structure%20is%20used%20by%20a%20function%20that%20these%20fields%20are%20recomposed%20into%20a%20logical%20date%2C%20and%20it's%20up%20to%20that%20function%20on%20how%20to%20deal%20with%20invalid%20dates.%3C%2FP%3EMost%20functions%20that%20accept%20a%20SYSTEMTIME%20value%20will%20return%20an%20error%20result%20when%20passed%20an%20invalid%20date.%20A%20good%20example%20is%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fwindows%2Fwin32%2Fapi%2Ftimezoneapi%2Fnf-timezoneapi-systemtimetofiletime%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESystemTimeToFileTime%3C%2FA%3E.%20It%20returns%20a%20boolean%20result%20code%2C%20which%20is%20TRUE%20as%20long%20as%20the%20input%20date%20was%20valid.%20(Because%20this%20is%20usually%20the%20case%2C%20developers%20sometimes%20don't%20bother%20to%20check%20this%20result!)%20When%20it%20returns%20FALSE%2C%20that%20indicates%20the%20conversion%20failed.%20The%20pointer%20to%20the%20FILETIME%20structure%20that%20was%20intended%20to%20receive%20the%20output%20will%20be%20left%20as%20is.%20And%20there's%20the%20problem%20%E2%80%93%20perhaps%20that%20value%20is%200%2C%20representing%20January%201st%2C%201601.%20That%20certainly%20won't%20have%20the%20desired%20effect!%20By%20contrast%2C%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fwindows%2Fwin32%2Fapi%2Foleauto%2Fnf-oleauto-systemtimetovarianttime%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESystemTimeToVariantTime%3C%2FA%3E%20function%20doesn't%20fail%20on%20dates%20like%20February%2029%2C%202021.%20Instead%2C%20it%20is%20treated%20as%20if%20it%20were%20March%201st%2C%202021.%20Perhaps%20this%20is%20still%20a%20bug%20for%20your%20code%2C%20as%20you%20may%20have%20expected%20February%2028th%2C%20but%20it%20is%20the%20Category%202%20type%20described%20earlier.%3CP%3ESo%20what%20is%20the%20solution%20for%20this%20C%2B%2B%20code%3F%20Well%2C%20unlike%20.NET%2C%20there%20is%20no%20built-in%20AddYears%20method%20to%20call.%20Instead%2C%20one%20has%20to%20ensure%20the%20structure%20has%20a%20valid%20date.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConsider%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Ebool%20isLeapYear%20%3D%20st.wYear%20%25%204%20%3D%3D%200%20%26amp%3B%26amp%3B%20(st.wYear%20%25%20100%20!%3D%200%20%7C%7C%20st.wYear%20%25%20400%20%3D%3D%200)%3B%20st.wDay%20%3D%20st.wMonth%20%3D%3D%202%20%26amp%3B%26amp%3B%20st.wDay%20%3D%3D%2029%20%26amp%3B%26amp%3B%20!isLeapYear%20%3F%2028%20%3A%20st.wDay%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20may%20look%20like%20a%20lot%2C%20but%20what%20it's%20doing%20makes%20sense%3A%20First%20it%20tests%20if%20the%20year%20is%20a%20leap%20year.%20If%20it's%20not%2C%20and%20it's%20February%2029th%2C%20it%20moves%20it%20back%20to%20February%2028th.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlternatively%2C%20one%20might%20consider%20converting%20to%20a%20FILETIME%2C%20adding%20365%20days%2C%20then%20converting%20back%20to%20a%20SYSTEMTIME.%20If%20doing%20so%2C%20ask%20yourself%20if%20it's%20ok%20for%20the%20result%20to%20sometimes%20be%20off%20by%20a%20day.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EWhat%20are%20common%20locations%20where%20I%20might%20find%20a%20leap%20year%20bug%3F%3CP%3EOne%20area%20you%20might%20find%20a%20Category%201%20leap%20year%20bug%20is%20when%20preparing%20valid%20from%2Fto%20dates%20for%20certificates.%20Certificates%20must%20have%20valid%20dates%20on%20them%2C%20so%20passing%20invalid%20ones%20will%20likely%20fail%20certificate%20generation%20processes.%20One%20such%20API%20in%20Windows%20is%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fwindows%2Fwin32%2Fapi%2Fwincrypt%2Fnf-wincrypt-certcreateselfsigncertificate%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ECertCreateSelfSignCertificate%3C%2FA%3E%2C%20which%20creates%20a%20%22self-signed%22%20certificate%2C%20and%20is%20a%20very%20common%20case%20for%20a%20leap%20year%20bug.%20If%20you%20have%20code%20that%20generates%20certificates%20(via%20any%20mechanism)%2C%20you%20should%20examine%20the%20logic%20used%20for%20determining%20their%20validity%20dates%20carefully.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnother%20area%20where%20leap%20year%20bugs%20are%20common%20is%20when%20dealing%20with%20anniversary%20dates%2C%20such%20as%20birth%20dates.%20Did%20you%20know%20that%20a%20person%20born%20on%20a%20leap%20day%20is%20called%20a%20%22leapling%22%3F%20I've%20certainly%20heard%20stories%20from%20leaplings%20describing%20how%20bothersome%20it%20is%20when%20some%20computer%20system%20won't%20accept%20their%20birth%20date%2C%20but%20the%20risk%20goes%20beyond%20that.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EImagine%20you%20have%20a%20user's%20date%20of%20birth%2C%20or%20date%20of%20employment%2C%20or%20date%20of%20first%20login%20to%20your%20website%20stored%20in%20a%20database.%20Maybe%20every%20year%20you%20want%20to%20send%20them%20a%20%22happy%20birthday%22%20or%20%22happy%20anniversary%22%20email%2C%20or%20perhaps%20an%20invoice.%20A%20common%20way%20to%20figure%20out%20when%20to%20do%20that%20might%20be%20to%20take%20the%20month%20and%20day%20from%20the%20user%20and%20apply%20it%20to%20the%20current%20year.%20If%20you%20do%20just%20that%2C%20then%20you%20have%20a%20leap%20year%20bug%20that%20will%20occur%20when%20its%20not%20a%20leap%20year!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELet's%20see%20that%20in%20C%23%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EDateTime%20birthdayThisYear%20%3D%20new%20DateTime(DateTime.Now.Year%2C%20birthDate.Month%2C%20birthDate.Day)%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOne%20approach%20to%20remedy%20the%20problem%20would%20be%20to%20figure%20out%20the%20number%20of%20days%20in%20the%20month%20and%20adjust%2C%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Eint%20year%20%3D%20DateTime.Now.Year%3B%20int%20month%20%3D%20birthDate.Month%3B%20int%20day%20%3D%20birthDate.Day%3B%20int%20daysInMonth%20%3D%20DateTime.DaysInMonth(year%2C%20month)%3B%20if%20(day%20%26gt%3B%20daysInMonth)%20%7B%20day%20%3D%20daysInMonth%3B%20%7D%20DateTime%20birthdayThisYear%20%3D%20new%20DateTime(year%2C%20month%2C%20day)%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnother%20approach%2C%20which%20is%20arguably%20simpler%2C%20is%20to%20just%20add%20the%20difference%20in%20years%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EDateTime%20birthdayThisYear%20%3D%20birthDate.AddYears(DateTime.Now.Year%20-%20birthDate.Year)%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EReally%2C%20a%20leap%20year%20bug%20might%20be%20anywhere%20that%20dates%20are%20being%20manipulated%20by%20some%20logic%2C%20not%20just%20these.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EAre%20there%20other%20types%20of%20leap%20year%20bugs%3F%3CP%3EIndeed%20there%20are.%20I%20described%20some%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fblog%2Fis-your-code-ready-for-the-leap-year%2F%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ein%20my%20blog%20post%20from%20last%20leap%20year%3C%2FA%3E.%20I've%20also%20started%20documenting%20some%20of%20them%20in%20%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fquestions%2F57530882%2Fwhat-are-some-examples-of-leap-year-bugs%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ethis%20Stack%20Overflow%20question%3C%2FA%3E%20(which%20you%20can%20contribute%20to!)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20are%20a%20few%20to%20watch%20out%20for%3A%3C%2FP%3EAssuming%20February%20only%20has%2028%20days%2C%20without%20considering%20the%20year.%20Assuming%20that%20one%20can%20decide%20whether%20to%20add%20365%20days%20or%20366%20days%20by%20checking%20the%20starting%20year%20or%20ending%20year.%20Testing%20if%20a%20year%20is%20a%20leap%20year%2C%20thinking%20they%20always%20occur%20every%20four%20years.%20(year%20%25%204%20is%20only%20part%20of%20the%20formula)%20Declaring%20a%20fixed%20array%20of%20365%20elements%20%E2%80%93%20one%20for%20each%20day%20of%20the%20year.%20(Which%20will%20fail%20on%20Dec%2031%20in%20a%20leap%20year)%20Accepting%20all%20combination%20of%20year%2C%20month%2C%20and%20day%20from%20user%20input%20without%20checking%20for%20validity%20Using%20a%20leap%20year%20test%20to%20branch%20your%20code%20significantly%20(especially%20if%20the%20leap%20year%20branch%20goes%20untested)%20Parsing%20a%20month%2Bday%20string%20to%20a%20data%20type%20that%20requires%20a%20year%20component%3CP%3E%26nbsp%3B%3C%2FP%3EWhat%20about%20other%20programming%20languages%3F%3CP%3ELeap%20year%20bugs%20can%20be%20introduced%20in%20any%20programming%20language.%20However%20some%20languages%20such%20are%20not%20as%20prone%20to%20Category%201%20impact%20bugs%20as%20others.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20in%20JavaScript%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Evar%20d%20%3D%20new%20Date()%3B%20d.setFullYear(d.getFullYear()%20%2B%201)%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20code%20won't%20fail%20on%20leap%20day%2C%20but%20the%20Date%20object%20will%20advance%20to%20March%201st.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOther%20languages%20like%20Python%20are%20prone%20to%20Category%201%20impact%20bugs.%20For%20example%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Efrom%20datetime%20import%20date%20today%20%3D%20date.today()%20later%20%3D%20date(today.year%20%2B%201%2C%20today.month%2C%20today.day)%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20will%20raise%20a%20ValueError%20when%20run%20on%20a%20leap%20day.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20either%20of%20these%20two%20languages%2C%20consider%20the%20best%20option%20may%20be%20to%20use%20an%20open%20source%20library%20for%20date%20manipulation.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EDo%20leap%20year%20bugs%20only%20happen%20on%20February%2029th%3F%3CP%3ENo.%20Another%20date%20that%20can%20cause%20problems%20is%20December%2031st%2C%20as%20it%20is%20the%20366th%20day%20of%20a%20leap%20year.%20Some%20applications%20may%20be%20hard-wired%20for%20365%20days.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdditionally%2C%20not%20all%20date%20manipulate%20happens%20around%20the%20current%20date.%20It's%20reasonable%20that%20a%20leap%20day%20bug%20could%20be%20encountered%20any%20day%20of%20the%20year.%20It's%20just%20that%20a%20lot%20of%20code%20works%20with%20%22today%22%20as%20a%20basis%2C%20so%20leap%20year%20bugs%20are%20more%20likely%20to%20become%20visible%20on%20the%20leap%20day.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EHow%20can%20I%20test%20my%20code%20for%20leap%20year%20bugs%3F%3CP%3EOne%20excellent%20way%20to%20ensure%20your%20code%20is%20free%20of%20leap%20year%20bugs%20is%20unit%20testing%2C%20using%20the%20%22Virtual%20Clock%22%20pattern%20(also%20known%20as%2C%20%22Mock%20the%20Clock%22).%20The%20general%20idea%20is%20to%20treat%20the%20system%20clock%20as%20a%20service%2C%20rather%20than%20as%20a%20simple%20property%20or%20method%20call.%20You%20can%20then%20test%20this%20service%20in%20the%20same%20way%20that%20you%20might%20test%20any%20other%20service%2C%20such%20as%20a%20service%20that%20makes%20a%20network%20call.%20The%20advantage%20being%20that%20one%20can%20prove%20deterministically%20that%20their%20code%20is%20resilient%20to%20a%20variety%20of%20dates%2C%20before%20or%20after%20those%20dates%20actually%20come%20about.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENote%20that%20this%20pattern%20takes%20several%20different%20forms%20and%20can%20vary%20slightly%20per%20language.%20Also%2C%20it%20already%20exists%20in%20several%20open%20source%20libraries%2C%20such%20as%20%3CA%20href%3D%22https%3A%2F%2Fnodatime.org%2F%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ENoda%20Time%3C%2FA%3E%20for%20.NET.%20It%20can%20also%20be%20implemented%20manually.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20an%20example%20implementation%20in%20C%23%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%2F%2F%20Here%20is%20the%20clock%20interface%20public%20interface%20IClock%20%7B%20DateTimeOffset%20GetCurrentTime()%3B%20%7D%20%2F%2F%20This%20implementation%20will%20be%20used%20at%20runtime%20public%20class%20SystemClock%20%3A%20IClock%20%7B%20public%20DateTimeOffset%20GetCurrentTime()%20%7B%20return%20DateTimeOffset.UtcNow%3B%20%7D%20%7D%20%2F%2F%20This%20implementation%20will%20be%20used%20during%20testing%20public%20class%20FakeClock%20%3A%20IClock%20%7B%20private%20readonly%20DateTimeOffset%20_value%3B%20public%20FakeClock(DateTimeOffset%20value)%20%7B%20_value%20%3D%20value%3B%20%7D%20public%20FakeClock(int%20year%2C%20int%20month%2C%20int%20day)%20%7B%20_value%20%3D%20new%20DateTimeOffset(year%2C%20month%2C%20day%2C%200%2C%200%2C%200%2C%20TimeSpan.Zero)%3B%20%7D%20public%20DateTimeOffset%20GetCurrentTime()%20%7B%20return%20_value%3B%20%7D%20%7D%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20these%20defined%2C%20you%20can%20now%20depend%20on%20the%20IClock%20interface%20in%20your%20application%20components%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%2F%2F%20Example%20usage%2C%20via%20constructor%20injection%20public%20class%20SomeComponentOfMyProgram%20%7B%20private%20readonly%20IClock%20_clock%3B%20public%20SomeComponentOfMyProgram(IClock%20clock)%20%7B%20_clock%20%3D%20clock%3B%20%7D%20%2F%2F%20a%20simple%20example%20public%20string%20GetOneYearFromToday()%20%7B%20var%20now%20%3D%20_clock.GetCurrentTime()%3B%20return%20now.AddYears(1).ToString(%22yyyy-MM-dd%22%2C%20CultureInfo.InvariantCulture)%3B%20%7D%20%7D%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAt%20runtime%2C%20one%20might%20wire%20up%20through%20a%20Dependency%20Injection%20container%2C%20like%20so%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Eservices.AddSingleton%3CICLOCK%3E()%3B%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20in%20unit%20tests%2C%20we%20can%20use%20the%20FakeClock%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Epublic%20void%20CanGetOneYearFromNormalDate()%20%7B%20var%20clock%20%3D%20new%20FakeClock(2020%2C%201%2C%201)%3B%20var%20component%20%3D%20new%20SomeComponentOfMyProgram(clock)%3B%20var%20result%20%3D%20component.GetOneYearFromToday()%3B%20Assert.Equal(%222021-01-01%22%2C%20result)%3B%20%7D%20public%20void%20CanGetOneYearFromLeapDay()%20%7B%20var%20clock%20%3D%20new%20FakeClock(2020%2C%202%2C%2029)%3B%20var%20component%20%3D%20new%20SomeComponentOfMyProgram(clock)%3B%20var%20result%20%3D%20component.GetOneYearFromToday()%3B%20Assert.Equal(%222021-02-28%22%2C%20result)%3B%20%7D%3CP%3E%26nbsp%3B%3C%2FP%3EWhy%20not%20just%20set%20the%20clock%20forward%20and%20see%20what%20happens%3F%3CP%3EOne%20might%20think%20that%20the%20easiest%20thing%20to%20do%20would%20be%20to%20create%20an%20environment%20where%20we%20turn%20the%20clock%20forward%20to%20February%2029th%20and%20see%20what%20fails.%20While%20this%20might%20work%20for%20small%20individual%20programs%2C%20it's%20usually%20not%20a%20viable%20option%20for%20distributed%20systems%20because%20time%20is%20so%20interwoven%20to%20every%20dependency.%20For%20example%2C%20does%20your%20application%20send%20telemetry%20to%20a%20logging%20service%3F%20If%20so%2C%20how%20will%20that%20service%20handle%20events%20with%20timestamps%20from%20the%20future%3F%20Perhaps%20it%20will%20discard%20them%2C%20which%20might%20make%20your%20system%20appear%20as%20if%20it%20is%20offline.%20As%20a%20more%20concrete%20example%2C%20consider%20that%20most%20web%20applications%20require%20SSL%20certificates%20that%20are%20signed%20by%20a%20trusted%20certificate%20authority.%20The%20validity%20start%20and%20end%20dates%20are%20timestamped.%20What%20will%20happen%20if%20your%20certificate%20is%20expired%20when%20your%20tests%20run%3F%20Lastly%2C%20consider%20that%20many%20authentication%20protocols%2C%20such%20as%20Kerberos%20and%20OpenID%20Connect%2C%20include%20timestamping%20and%20validation%20of%20timestamps%20as%20a%20security%20mechanism.%20Will%20your%20system%20behave%20correctly%20if%20authentication%20fails%3F%20Even%20if%20none%20of%20these%20things%20matter%20to%20you%2C%20are%20you%20sure%20that%20you%20have%20the%20ability%20to%20exercise%20all%20of%20your%20code%20in%20a%20way%20that%20would%20highlight%20any%20problems%3F%20What%20if%20the%20result%20is%20simply%20a%20category%202%20bug%20like%20described%20earlier%20%E2%80%93%20how%20would%20you%20catch%20that%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20actually%20have%20spent%20considerable%20research%20into%20this%20capability%2C%20and%20what%20we%20have%20learned%20is%20that%20time-forward%20testing%20is%20only%20a%20viable%20approach%20for%20testing%20a%20single%20machine%20running%20in%20isolation.%20We%20don't%20recommend%20it%20for%20modern%20cloud%20infrastructure%20and%20applications.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20do%20decide%20to%20try%20it%20anyway%2C%20be%20sure%20to%20first%20disable%20all%20time%20synchronization%20services%20(NTP%2C%20w32tm%2C%20Hyper-V's%20VMIC%20Time%20Provider%2C%20etc.)%20%E2%80%93%20otherwise%20your%20clock%20might%20simply%20correct%20itself%20during%20your%20tests.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EConclusion%3CP%3ELeap%20year%20bugs%20aren't%20always%20disastrous%2C%20but%20they%20certainly%20can%20be%2C%20and%20leap%20day%20is%20just%20around%20the%20corner.%20Please%20take%20a%20few%20minutes%20now%20to%20go%20look%20at%20any%20code%20you%20might%20have%20in%20your%20application%20that%20manipulates%20dates.%20Think%20about%20what%20will%20happen%20when%20one%20of%20those%20dates%20is%20February%2029th.%20If%20possible%2C%20go%20implement%20Virtual%20Clock%20in%20your%20tests.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20talk%20to%20your%20colleagues%20about%20leap%20day%20bugs.%20This%20isn't%20specialized%20or%20difficult%20knowledge%2C%20and%20leap%20year%20bugs%20certainly%20have%20happened%20many%20times%20before%2C%20but%20somehow%20we%20keep%20forgetting.%20Hopefully%20this%20time%20we%20can%20all%20work%20together%20to%20make%20leap%20day%20a%20fantastic%20non-event.%3C%2FP%3E%3C%2FICLOCK%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1157279%22%20slang%3D%22en-US%22%3E%3CP%3EIt's%202020%2C%20and%20February%20has%2029%20days%20instead%20of%2028.%20Is%20your%20code%20handling%20that%20correctly%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1157279%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Developer%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FLINGO-BODY%3E

jump-into-leap-year.jpg"2020 is the start of a new decade – or does it start in 2021?" That was the debate on social media as we crossed over into the new year. There was also a lot of talk about remembering Y2K twenty years later, which inevitably led to speculation about how computers will behave in Y2038.

 

However, what's more interesting to me is just how little we discuss software bugs related to leap years, which occur much more frequently than any of these grand events. In an attempt to remedy this, I'd like to tell you a little about leap year bugs, how you can spot them in your code, and what we have been doing here at Microsoft to prevent them from impacting our products and services.

 

What are leap years, and why do we have them?

A leap year is a year which contains an extra day which we observe on February 29th and call a leap day. Because of the extra day, there are 366 days in the year instead of the usual 365.

 

Many think leap years occur every four years, but the exact algorithm is slightly more complicated:

  • Is the year evenly divisible by 4? Then it is a leap year. (Examples: 2012, 2016, 2020, 2024)
  • … Unless it is also evenly divisible by 100. Those are not leap years. (Examples: 1800, 1900, 2100)
  • … Except that year that are evenly divisible by 400 are leap years. (Examples: 1600, 2000, 2400)

Leap years are an important part of our calendar system, as they keep seasons and astronomical events from drifting from one year to the next. This is because the mean time it takes for the Earth to actually go around the sun is slightly more than 365 days, but not quite 366 days. The leap year algorithm approximates this as 365.2425 days – though it's important to note than no given year has a fractional number of days in it. Rather, we decide when to add an extra whole day and when not to.

 

For more detail on the science and history behind leap years, see the leap year article on Wikipedia, or watch CGP Grey's excellent short video on YouTube.

 

Note that this information refers to the proleptic Gregorian calendar, which is the primary calendar system used in business and computing today. Other calendar systems (such as the Buddhist calendar, Hebrew calendar, Hijri calendar, and others) have different rules for observing leap days or months.

 

What about leap seconds, time zones, daylight saving time, time on Mars, relativity, etc.?

While all fascinating topics, none are related to leap years. Even leap seconds – despite having the word "leap" in them, are related to a completely different phenomenon, and thus I won't dive into them in this post.

 

Ok then, What is a leap year bug?

A leap year bug is what happens in software when programs that work with dates do not correctly take leap years into account. They might simply misapply the leap year algorithm, or they might ignore the difference between leap years and common years when manipulating dates.

 

I can demonstrate this without any code at all. Let me ask you a simple question: What date will it be a year from today? Let's say that "today" is January 1st, 2020. Got the answer? Now think about how you figured that out. Likely you did something like this:

  • 2020 plus 1 year is 2021
  • Today is January 1st
  • The result is January 1st, 2021

If you did that, congratulations! You have just created a leap year bug! Don't feel bad, even the very best software engineers sometimes do this.

 

Not getting it? Ok – let's try that exact same process again, but this time let's say that "today" is leap day – February 29th, 2020:

  • 2020 plus 1 year is 2021
  • Today is February 29th
  • The result is February 29th, 2021

See the problem? The resulting date does not exist. 2021 is not a leap year, it is a common year and thus February only has 28 days in that year.

 

As a human being, if you were looking for February 29th on the calendar and it wasn't there, likely you would just pick February 28th and move on to better things. Computers, however, only do exactly what we tell them to do, and in many programing languages invalid input is expected to return an error.

 

What kind of impact can leap year bugs have?

Leap year bugs typically fall into two impact categories:

  • Category 1: Those that lead to error conditions, such as exceptions, error return codes, uninitialized variables, or endless loops
  • Category 2: Those that lead to incorrect data, such as off-by-one problems in range queries or aggregation

It's generally Category 1 bugs, such as the one described above, that are the most concerning. These are the type that are responsible for cloud service outages, bricked personal media players, airport baggage handling mishaps, and catastrophic industrial equipment failures.

 

Category 2 bugs do not typically lead to outages, but that doesn't mean they aren't important. They occur when "365 days" is substituted in place of a year – akin to calling a month "30 days". Most of us know that not every month has 30 days. It may suffice as an approximation, but is no good when you need a precise answer. Likewise, adding 365 days is fine if you need "about a year", perhaps for an expiration date. However, it won't lead to correct results if you're calculating financial reports or figuring out how many years old someone is.

 

What is Microsoft doing to protect me from leap year bugs?

Leap year bugs can be incredibly challenging to find, especially in large projects. It's even harder if you need to sift through billions of lines of source code across many different divisions of a company like Microsoft. However daunting the task, we've been taking leap year readiness quite seriously in order to reduce the risk of impact to our customers on Feb 29th. Over the past 9 months or so, I've been working with a small team of engineers in Azure to prepare the company for leap year. We've been searching through source code looking for potential leap year bugs, through both manual and automated approaches. We started within Azure, building upon some of the efforts from 2016's leap year, then expanded our scope to include a much larger portion of Microsoft. Tens of thousands of source code repositories have now been scanned, and are continually being scanned as new code is written by product teams.

 

A large part of the challenge is positive identification. Many of the items we find may match patterns associated with leap year bugs, but turn out to be benign. For example, we might detect that a year of a date is being incremented but miss that the day is always the 1st of a month – in which case there is no problem. We also tend to find more issues in test code than in code that makes its way into a product or service. Tests can still be important, as many teams depend on passing tests in order to build and release updates. In order to address these challenges, we've enlisted the aid of thousands of Microsoft engineers on each of the product or service teams. They examine our findings, triage them, and take action where necessary. Through this tedious process, we have identified and repaired many leap year bugs well before they can become an issue for customers.

 

Azure Engineering has fully audited the Azure services and supporting services, libraries, and operating systems for leap year issues. While the code has been reviewed extensively, we also recognize that this is not a foolproof process and one approach is not enough. As we want to protect our customers in every way possible, we have prepared the company through multiple avenues including:

  • Code scanning, testing, and manual review where necessary
  • Documentation of the leap year risk, the code patterns involved, testing approaches, and past occurrences
  • Training sessions and presentations, both to existing engineers and to new hires
  • Participation in internal events to raise awareness among engineers and product managers
  • Broad internal communications of our efforts through both email and physical posters hung around campus
  • External communications, such as the blog post you're reading now
  • An action plan for the leap day weekend, including heightened awareness, monitoring, and escalation channels

 

I'm a developer. What does a leap year bug look like in code?

Here is an example of .NET code containing a leap year bug, written in C#, that uses the DateTime structure. It is trying to add a year to today, but it is doing it in a way that doesn't account for February 29th.

 

DateTime dt = DateTime.Today;
DateTime result = new DateTime(dt.Year + 1, dt.Month, dt.Day);

 

There are variations of this of course. Perhaps the data type is a DateTimeOffset structure. Perhaps the date doesn't originate with Now or Today but comes from a stored value. Perhaps the number of years being added or subtracted is variable. In all variations, the problem is the same – when the result is a date that doesn't exist, an exception is thrown. (Specifically, an ArgumentOutOfRangeException.)

 

For .NET, the solution is simple. Just use the AddYears method:

 

DateTime dt = DateTime.Today;
DateTime result = dt.AddYears(1);

 

The AddYears method is built in, and works by doing what I said a human might do. It extends the logic to ensure the resulting value is valid. If not, it adjusts to the last day of the month (February 28th).

 

Now let's take a look at some C++ code that exhibits the same problem, using the Windows SYSTEMTIME structure.

 

SYSTEMTIME st;
GetSystemTime(&st);
st.wYear++;

 

At this point, the st variable could contain an invalid date, such as February 29, 2021.

 

Unlike .NET's DateTime structure, the Windows SYSTEMTIME structure doesn't care if it represents a valid date or not. It is just a plain data type containing separate integers for year, month, day, and so on. It is not until the structure is used by a function that these fields are recomposed into a logical date, and it's up to that function on how to deal with invalid dates.

  • Most functions that accept a SYSTEMTIME value will return an error result when passed an invalid date. A good example is SystemTimeToFileTime.
    • It returns a boolean result code, which is TRUE as long as the input date was valid. (Because this is usually the case, developers sometimes don't bother to check this result!)
    • When it returns FALSE, that indicates the conversion failed. The pointer to the FILETIME structure that was intended to receive the output will be left as is. And there's the problem – perhaps that value is 0, representing January 1st, 1601. That certainly won't have the desired effect!
  • By contrast, the SystemTimeToVariantTime function doesn't fail on dates like February 29, 2021. Instead, it is treated as if it were March 1st, 2021. Perhaps this is still a bug for your code, as you may have expected February 28th, but it is the Category 2 type described earlier.

So what is the solution for this C++ code? Well, unlike .NET, there is no built-in AddYears method to call. Instead, one has to ensure the structure has a valid date.

 

Consider the following:

 

bool isLeapYear = st.wYear % 4 == 0 && (st.wYear % 100 != 0 || st.wYear % 400 == 0);
st.wDay = st.wMonth == 2 && st.wDay == 29 && !isLeapYear ? 28 : st.wDay;

 

That may look like a lot, but what it's doing makes sense: First it tests if the year is a leap year. If it's not, and it's February 29th, it moves it back to February 28th.

 

Alternatively, one might consider converting to a FILETIME, adding 365 days, then converting back to a SYSTEMTIME. If doing so, ask yourself if it's ok for the result to sometimes be off by a day.

 

What are common locations where I might find a leap year bug?

One area you might find a Category 1 leap year bug is when preparing valid from/to dates for certificates. Certificates must have valid dates on them, so passing invalid ones will likely fail certificate generation processes. One such API in Windows is CertCreateSelfSignCertificate, which creates a "self-signed" certificate, and is a very common case for a leap year bug. If you have code that generates certificates (via any mechanism), you should examine the logic used for determining their validity dates carefully.

 

Another area where leap year bugs are common is when dealing with anniversary dates, such as birth dates. Did you know that a person born on a leap day is called a "leapling"? I've certainly heard stories from leaplings describing how bothersome it is when some computer system won't accept their birth date, but the risk goes beyond that.

 

Imagine you have a user's date of birth, or date of employment, or date of first login to your website stored in a database. Maybe every year you want to send them a "happy birthday" or "happy anniversary" email, or perhaps an invoice. A common way to figure out when to do that might be to take the month and day from the user and apply it to the current year. If you do just that, then you have a leap year bug that will occur when its not a leap year!

 

Let's see that in C# code:

 

DateTime birthdayThisYear = new DateTime(DateTime.Now.Year, birthDate.Month, birthDate.Day);

 

One approach to remedy the problem would be to figure out the number of days in the month and adjust, like this:

 

int year = DateTime.Now.Year;
int month = birthDate.Month;
int day = birthDate.Day;
int daysInMonth = DateTime.DaysInMonth(year, month);
if (day > daysInMonth)
{
  day = daysInMonth;
}
DateTime birthdayThisYear = new DateTime(year, month, day);

 

Another approach, which is arguably simpler, is to just add the difference in years like this:

 

DateTime birthdayThisYear = birthDate.AddYears(DateTime.Now.Year - birthDate.Year);

 

Really, a leap year bug might be anywhere that dates are being manipulated by some logic, not just these.

 

Are there other types of leap year bugs?

Indeed there are. I described some in my blog post from last leap year. I've also started documenting some of them in this Stack Overflow question (which you can contribute to!)

 

Here are a few to watch out for:

  • Assuming February only has 28 days, without considering the year.
  • Assuming that one can decide whether to add 365 days or 366 days by checking the starting year or ending year.
  • Testing if a year is a leap year, thinking they always occur every four years. (year % 4 is only part of the formula)
  • Declaring a fixed array of 365 elements – one for each day of the year. (Which will fail on Dec 31 in a leap year)
  • Accepting all combination of year, month, and day from user input without checking for validity
  • Using a leap year test to branch your code significantly (especially if the leap year branch goes untested)
  • Parsing a month+day string to a data type that requires a year component

 

What about other programming languages?

Leap year bugs can be introduced in any programming language. However some languages such are not as prone to Category 1 impact bugs as others.

 

For example, in JavaScript,

 

var d = new Date();
d.setFullYear(d.getFullYear() + 1);

 

This code won't fail on leap day, but the Date object will advance to March 1st.

 

Other languages like Python are prone to Category 1 impact bugs. For example:

 

from datetime import date
today = date.today()
later = date(today.year + 1, today.month, today.day)

 

That will raise a ValueError when run on a leap day.

 

With either of these two languages, consider the best option may be to use an open source library for date manipulation.

 

Do leap year bugs only happen on February 29th?

No. Another date that can cause problems is December 31st, as it is the 366th day of a leap year. Some applications may be hard-wired for 365 days.

 

Additionally, not all date manipulate happens around the current date. It's reasonable that a leap day bug could be encountered any day of the year. It's just that a lot of code works with "today" as a basis, so leap year bugs are more likely to become visible on the leap day.

 

How can I test my code for leap year bugs?

One excellent way to ensure your code is free of leap year bugs is unit testing, using the "Virtual Clock" pattern (also known as, "Mock the Clock"). The general idea is to treat the system clock as a service, rather than as a simple property or method call. You can then test this service in the same way that you might test any other service, such as a service that makes a network call. The advantage being that one can prove deterministically that their code is resilient to a variety of dates, before or after those dates actually come about.

 

Note that this pattern takes several different forms and can vary slightly per language. Also, it already exists in several open source libraries, such as Noda Time for .NET. It can also be implemented manually.

 

Here is an example implementation in C#

 

// Here is the clock interface
public interface IClock
{
  DateTimeOffset GetCurrentTime();
}

// This implementation will be used at runtime
public class SystemClock : IClock
{
  public DateTimeOffset GetCurrentTime()
  {
    return DateTimeOffset.UtcNow;
  }
}

// This implementation will be used during testing
public class FakeClock : IClock
{
  private readonly DateTimeOffset _value;

  public FakeClock(DateTimeOffset value)
  {
    _value = value;
  }

  public FakeClock(int year, int month, int day)
  {
    _value = new DateTimeOffset(year, month, day, 0, 0, 0, TimeSpan.Zero);
  }

  public DateTimeOffset GetCurrentTime()
  {
    return _value;
  }
}

 

With these defined, you can now depend on the IClock interface in your application components:

 

// Example usage, via constructor injection
public class SomeComponentOfMyProgram
{
  private readonly IClock _clock;

  public SomeComponentOfMyProgram(IClock clock)
  {
    _clock = clock;
  }

  // a simple example
  public string GetOneYearFromToday()
  {
    var now = _clock.GetCurrentTime();
    return now.AddYears(1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
  }
}

 

At runtime, one might wire up through a Dependency Injection container, like so:

 

services.AddSingleton<IClock, SystemClock>();

 

But in unit tests, we can use the FakeClock:

 

public void CanGetOneYearFromNormalDate()
{
  var clock = new FakeClock(2020, 1, 1);
  var component = new SomeComponentOfMyProgram(clock);

  var result = component.GetOneYearFromToday();

  Assert.Equal("2021-01-01", result);
}

public void CanGetOneYearFromLeapDay()
{
  var clock = new FakeClock(2020, 2, 29);
  var component = new SomeComponentOfMyProgram(clock);

  var result = component.GetOneYearFromToday();

  Assert.Equal("2021-02-28", result);
}

 

Why not just set the clock forward and see what happens?

One might think that the easiest thing to do would be to create an environment where we turn the clock forward to February 29th and see what fails. While this might work for small individual programs, it's usually not a viable option for distributed systems because time is so interwoven to every dependency. For example, does your application send telemetry to a logging service? If so, how will that service handle events with timestamps from the future? Perhaps it will discard them, which might make your system appear as if it is offline. As a more concrete example, consider that most web applications require SSL certificates that are signed by a trusted certificate authority. The validity start and end dates are timestamped. What will happen if your certificate is expired when your tests run? Lastly, consider that many authentication protocols, such as Kerberos and OpenID Connect, include timestamping and validation of timestamps as a security mechanism. Will your system behave correctly if authentication fails? Even if none of these things matter to you, are you sure that you have the ability to exercise all of your code in a way that would highlight any problems? What if the result is simply a category 2 bug like described earlier – how would you catch that?

 

We actually have spent considerable research into this capability, and what we have learned is that time-forward testing is only a viable approach for testing a single machine running in isolation. We don't recommend it for modern cloud infrastructure and applications.

 

If you do decide to try it anyway, be sure to first disable all time synchronization services (NTP, w32tm, Hyper-V's VMIC Time Provider, etc.) – otherwise your clock might simply correct itself during your tests.

 

Conclusion

Leap year bugs aren't always disastrous, but they certainly can be, and leap day is just around the corner. Please take a few minutes now to go look at any code you might have in your application that manipulates dates. Think about what will happen when one of those dates is February 29th. If possible, go implement Virtual Clock in your tests.

 

Also, talk to your colleagues about leap day bugs. This isn't specialized or difficult knowledge, and leap year bugs certainly have happened many times before, but somehow we keep forgetting. Hopefully this time we can all work together to make leap day a fantastic non-event.

10 Comments

Thanks for Sharing with the Community :smile:

Trusted Contributor

Nice one!

Occasional Contributor

Great Information! thanks for sharing this with the community :smile:

Occasional Visitor

Great post @MattJohnson-Pint :)

Occasional Visitor

@MattJohnson-Pint Excellent post.  Thank you for sharing.

Occasional Visitor

Gracias por la Informacion, es muy valiosa.

Occasional Visitor

Random question.

With regards to the calculation of leap years.

 

  • Is the year evenly divisible by 4? Then it is a leap year. (Examples: 2012, 2016, 2020, 2024)
  • … Unless it is also evenly divisible by 100. Those are not leap years. (Examples: 1800, 1900, 2100)
  • … Except that year that are evenly divisible by 400 are leap years. (Examples: 1600, 2000, 2400)

What happens if the year is 10000.

it can be divisible by 4. (2500)

it can be divisible by 100. (100)

it can be divisible by 400. (25)

@Dhivek_Sewpersad Because it is evenly divisible by 400, then year 10000 is indeed a leap year.

Occasional Visitor

I read somewhere every 400 years, FEB gets 30 days ..

 

Any reason why FEB has 28 days (+1 or +2 days) it is not even at start or end of a calendar year to be adjusted ..

Only reason i can think is because as per Zodiac (solar) in north hemisphere, spring starts at March 20 (ideally this should be the new year, not Jan 1) as everyone considered spring to be start of new things / new year in old days ... so i guess they adjusted +1 day just before March started... which happened to be FEB.

thanks for valuable information sir