Lazy coding practice takes down Microsoft's Azure cloud platform. Someone just incremented the year to a leap year date and didn't check if that new date was good. : programming
Lazy coding practice takes down Microsoft's Azure cloud platform. Someone just incremented the
year to a leap year date and didn't check if that new date was good. (blogs.msdn.com)
Good lord. What programmer just increments a date with an integer? We have extensively
tested and vetted date-handling APIs for a goddamn reason.
Well, it also depends on your environment. I mean, the code I write at home is much more
solid, stable, and easier to maintain, but that's because I'm not having to meet immovable
deadlines with product management forcing feature creep on me.
I agree, but one could hope that a company like Microsoft had learned how to plan
development of software by now.
Microsoft wrote the C# DateTime class which is arguably the best date/time management
API anywhere.
Yes, this makes this problem all the more confusing. They're really aware of
international/locale issues throughout .NET as well as the intricaties of time
management, and yes, DateTime has .AddYears() exactly for this issue.
One may excuse this as a simple oversight, but you have to be really tired or caffeine
depraved as a developer to not instantly realize the issues with "year + 1"...
It's almost as bad as "if (i = 1)" when intending a comparison.
Honestly I'm going to go ahead and defend the guy who did this, I'm 100% sure he did
not do this because he was incompetent or wanted to be lazy (in fact he did the
opposite of lazyness), I'm convinced he was just tired and caffeine deprived, Apple
probably wanted Azure delivered for the iCloud services or something the next day.
If you reckon you're someone who has never screwed up code in a stupid way like this
then you've never really been put under the pump.
Part of our system failed on 2/29 because I did this: DateTime t = new DateTime(2099, DateTime.Today.Month, DateTime.Today.Day);
Definitely not lazy. Simply forgot. Time is a tricky thing sometimes.
I agree that having crushing requirements makes producing good code difficult, but
taking tiny shortcuts like these mean you'll get even less done because you're
constantly having to fix them.
Yep, and even Microsoft has a decent date and time API. Here's the code:
DateTime leapYearsDay = new DateTime(2012, 2, 29);
Console.Out.WriteLine("leap years day is: " + leapYearsDay);
DateTime oneYearLater = leapYearsDay.AddYears(1);
Console.Out.WriteLine("One year later is: " + oneYearLater);
The output is:
leap years day is: 29/02/2012 00:00:00
One year later is: 28/02/2013 00:00:00
Yeah, it's also worth mentioning that it seems like Apple has completely bungled every single
DST switch since the release of the first iPhone. I'm sure they probably got one of them
right somewhere, but it sure seems like I read articles every single time about alarms not
going off, timezones being reset to nonsensical values, etc.
Time is hard. Though it probably should be said, this particular bug isn't one of
trickier ones to avoid.
Microsoft's original Zune had a leapyear issue, too, that caused devices to lock up 'til the
battery drained.
If memory serves me, the peripheral library Freescale provides for their MCU's RTCC had a
bug in it that caused an infinite loop. So basically everything that used Freescale's code
had the same problem.
What is "the same date next year" for february 29 anyway?
Perhaps the real problem is trying to attempt to find a date "next year" at all,
given that there is no single value for "1 year". Perhaps all deltas should be
expressed -- as a best practice -- in terms of a more fixed time such as a second. So, if
you want to put a year expiry on a certificate you're generating, you do
"now() + 31536000 seconds".
Even expressing it as 365 days is more explicit, but there's a reason why Unix timestamps are
so popular as an unambiguous number of seconds since a fixed point in time.
According to .Net's DateTime class, "29 Feb 2012" plus 1 year is "28 Feb, 2013". The code is here
This is what Perl's DateTime does as well On the other hand, Perl's DateTime gets it correct:
perl -MDateTime -wle'my $dt = DateTime->new(year=>2012,month=>02,day=>29); $dt->add(years=>1); print $dt'
2013-03-01T00:00:00
perl -MDateTime -wle'my $dt = DateTime->new(year=>2012, month=>02, day=>29); $dt->add_duration(DateTime::Duration->new(years=>1)); print $dt'
2013-03-01T00:00:00
My question is: why the hell do we have leap years? Who cares where the moon is in
relation to the number I give to a day?