Computer
Boeing Has Started Working on a 737 MAX Replacement
Read more of this story at Slashdot.
'America's Elite Universities Have Lost Their Way'
Read more of this story at Slashdot.
Swift To Build a Global Financial Blockchain
Read more of this story at Slashdot.
NASA Backs Lunar Wi-Fi Project To Connect Astronauts and Rovers On the Moon
Read more of this story at Slashdot.
Senators Try To Halt Shuttle Move, Saying 'Little Evidence' of Public Demand
Read more of this story at Slashdot.
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.Climate Change Spurs Rare Hybrid Between Blue Jay and Green Jay
Read more of this story at Slashdot.
Reddit Mods Sued By YouTuber Ethan Klein Fight Efforts To Unmask Them
Read more of this story at Slashdot.
Streameast Reclaims Domain Name Previously Seized By US Government
Read more of this story at Slashdot.
ChatGPT Adds 'Instant Checkout' To Shop Directly In Chat
Read more of this story at Slashdot.
Buyers of RadioShack Accused of Running $112 Million Ponzi Scheme
Read more of this story at Slashdot.
FCC Mistakenly Leaks Confidential iPhone 16e Schematics
Read more of this story at Slashdot.
Afghanistan Hit By Nationwide Internet Blackout As Taliban Cuts Fiber Optic Cables
Read more of this story at Slashdot.
Gavin Newsom Signs First-In-Nation AI Safety Law
Read more of this story at Slashdot.
Open Source Android Repository F-Droid Says Google's New Rules Will Shut It Down
Read more of this story at Slashdot.
OpenAI's New Sora Video Generator To Require Copyright Holders To Opt Out
Read more of this story at Slashdot.
UK Government To Guarantee $2 Billion Jaguar Land Rover Loan After Cyber Shutdown
Read more of this story at Slashdot.
Daylight Savings Time Is So Bad, It's Messing With Our View of the Cosmos
Read more of this story at Slashdot.
Environmental Damage is Putting European Way of Life at Risk, Says Report
Read more of this story at Slashdot.
Microplastics Could Be Weakening Your Bones, Research Suggests
Read more of this story at Slashdot.