- 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
(I'ld include an example but I lost the ability to write javascript)
Admin
Trans: I have a number (price)
Admin
But that's the definition of years in perl - $date[5] contains year minus 1900. You can call this a mistake in the perl api, but that's the way it is now.
Admin
Strictly speaking, it will work after 2016 as well. It just won't work between the hours of 23:59:41 and midnight GMT on February 29th every 4th year afterwards.
Oh, it will also work every 400th year from 2400 onwards, assuming we're still using the same calendar then.
Admin
Oi, speak for yourself mate!
When I was new, I implemented my own gmtime function (well, localtime actually, and no daylight savings support). Unlike the silly ANSI standard, my function returned the correct year, so I never had to add 1900 to anything.
In my defense, I'd like to point out that to link against gmtime I would have had to shell out $90 or so for a C compiler on my platform.
My implementation of "19 seconds in the future" (although "20 minutes into the future" would have been more likely in the era when I was young ;-) would have looked pretty much like Yuri's, if Perl had existed at the time.
Admin
I thought the real WTF was that the replacement code doesn't do the same thing as the original code.
Admin
Admin
I'm also interested in what they did with @date after that.
Personally, in perl, I pass a date format and the output from localtime/gmtime to POSIX::strftime(), but I bet he formats it manually, too.
Admin
The real WTF is using VB. Oh, wait...
I don't see any code in the second post. O_oAdmin
There's another bug you've all missed: the code for December doesn't check the day before incrementing all the way to January 1st!
Admin
Oh, and the conversion done to the hours will also break at certain times of the day, as there's no check for the hour exceeding 23.
Admin
Oh, but it is. Perl returns the year as the number of years since 1900 -- a reason why in the glorious year 2000, a lot of sites were showing '190100' as the year. Yeah.
So actually he did get that one right. The rest of it is seriously screwed up.
Oh, note to submitter ... 'gmtime' is not a library, it's just another function call, just as 'time' is ;)
Captcha: yummy -- which this perl code definitely is not!
Admin
Well - MS is advising their broken excel-time as a ISO-standard with ms-ooxml (based on 1900 too).
Q.: How do both solutions handle daylight-saving-times? Perhaps the second solution does?
Admin
Admin
no.
Admin
Actually there are so many real WTFs, I'm not sure I can count them.
Admin
Well, the code in the post doesn't handle DST at all. I'm not sure about MS's implementation, I'd assume that it does handle it though. As for gmtime, I'm not sure if that's a locale that participates in daylight savings time offsets. The localtime function will do it automagically if you're in a locale that uses DST, and won't if you're not, provided of course that you've correctly set up your time zone/locale in the application's environment.
As for the offset from 1900 thing, I'd imagine it was decided on for the purposes of efficiency and longevity.
Admin
Huh? I may be missing the joke, but a leap year is a year where February has 29 days, by definition. It's the same thing.
The rule in the Gregorian calendar is actually (pseudo-code):
is_leap_year(x) = is_divisible(x, 4) and ( is_not_divisible(x, 100) or is_divisible(x, 400))
Now if you do the math this means that the average year in the Gregorian calendar has 365.2425 days, which is quite close to the mean length of the tropical year (also called solar year), which is about 365.2422 days.
Admin
The last post in that thread (according to the googlefish) is "The Wild Chair" saying "fortunately that I am not paid with the line of code :)"
Admin
Of course, the real WTF is the calender system that makes date calculations so interesting in the first place.
Admin
I did something similar not too long ago when I needed the time and date with an offset in LSL. But at least I googled first, although the result of that was not a few stupid meaningless variable names short of a WTF on its own. But surprisingly enough, it worked:
Admin
I wonder why (s)he is using a comma as a thousands separator - don't the French use "."?
Admin
So you have a better one all worked out then? One that accounts for the idiosyncrasies in the Earth's orbit, the changing seasons, the varying length of a solar day, makes a lunar month fit onto a solar calendar?
The calendar we have is a good fit for the needs of the actual people on the planet. I realise that Julian days, or just abolishing the concept of days altogether and using the UNIX epoch would be easier for us programmers, but I don't think the rest of humanity would agree...
Admin
A better calendar would realize that it cannot be done and just ignore the lunar cycles. The Gregorian calendar pretends to honor those cycles, but fails quite badly, so nothing would be lost if we abandoned the concept of months. The day should remain the basic unit of any calendar since day-night cycles are so fundamental to life on Earth. Years are also worth keeping because of the importance of seasons. But months? I know some women think that the moon controls their menstruation, some farmers think it affects their crops etc., but even if all that's true, for one, whatever lunar cycle you take (sidereal, synodic etc.), you end up with something that does not evenly divide the year at all, and secondly, it takes rather more to justify inclusion in a general calendar, so it's not worth the effort to try and shoehorn true lunar months into a solar calendar.
Admin
s/Perl/Unix/
Admin
you guys are missing an important point. consider how much programmers (even second rate programmers) get paid.
now imagine a boss who knows little or nothing about programming, who asks his programmer to create this 19 second addition.
If the guy submits that one line of code, the boss will think "This is what I pay so much money for ??? my teenage nephew could do this"
If however a complicated function, which more or less works, is submitted, the boss pretends to understand it and goes away thinking his money is well spent.
Admin
Welcome to the Internet. :-p
Admin
Which is why paying programmers per line is a Bad Idea (tm) just don't the PHB's of the world.
Admin
I've seen way too many date/time WTFs in my time.. but a favourite remains (in C#)...
string dateString = DateTime.Now.ToString();
string year = dateString.Substring(...); string month = dateString.Substring(...); string day = dateString.Substring(...);
// now assuming where the year/month/day/etc are going to be placed in the string is already nuts because without locale specification you don't know what DateTime.ToString() is going to return
DateTime nextMonth = DateTime.Parse(day + "/" + (int.Parse(month) + 1) + "/" + year);
Even though .NET has a nice .AddMonths() function, the programmer declined to use it. Needless to say we had sudden failures in December.
Admin
I have my own coding standard for dates which is: "All dates are represented internally as unix timestamps. 'Real' dates/times are parsed/formatted for I/O only." So far it hasn't let me down, although I'm sure someone will now point out why this is a huge wtf in itself.
Admin
This made me laugh - it's a mistranslation of a typo. Should be: "J'ai des nombres (prix)" and "I have some numbers (prices)". Whaddya mean, "So what?"?
Admin
If that is so (well, in any case), in France (like most/all of Europe) it would have been 2.500.000,00 rather than 2,500,000.00 .
Admin
By the way, those aren't hypothetical situations - I've encountered both of them recently. Assumptions are the mother of all WTFs.
Admin
Luckily there aren't too many major landmasses at that longitude in the Southern hemisphere.
Admin
I can figure out what the programmer was probably thinking in some parts of this code, but can anyone guess what was going through his mind when he wrote:
What's the significance of 41 seconds and 19 seconds?Admin
That code is equivalent (for positive $sec) to "$sec = ($sec + 19) % 60" - now do you get it?
Admin
Admin
Admin
That was just the specification of the job he was given; from the article:
As for a suggestion of where that requirement may have come from, Alexgeig suggests above:
HTH. HAND.
Admin
imho.. all servers and databases should stick with GMT ... and display the local time correctly using the proper library to deal with headaches like time zone offsets and daylight savings..
The programmer isn't a "newfie" either.. those folks live in an area that is GMT-3:30 (or GMT-2:30 during daylight savings).... don't ask... /shrug
Admin
I believe this should be filed under "PWN'd"
Admin
The real WTF is the pesky fact the Earth takes 365 days, 6 hours, 9 minutes, and 9 seconds to complete an orbit around the sun. It really should be 360 days. So all we need to do is move the entire Earth-Moon system a few thousand kilometres closer to the sun and all these pesky calendar problems will be resolved.
Admin
It depends on the severity of the application. But your code wont actually work if there is a leap second. Neither does the protracted version of course.
Admin
Indeed, a minute could be 61 seconds.
Coordinated Universal Time (UTC) has leap second used to match day duration increase due to Earth rotation slowing down.
Admin
Um: sub factored_time_calc { shift if blessed($[0]); return DateTime->now->add(seconds => $_[0]); }
Admin
As a programmer, I usually tend to use the same approach. However, there are certain cases where this might be a problem, for example, when you store these timestamps in a database, and you intend to use a different tool to create, for example, reports by month of the same data, or simply browse and query the data by date, with any SQL tool. Of course the queries can be done by calculating a timestamp range, or converting data "on the fly" but the use of date/time sql functions is often a little easier and I guess even optimal for the database.