- 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
Whoah, one of those code snippets is disingenious:
It might not happen soon, but if you ever want to extend Calendar this little nugget will start spitting exceptions in your face… I can only hope that idiom was used sparingly.
Admin
I can't even make a funny comment about this. I'm just speechless. It's like he's never heard of type safety.
Admin
reads to me more like he has and doesn't trust it. of course if he was coding in C# and didn't want anyone to inherit from his classes he could always create them as sealed and then the type system would take care of his paranoia for him.
Admin
You don't want to know how often similar things appear in the C# code a former coworker left behind.
Admin
Wow... the level of :wtf: is so high it nearly blew the meter! Good thing it didn't; those things are expensive...
<!-- Emoji'd by MobileEmoji 0.2.0-->Admin
I wonder why someone would type “
{1}
“ instead of typing “”. Paid by the character? Also, regex abuse. Perl has a function to get the length of a string; it’s calledlength
. It also has asprintf
function to avoid having to manually prepend zeros.Admin
Yep. I'm the submitter of that little bit - we have had some date WTFs in our code (Why did this invoice upload for January 1, 1900?!) thanks to Perl's... idiosyncratic date implementation combined with the Not Invented Here syndrome some of our previous devs had. I've been using sprintf to replace a lot of iffy string builders as well.
Nearly every time I go in to fix something in the older areas of our application, I end up carving out some useless crap. We've actually set it up to crash on unused variables on the devel server just so we get rid of the huge pile of legacy variables, db queries that are made then never paid attention to, etc...
Admin
Sigh,
Date handling is hard. Its not supposed to be hard for you though. Why developers can't just internalize the lesson use whatever epoch your platform likes and store the date as integer, than use the provided formatting and conversion functions; do not write your own.
Honestly most date time handling WTFs come down to someone could not be bothered to RTFM. These are all solved problems if you are working with any modern language from plain old C onward.
The two real exceptions are when you have to deal with dates that may be a mix of Julian and Gregorian and when you have to move data between systems using different epocs; which is generally easy except when there are conditional rules you need to be aware of about which epoc is used, (looks disapprovingly at Excel).
Admin
Everyone who uses any .NET language - even if just during 5 minutes of their life - should have these two articles bookmarked:
https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
Admin
It seems like a poor man's check whether you haven't been passed a
ChineseLunisolarCalendar
by accident. I don't vouch for it actually working though...on the other hand, I see nothing wrong with - maybe they interface with a system that uses 9999-12-31 as a placeholder of sorts, and want to bring it to the common denominator? Or does
mean there's some weird MaxValue quirk I'm not aware of?
Admin
Admin
This article feels a bit dated...
Admin
:rimshot:
Admin
However, if I'm reading that right (I'm not a .NET guy), only the Date part of that is being used; the
23:59:59.9999999 UTC
part is being ignored in the comparison and discarded in the assignment. So the code snippet is, indeed, a NOP. (Alternatively, if the time component is not ignored in the comparison, the comparison will always fail. Again a NOP.)Admin
Why does the code care at this point though? :facepalm:
Admin
Obligatory Joke:
Q: Why do programmers confuse Halloween and XMas? A: Because DEC 25 == OCT 31
:rimshot:
Admin
But the business-day function makes me despair. Deciding if a particular day is a business day without a database - that is, 100% algorithmically - is a difficult problem, and is best solved using a database. (Even if the problem is specified as "without a database", the best solution is to use a database. In this context, "best" is usefully translated as "only viable".) For starters, once you go beyond one particular group of countries, testing for weekends as "Saturday and Sunday" fails - the weekend in Israel is "Friday and Saturday", for example. Public holidays can only sanely be handled by a database because of the number of exceptions, changes, and so on.
Like much in the business world, naive generalisations will let you down. Consider currencies. Quick, which of these statements is true?
The answer, of course, is "none of them." Some currencies don't have sub-units at all. Some of the ones that do have sub-units have 1000 sub-units per major unit rather than the more common 100. Two very, very minor currencies have 5 sub-units per major unit. Share prices in London are usually listed in pence, not pounds, but in some cases, the listing currency is pounds, not pence.
EDIT: Fixed the quote. Discourse is bogus. Or maybe bugus.
Admin
Yeah, DateTimes in .NET are sane (as in, compare by value).
Admin
:+1:
Admin
One thing I've always admired about Java's date-handling library is that if you used it correctly, you could switch to a wildly different calendar without changing any of the other date code. Sure, having to type in "new GregorianCalendar()" was a pain, but that they didn't assume anything about it was nifty. So, for example, creating something that would switch from looking at the Jewish month of Adar to the more conventional month of March is really not that difficult.
Admin
It looks like they had
DateTime.MaxValue
in their database already in a column that allowed DateTime values, but their UI only allowed users to enter dates. So if a user entered12/31/9999
this code changed it toDateTime.MaxValue
to keep their database consistent.They probably had some more WTFy business logic that selected the rows containing
DateTime.MaxValue
for some particular reason, and they didn't want to try to change that in five dozen different locations to ignore the time component of the DateTime so it would also select rows that contained12/31/9999 00:00:00
.Admin
The real WTF with the perl example is that it is definitely not "clever".
if you really want to do what the programmer was doing & avoid standard date functions, you would:
a 'clever' perl programmer would be succinct, invoke a deep meaning of hashes & perl parameter passing, use map & eval and the code would be completely opaque.
the only let-down from a perl point-of-view is that there in no 1000 character regex involved.
Admin
Never mind that fractional United States cents do exist in some parts of the finance world (such as credit/debit card payments)...
Admin
I think I'll manage to survive somehow…
Admin
And gas station signs! :wtf:
Admin
Admin
Referring StackOverflow: http://stackoverflow.com/questions/6127123/net-datetime-maxvalue-is-different-once-it-is-stored-in-database
Admin
Until they do have to care, which is when the problems start (or rather they started a bit before). Dates aren't as simple as they look. For example, it matters a lot whether you're talking about a genuine date or a timestamp when it comes to things like the calculation of differences between two dates, and many calculations are not meaningful at all without knowing about the calendar as well.
7 days ago != 7×24 hours ago.
Admin
Admin
100th's of a penny.
http://www.londonstockexchange.com/exchange/prices-and-markets/stocks/summary/company-summary.html?fourWayKey=GB00B09LQS34GBGBXAIM
[image]Admin
Nope, they round to the nearest penny.
Admin
That Perl "date function" has a lovely gem:
localtime()
is called multiple times for each of year, month, day, hour, minute, and second. That leaves for a nasty ticking landmine when the function inevitably gets called on a date roll-over.Call the function on 2015-12-31 11:59.9998? It could very well return 2015_01_01_12_00.
Calling the function on 2015-01-31 11:59.9990? Hope the rest of the program has sanity checks for the new 31st of February...
(This is not OT, but sweet baby Cthulu on a flaming unicycle this forum feels like the most ADHD mashup of Tumblr, Twitter, and Facebook. Sooo many gewgaws, gubbins, and gadgets expanding, sliding, contracting, popping up, scrolling... I feel like I should be at least 3 decades younger to properly appreciate it...)
Admin
Edit: BTW, the link next to your post means that somebody (me) replied to it in that other topic. Well done, to post a quote-worthy comment in your first post here. :)
Admin
Correct.. its checking for 12-31-9999 @ any time of day, and forcing it to 12-31-9999 @ 23:59:59.9999999.. I would guess so that they can compare against DateTime.MaxValue elsewhere in the code rather than having to come up with their own constant (or worse, hardcoding the comparison all over the place.)
Chances are its coming from a date-only field somewhere that has 12-31-9999 as a sentinel and using .Date is just a safety precaution in case a non-midnight time somehow gets added in.
Admin
On of the few things I like about SQL is that this always displays now()
select if (now() - now(), 'Black hole', now())
as the value returned by now() is calculated at the start of the query and remains constant throughout the query.
Admin
Really? I don't mean to doubt what you say, but that would be the sort of fuckup that you don't usually see in Perl, due to its widespread use by pedantic asshole sysadmins…
Admin
Calendar c = new Calendar();
So they actually managed to create the instance of an abstract class?Admin
Geez, why do I have to explain this? Are you ... No, I won't say it. But please stand over there. Don't worry about the machine with the long tubes pointing at you, it won't hurt (for long) if it starts up.
Admin
That's a rendering of 538 hundredths of a penny, of course.
Admin
Admin
As the tag line says, Better living through pedantry…
Admin
Perl's date functions are well documented so you can't blame perl for that one. Besides, wouldn't it have been the year 19100?
You should have seen the bugs when someone decided they didn't want to see 24 hour time in the UI. It actually made it to production where it went 11am, 12am, 1pm. That's right, they didn't test for midnight and midday properly. I also replaced hundreds of lines of manual date flinging with a series of one-liners.
I shudder to think what is going to happen when we try and expand into markets with different expectations for date formats.
Admin
TSQL smalldatetime also has this irregularity:
The system I work on now has 173 smalldatetime columns because they are "optimized for reduced space usage", while causing many, many missing results due to this value resolution misinterpretation. :wtf:
Admin
We handle it by not scheduling any batch jobs between 11 PM and 12:15 AM. Seriously.
Certain advantages to doing accounting and billing software...
Admin
Admin
Efficient!
Efficient and effective!
ANOTHER GREAT OPEN SOURCE PROGRAMMING LANGUAGE!
Admin
Doesn't always work. For example, if you're storing the date and time of a future appointment, you pretty much have to do that in local datetime component form, complete with tz; store it as epoch+offset and you risk being screwed over by a change in Daylight Saving rules.
Admin
that's what Julian Dates were invented for. Store as Year+day index in year+decimal pecentage of day elapsed (or HH:MM if you insist)
well ok they weren't invented for that but they do neatly sidestep the issue (until someone fucks up their handling of Feb29)
Admin
So, to cut this short, our calendars are TRWTF.
The sooner[1] we move to a stardate equivalent, the happier I'll be.
[1] - See also: never
Admin
you just had to defuse a perfectly good flame war, didn't you?!