Telling social media clue Keith Urban and Nicole Kidman's marriage was over months before their split was revealed
Terrified residents claim neighbourhood around London's Regent's Park is a 'no-go zone' after man is stabbed and car ploughs into crowd in 'bloodbath' knife fight
Shocking moment diners scramble to safety after ceiling COLLAPSES
CodeSOD: A Date with Gregory
Calendars today may be controlled by a standards body, but that's hardly an inherent fact of timekeeping. Dates and times are arbitrary and we structure them to our convenience.
If we rewind to ancient Rome, you had the role of Pontifex Maximus. This was the religious leader of Rome, and since honoring the correct feasts and festivals at the right time was part of the job, it was also the standards body which kept the calendar. It was, ostensibly, not a political position, but there was also no rule that an aspiring politician couldn't hold both that post and a political post, like consul. This was a loophole Julius Caesar ruthlessly exploited; if his political opposition wanted to have an important meeting on a given day, whoops! The signs and portents tell us that we need to have a festival and no work should be done!
There's no evidence to prove it, but Julius Caesar is exactly the kind of petty that he probably skipped Pompey's birthday every year.
Julius messed around with the calendar a fair bit for political advantage, but the final version of it was the Julian calendar and that was our core calendar for the next 1500 years or so (and in some places, still is the preferred calendar). At that point Pope Gregory came in, did a little refactoring and fixed the leap year calculations, and recalibrated the calendar to the seasons. The down side of that: he had to skip 13 days to get things back in sync.
The point of this historical digression is that there really is no point in history when dates made sense. That still doesn't excuse today's Java code, sent to us by Bernard.
GregorianCalendar gregorianCalendar = getGregorianCalendar(); XMLGregorianCalendar xmlVersion = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); return gregorianCalendar.equals(xmlVersion .toGregorianCalendar());Indenting as per the original.
The GregorianCalendar is more or less what it sounds like, a calendar type in the Gregorian system, though it's worth noting that it's technically a "combined" calendar that also supports Julian dates prior to 15-OCT-1582 (with a discontinuity- it's preceeded by 04-OCT-1582). To confuse things even farther, this is a bit of fun in the Javadocs:
Prior to the institution of the Gregorian calendar, New Year's Day was March 25. To avoid confusion, this calendar always uses January 1. A manual adjustment may be made if desired for dates that are prior to the Gregorian changeover and which fall between January 1 and March 24.
"To avoid confusion." As if confusion is avoidable when crossing between two date systems.
None of that has anything to do with our code sample, it's just interesting. Let's dig into the code.
We start by fetching a GregorianCalendar object. We then construct an XMLGregorianCalendar object off of the original GregorianCalendar. Then we convert the XMLGregorianCalendar back into a GregorianCalendar and compare them. You might think that this then is a function which always returns true, but Java's got a surprise for you: converting to XMLGregorianCalendar is lossy so this function always returns false.
Bernard didn't have an explanation for why this code exists. I don't have an explanation either, besides human frailty. No matter if the original developer expected this to be true or false at any given time, why are we even doing this check? What do we hope to learn from it?
[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.Experts reveal their secrets to feel better, live longer and transform your health - all in the Your Health newsletter
Millions of motorists lie to their insurer including using 'postcode porky pies' to get cheaper cover
QUENTIN LETTS: She droned on and on like a robot with a bunged-up nose... while our oblong potato of a PM applauded
Princess Eugenie's satin slip skirt is on sale with 50% off - it's almost sold out so we've found others that are equally chic
NFL great mistakenly caught in 'Coldplay kiss cam' moment with young woman on live TV
Mom stuns school board meeting as she STRIPS to protest transgender students using girls' locker rooms
Keanu Reeves gets warm embrace from girlfriend Alexandra Grant after sparking fan concern with disheveled appearance
Asylum seeker paedophile who claimed he didn't know he was doing anything wrong when 'messaging a teenage girl' is spared jail
I booked a hotel for a romantic getaway with my husband. What I saw when we entered killed the mood in SECONDS
VMware bungles cloud management portal upgrade, twice in two weeks
VMware has bungled a portal upgrade project that aims to give its customers a superior experience when managing their clouds.…