How Meghan Markle used clothes to send a subtle message: Duchess's Invictus Games wardrobe marked a turning point free from royal style constraints
What happens when a US billionaire buys the house next door in a tiny village in Wiltshire
Police update after woman, 19, missing for three days from her Essex home
Property tax shake-up would pile pressure on 'underperforming' London and the South East
After deleting a web server, I started checking what I typed before hitting 'Enter'
Who, Me? It's Monday morning, and a week of possibilities presents itself to IT pros everywhere. Which is why The Register brings you another edition of Who, Me? It's the reader-contributed column in which we remind you what not to do with your day, your week, and your career, by sharing stories of your worst workplace mistakes and the contortions you made to survive them.…
CodeSOD: Functionally, a Date
Dates are messy things, full of complicated edge cases and surprising ways for our assumptions to fail. They lack the pure mathematical beauty of other data types, like integers. But that absence doesn't mean we can't apply the beautiful, concise, and simple tools of functional programming to handling dates.
I mean, you or I could. J Banana's co-worker seems to struggle a bit with it.
/** * compare two dates, rounding them to the day */ private static int compareDates( LocalDateTime date1, LocalDateTime date2 ) { List<BiFunction<LocalDateTime,LocalDateTime,Integer>> criterias = Arrays.asList( (d1,d2) -> d1.getYear() - d2.getYear(), (d1,d2) -> d1.getMonthValue() - d2.getMonthValue(), (d1,d2) -> d1.getDayOfMonth() - d2.getDayOfMonth() ); return criterias.stream() .map( f -> f.apply(date1, date2) ) .filter( r -> r != 0 ) .findFirst() .orElse( 0 ); }This Java code creates a list containing three Java functions. Each function will take two dates and returns an integer. It then streams that list, applying each function in turn to a pair of dates. It then filters through the list of resulting integers for the first non-zero value, and failing that, returns just zero.
Why three functions? Well, because we have to check the year, the month, and the day. Obviously. The goal here is to return a negative value if date1 preceeds date2, zero if they're equal, and positive if date1 is later. And on this metric… it does work. That it works is what makes me hate it, honestly. This not only shouldn't work, but it should make the compiler so angry that the computer gets up and walks away until you've thought about what you've done.
Our submitter replaced all of this with a simple:
return date1.toLocalDate().compareTo( date2.toLocalDate() ); .comment { border; none; }Scramble to save Starmer amid revolt that could oust him before the next election after Mandelson disaster
Rita Ora's glossy look turns heads as she third wheels husband Taika Waititi - while he cosies up to a VERY famous star on the Emmys red carpet
Fans go into overdrive with Taylor Swift rumors after she arrives behind SCREEN and can't be seen at Travis Kelce's Chiefs game
Free firework display over the Essex seaside coming to Southend
Manhunt for fraudster with several names who stole £500k
Javier Bardem leads stars supporting Palestine on Emmys red carpet amid Israeli boycott
The Cosby Show star Malcolm-Jamal Warner honored at Emmys 2025 In Memoriam after tragic death at 54
Breaking Bad star Anna Gunn stuns with youthful appearance nearly 12 years after finale
Stephen Colbert makes a plea for Hollywood to hire his staff after his show's cancellation in surprise monologue at the 2025 Emmys
John Oliver is bleeped TWICE in acceptance speech at Emmys 2025
Jenna Ortega channels iconic 90s movie with VERY revealing outfit at 2025 Emmy Awards
Emmy Awards devise clever new tactic to prevent stars from going overtime on their acceptance speeches
Vintage Essex cafe with amazing afternoon teas that's like 'walking into your nan's front room'
Open source Cloud Hypervisor adds (maybe futile) no-AI-code policy
The Cloud Hypervisor project has introduced a No AI code policy.…