- 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
Admin
The Internet would be a better place if we thought of each other as "fellow contributors" and not "opponents." Sigh, tis but a dream...
Admin
Admin
Admin
Admin
But I'm on a little endian CPU!
Admin
Admin
To clarify, I wasn't blaming you.
Admin
-Harrow.
Admin
Oh snap !
Admin
Specifically, if I remember correctly, in Java January = 0 and December = 11.
Admin
Well prior to the Gregorian reformation, the Julian calendar had a leap year every four years; making the assumption that the solar, or equinocal, year is exactly 365.25 days. However it is actually 11 minutes shorter and so the measurable points of the solar year (solstices and equinoxes) drift against the calendar. Very slowly though, today is 11th January in Julian so the discrepancy is still insignificant against the seasons.
Anyway, remember those 11 minutes, well that adds up to three days every 4 centuries. Hence the Gregorian reformation was to have 97 instead of 100 leap days every four centuries. Guess it was just a case of deciding what what the most memorable rule for the 3 to be skipped. They could have picked worse.
Admin
No, its ok. You are the reason why we were inventing exceptions. ;)
Admin
I'll assume your eyes glazed over, but I'd guess that 12-18-2003 giving a "BeginDate" five days after the "EndDate" counts as a problem.
Admin
Right in this age of Wikipedia if you must roll your own date math chances are the formula you need is there. Gauss and other giants solved these problems. Still this does require you to have had some education to know that date math is complex in the first place and the formulas are out there, and that you remember a name or two like Gauss so you know how to search.
All in all a better more simple line of advice is "always use the system date libraries" they exist.
Admin
The real question is why did it suddenly break? If it had been running all that time without incident.
Capthca: odio - the code was odio indeed.
Admin
No. The problem lies with the Earth for having a number of days in the year that doesn't divide neatly into anything. And that's without even taking into account the fact that a year isn't even a whole number of days. WTF, Earth? What were you thinking? It's like you're deliberately making it hard for us.
Admin
So just wait while it further slows down until a year is exactly 365 days, then destroy the moon.
Fixed?
Admin
Of course, they still started at 9:00am the previous day, they just haven't finished yet.
Admin
emaNrouY has a mistake in his version of the code. He is taking the input data from the spreadsheet cells almost everywhere, except at one place he is still using day(curDate). That explains some weird results which are not in fact due to the original WTF code.
Several people commented on those cases without spotting the error, which has me worried... are the commenters here also that WTF-prone? Yes, emaNrouY's mistake is not all that obvious, but still it is obvious that the original code can not lead to those weird cases.
And why at all would anyone need to see the function's result with random inputs anyway? It is pretty obvious what it does and how it fails. Overshooting the begindate as if the previous month had 28 days, and giving month "0" instead of 12, with properly decremented year for inputs 1-6th January but nondecremented year for 7th, is pretty much all there is to it.
Admin
Dammit I was just writing a post about that. Granted it's a flawed chunk of unnecessary code, but it shouldn't ever give dates AFTER the current date.
Also someone else mentioned that there are 2 global variables. I must be a moron, please point them out?
Admin
I'm not complaining, mind, anything that reduces the number of Merkins in the world gets my full support.
Admin
Admin
TRWTF is using VB Script, which is even lower than the horrible VB.NET. They can't use C# with Mono or even C++?! Seriously, using VB Script which has many vulnerabilities in it? You might as well have written it in PHP with
!Captcha: opto - they should have optedto use C#
Admin
CAPTCHA: The image was clipped and appeared as "coqo". Though for some reason I knew it was meant to be "cogo" (and my browser also knew it already), so I got it right the first time. Maybe CAPTCHAs would be more interesting if they clipped half of all the images. Regular posters should have no problem.
Admin
Admin
Blame God, if you have to blame anyone.
Just wait until the Martian colonies need to keep local time (approx. 25 hour day) and Earth time.
Admin
I think we should just throw out leap years.
Yes, yes, at this point someone will say, But that doesn't work. You have to have leap years to keep the calendar synchronized with the motions of the Earth around the Sun.
Who says? Why is that a rule? If we threw out leap years, then in an average lifetime of 70 years or so, each season would shift by about 2 weeks. If when you were born winter begins at the end of December, then when you die winter will begin in mid-December. So what? I think that would be way less pain then having to mess with leap years all the time.
I'd also throw out daylight savings time. If people want to get up an hour later in the summer, why don't they just do it? Why do we need to change the clock so they can call the time they get up by the same name?
And don't even get me started on leap seconds. Fortunately they're generally ignored. But what insane person got the idea that screwing up time-keeping by adding seconds to the clock at unpredictable intervals was somehow better than putting up with the fact that sunrise is 1 second later this year than last year. Does anyone really time anything he does that relates to the motions of the sun that precisely?
I think the convenience of having a more systematic calendar would far outweigh the disadvantages of desynchronization from the sun. For the relatively few people whose lives are directly tied to the seasons, like farmers, so okay, they'd have to get used to the idea that planting and harvest times are not the same date every year. Do farmers actually go strictly by a calendar on this anyway, or do they look at what the actual weather is?
Admin
Are you a troll? Or just very very ignorant?
My guess is that you actually never had to work with time and/or dates in a "real" computer program, or you would never have written something as utterly stupid and arrogant as you just did.
Others already posted the links to myths programmers believe about time, but let me add this for a starting point into just a single pretty banal aspect of time in computer systems: http://en.wikipedia.org/wiki/Leap_second
Yes, sometimes 23:59:60 is a valid timepoint. No, you can not just use the number of seconds since some fixed point. And so on, and so on.
As someone else posted: never, ever, roll your own time/date handling code, unless you really, really know what your are doing, and is prepared to deal with all the weirdness and pain of the human calendarsystems. Also, test all your use of the time libs as much as you can. Remember to include weird timezones, leap days, crossings across days, months, years, and so on.
Proper time and date handling in computer systems is hard to do right. Rely on the built in functionality.
Admin
There is a shocking amount of ignorance about VBScript out there.
Admin
It could be worse; we could experience the martian Sol instead (24.5 hours) Not only does that not neatly divide into anything, it's not even a whole number.
Admin
No, I'm just very, very experienced.
In order to handle date-related functionality in the context of software applications, it is essential to understand, to a greater or lesser extent, the nature of time measurement and the inter-relation of those time units.
What I was suggesting, a little too compactly for those whose ability to think about what they read is smaller than their self-opinion, is that before you can even start thinking about how best to implement a date-based function (e.g. in this case, to get the date 7 days before), it is necessary to have a basic handle on How Dates Work. (Otherwise, for starters, how can you test your implementation and know it's working properly?)
The fact that one would then by preference go to a pre-built date-handling library (if such exists) in order to implement that function is of course a no-brainer. Equally of course, the person who lacks the mental apparatus to comprehend dates would also fail to leap that particular mental hurdle.
One of the first exercises we used to set our new entrants to a particular mathematical modelling team was to develop a program to write out a calendar. (This was in FORTRAN, in the days before Java with its Calendar class). Those members of staff who could not do a good job of that were considered unfit to be trusted to do proper work. (Such people were fortunately rare in those days.)
Hence the concept of using such knowledge as a "pons asinorum" to separate out those who can with those who can't but think they can. Those latter are the ones who we really want out of the profession.
Admin
Naturally. But it's implemented on a very large and ancient legacy system, and we can't afford the OS upgrade costs.
Admin
+1
I always thought the Dim in VB was referring to the person trying to use it.
Admin
Well, thanks for making me a non-programmer and nullifying my 5+ year experience ;-)
My current employer is very flexible with regards to working hours. There are folks who arrive at the office at 10 and leave at 18, there are folks who to the more usual 9-17 or 8-16 days. I seem to be more creative in the morning, so I prefer to be at the office at 7, although sometimes to avoid traffic jams I arrive as early as 6:20.
Admin
But if it was an embedded system without division?
Admin
Tabitha, Tabatha...
To-may-to, To-mah-to...
Admin
Totally. No one here has mentioned the fact that we're incredibly lucky to have been born on a planet with 24 hours in each day, I mean it easily could have been 24.7 - praise Jesus!
Admin
Each of the five small companies I've worked at had home brewed, horrible date and calendar logic just like this article.