- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Hey, asshole, it's not August 2007.
Admin
If Java's date API wasn't such a clusterfuck in itself, maybe people wouldn't do this kind of shit.
Admin
So you might also want to include just about all of Asia, South Africa, the entire middle east, and several parts of Europe that all use the ISO standard yyyy-mm-dd.
So yes, it really is effectively "UK/Europe" format, and most certainly isn't "Everywhere-that-isn't-USA" format.
Admin
Maybe you can make a better one and release it under the GPL.
Admin
Why use anything else then C or Assembler?
Admin
How right you are, you just forgot to mention the earth is flat.
Admin
It's not java - that is the reason no one is listening to the anti-java crowd - you bitch before you think and you are too quick to show what you don't know.
Admin
This is the best part of this WTF:
Admin
I once watched a coworker scratch his head over his sometimes failing date functions. January through July worked fine, August and September would fail outright, and October through December were just wrong.
He was new to C and didn't appreciate the difference between integer conversion and decimal conversion. Just so you know, the string "08" is an invalid (implied) octal for integer conversions, but it's perfectly fine for decimal conversions with its harmless leading zero.
I laughed 'till he cried, then clued him in. Fun times. Fun times.
Admin
Admin
Admin
Stop reinforcing the stereotype of Americans being ignorant of the rest of the world.
Germany and Afghanistan are US Territories, not states. We liberated them in WWII, but never granted them statehood. They have a similar status to the UK (Liberated in the Revolutionary War) and Russia (Liberated in the Cold War).
Admin
What is it anyway with the compulsion some people seem to have now with wanting to handle all data as strings?
Admin
I blame Python.
In other languages, someone who gets paid $20 an hour (arguments sake) and works for 10 hours gets: 20 * 10: $200.
In Python however, if you treat "20" as a String: "20" * 10: $20202020202020202020
A much better wage!
Admin
You are TheLesserDate. Goodbye.
Admin
I love how he multiplies the year by 10000 and the month by 100. While it will actually produce the correct result, it isn't especially intuitive. Gets around those pesky leap years though.
Admin
However, I've switched mostly to the ISO-8601 standard, for most of the reasons stated above. In fact, some apps actually use a bastardized version of the ISO 8601 format:
yyyyMMdd (we don't need no steeeenkin' delimiterz!)
Oh, what fun. Anyway, isn't this function just doing what this can do?
Date firstDate = new SimpleDateFormat("dd/MM/yyyy").parse(stringDate);
(or something like that.)
Admin
It would make more sense if his method REQUIRED date objects - that way it only needed to check if they were null as the framework should make sure they are valid date objects otherwise.
Then parsing doesn't need to be done by the method - parsing can be done by whatever needs the comparison done, as long as it can form a valid date from it's data.
Admin
Actually, you can't compare date strings using string comparison, unless you can guarantee that single-digit day or month values won't happen. Because then "5/12/2008" would be greater than "18/12/2008". So that is the reason for this (not very elegant, but correct) code. No WTF here.
Admin
Or a little place called China (yyyy/mm/dd).
Admin
All data is strings...
Admin
And it's not even a regular int, it's a short! He probably thought he was being 1337 with this code since he even saved memory space, when in reality this is stupid.
Admin
Admin
Oh man. We are such losers. We can't even handle dates in code, much less get a date for dinner and movie.
Captcha: vereor - A new type of meteor.
Admin
No the 100days in a month and 10000 months in a year is just a form of left shift by powers of 10 so today would be represented as a number 20,080,730 so you can compare them without losing information.
Admin
Germany: dd.mm.yyyy
Just to point out that you can't rely on the / either.
Admin
It even returns a short. How cute. At least he's not wasting memory...
Admin
"No the 100days in a month and 10000 months in a year is just a form of left shift by powers of 10 so today would be represented as a number 20,080,730 so you can compare them without losing information."
I've unfortunately had to use this as a sort criteria in SQL as I could not find a way to get SQL to ignore the timestamp portion of the date when sorting.
Admin
On the brighter side, it appears to handle those fictive dates governments sometimes require apps to use, like 0-Jan-nn, 32-Dec-nn (sometimes even 33 and 34) 01-(Dec+1)-nn and 31-(Dec-1)-nn. (These do exist in government accounting systems)
Whereas a well-educated Date type won't work. Maybe that contractor wasn't so silly.
Admin
What happens to Jared when he does something simple like "if ('12/31/2007' < '01/01/2008')"?
Admin
I'd say he picked 10000 and 100 so that when printed it looks like yyyyMMdd, look at the above example without the commas: 20080730
Admin
Heh. I read this and at first thought, "Dang, this Jared guy is REALLY shallow. The real WTF is that he is comparing two people using code."
Admin
I think you made a typo..
enum LessThanReturnCodes {Unknown, Lesser, GreaterOrEqual, FileNotFound, Maybe, Probably, ImFeelingLucky, ...}
-Dan
Admin
The real WTF is comparing dates based on strings. String-based dates are an initial or final representation of a date only -- internally, all dates should be date-type objects (locale, time zone, etc agnostic).
Admin
What's the difference between Unknown and FileNotFound? I always imagined FileNotFound is returned if you try, say, TheLesserDate("fish", "chips"), so what causes Unknown? TheLesserDate("fish", "girlfriend")?
Admin
I've seen quite a number of experienced and otherwise competent programmers do really stupid crap that begins with the thought, "What to do with this data? Well, let's first turn it into a string..."
<?xml version="1.0" encoding="it-bloody-well-aint"?>Just yesterday I had to fix some backend Java code that had two setXmlData() methods, one accepting Strings, the other byte arrays. The byte array one took the raw data, converted it to String using a hardcoded (i.e. possibly wrong) encoding, then passed it to the other method, which converted it back to bytes using the same hardcoded encoding, passed those into an InputStreamReader which used the platform default encoding (i.e. a possibly different and also wrong one) to turn them into a character stream to feed into the XML parser ... which was perfectly capable of not only accepting raw bytes but also of analyzing them to find the actually correct encoding in the XML header...
I probably should submit that code here.
Admin
Wow! What a kind the language is that? I guess it's not Java.
Well, take a look this. As long as its result is int: -1 lesser, 0 equal, 1 greater, no problem with this, that is java old times without Enums. Taking a deep look you'll see the Date objects are completely wrong. Despite that, the comparising works!.
package org.abstra;
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar;
public class Tester1 { /** * Format: MM/dd/yyyy * @param dateFrom * @param dateTo * @return -1 lesser, 0 equals, 1 greater * @throws ParseException */ public int getLesserDate(String dateFrom, String dateTo){ SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
}
Admin
From the API:
public void setLenient(boolean lenient)
Admin
Nah... 0, 1, 2, and 3 are the most logical return values ever!!!
Admin
The way we write dates in Sweden is so great: yyyy-mm-dd. It's just to compare them as strings.
Admin
Admin
See: http://en.wikipedia.org/wiki/Balanced_ternary
Admin
You only have one byte of memory left to return the result. Now what?
Admin
I like how he redefines delim, just incase a buffer overrun in another unrelated part of the application just happened to trash that particular location in memory in the time between its initial declaration and its second use. His code is impervious to such trivialities!
I'm glad some developers have a clue about writing secure code.
Admin
I love that "on exception, ummm, return 3"
:D
Admin
I think it comes from people not understanding the Unix principle that all data should be transferred as strings, and think that is is best to handle them internally as stings as well.
Admin
Actually I'm working on several data migration projects where dates are coming from dubious sources (varchars in the database, Excel columns with arbitrary formatting, ...). And this is Germany, so you have a wild mixture of German, UK and US dates (and probably some French as well). I think I'm above 70 different patterns now with my rather heuristic date guessing function. So if somebody want's to review some real fun code...
Admin
This is wrong! It should always be:
Admin
Excellent! I always wanted something more impressive than .CompareTo to do this job.
Admin
WHAT???