- 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
Entirely correct, but not the point, as neither 7.5 nor 7 handles any leap years correctly.
Admin
It's a Nagesh grammar nazi. I thought I'd never see the day.
Admin
TRWTF is that some annoying and immature little bitch is trolling this forum by pretending to be Nagesh. Nagesh is a registered user of this site. If you see that the author of a comment is Nagesh(unregistered), you should treat the comment as spam.
Genuine Nagesh comments are (sometimes) funny when used sparingly. When some immature little script kiddie comes onto this forum and repeats the same joke that he stole from someone else over and over again, it makes TDWTF less enjoyable for everyone.
Admin
Admin
Admin
Admin
"Jeff had to admit, the solution was a little bit genius. "
I wouldn't say so. Genius is not writing your own calendar functions.
You asking for trouble there because there are a thousand caveats.
Every system has its own properties such as favouring accuracy or practicality.
If you make yet another one, you have even more to reconcile with when integrating with dates from another source.
Fortunately for him, unixtime is designed for practicality, not accuracy. A second is not a fixed duration in unixtime. For billing, where date is more important than time (at least down to the second).
10 minutes is way too long to workout what that is doing.
He might survive even with that unchecked loss of precision via division and failure to work out the days difference and they times that by DAY last of all. But can he survive missing -2 for his leap year calculation?
Admin
Excellent. Now you can get in on that Google IPO in a few years. And you can short-sell your way to wealth when the dot-com crash comes around again. And you can profit again from the stock market crash of 2008. By the time 2012 comes around again, you should be a very wealthy man.
Admin
Hey, if aint' broke, don't fix it.
Admin
It's not so much that it makes 1974 a leap year. Leap years are usually defined as years that have an extra day on 29th of February. With this code, the extra days are 32nd of December 1973, 1977, 1981 and so on.
Admin
So it was posted in Visual Studio magazine... no wonder.
staring, uhm... 10 minutes? it's more than obvious. whats so genius about that? i guess some geniuses just haven't heard about mktime.
Admin
return ((year-1970)*365+((1970+3+-year)>>2)+months[month-1]+day+(year%4==0&&month>2))*DAY;
That might fix it. At least it's more readable. No more having to shift your eyes around the place. But I don't know C# or mathematics. I'm merely a binman with a GCSE level C in maths.
Admin
2000 was a leap year
Admin
Oops, there is a mistake.
Make that:
return ((year-1970)*365+(year-1973>>2)+months[month-1]+day+(year%4==0&&month>2))*DAY;
Now even easier to read.
Admin
Here you go. Sorry, it's Python.
seconds_jan_1_0000_to_jan_1_1970 = 62167132800 leap_year = (year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0)) seconds_since_jan_1_0000 = ((day - 1) * DAY) + (months [month - 1] * DAY) + (DAY if leap_year and month > 2 else 0) + (int (year * 365.2425) * DAY) return seconds_since_jan_1_0000 - seconds_jan_1_0000_to_jan_1_1970
Admin
Um, print out the code? For what purpose? Making paper airplanes?
My 24" monitor can have as many toolbars next to it as I want. So can my 22" monitor, even though it gives up 2". Get a monitor from this century and find an employer with a hardware budget of more than $5 per developer.
Admin
"Regular" rounding (round half-up) is asymmetric. Banker's rounding is symmetric. When you're dealing with billions of transactions a day worth trillions of dollars, that kind of matters. "Regular" rounding is naive and should probably never be used if calculation of monetary amounts is involved.
Admin
FUUUUU... 1970-year+3.
Are you sure it works?
Here is a tester you can use in PHP:
A generator for the dates you will need for your test case:
Admin
(hint: Leap years occur every 4 years, unless the year happens to end with 00 in which case they only occur if the year is divisible by 400)
Admin
Admin
FTFY. Fucking stupid electrical engineers.
Admin
If we would always strive to fix what appears to work "because it wasn't done properly" nothing would get done exact refactoring. Firstly because there is so much shit out there, secondly because no 2 people would agree on what's good practice - and why should your idea of good practice be any more valid than mine? So you walk in and say "My God, people! This has to be the stupidest way to do things" and refactor everything. Some years later, you leave, and the next expert says "My God, people!! This is a stupid way to be implementing this stuff. Our first task has to be to do this properly".
While you're right, things should get done properly it should be noted that "properly" is subjective and if coders were given the license to dictate what is and what ain't proper then those same nimrods that are writing the shyte right now would be clobbering your good code anyway, so we all still lose....
Unfortunately, the real world doesn't (and I thin can not) work as well as any theoretical world we might try to live in, and once we start arguing about doing things "right" we first need a way of deeming that something is or isn't right (which usually means someone above the techo who doesn't understand enough to even have an opinion about what is right beyond "But it works now, right?").
That's my 2c. I'm Kent Brockman
Admin
Admin
Admin
Many a time I have had to admit the "bad programming" causing issue today is a result of the knowledge I didn't have yesterday.
We all start somewhere, and very few are instantly great programmers - even the best of us (read: me) have written some crap somewhere along the way....
Admin
Admin
One of the issues (made abundantly clear by reading this site) is that in IT there are usually infinite (or close enough to infinite) ways to fix a certain issue. Not all are right, and not all are wrong, but opinions certainly differ on best approaches. Compare this to a mechanic who simply has to decide on the brand of a component and then make it fit the missing part he's replacing....Our role as IT experts is a lot vaguer (which is why most of us have to attend tertiary institutions at some stage to get something that evidences the fact we might actually be able to solve problems)
Admin
Admin
I actually wish more people understood C - not necessarily wrote in C, but understood it....
I've people (mainly in C#, but other languages too) implement bit strings as strings (if(X.at(5) == '1')), repeatedly create new data structures (because they don't understand the underlying work), reuse functions to get variables instead of storing what the value is, etc, etc...
Sure, to make a sudoku solver or a maze application on your desktop the overhead is unnoticeable, but when you write an app that will have many users and performance is critical...well...good to understand what is happneing under the hood. By all means use C#, Java etc (including all the nice data structures that have been made by someone who understands the world far better than you ever will) but write even a simple Linked List in C and you might begin to understand the work that is happening each time you say "new" (and the implicit "delete" (free) that comes with it). C is cumbersome, old fashioned etc - by all means use an OO program that is easy to use but UNDERSTAND WHAT IS GOING ON and you will be a better programmer.
Boy did I sail off course...
Admin
(just repeating: letation and apellation is awesome captha's)
Admin
I'm glad I didn't go to your school, it sounds awfully boring.
Admin
Admin
... and they're perfectly right. Why report the usage of unix epoch as a bug, instead of reporting a REAL bug in the way it was done?
Admin
Why would I pretend to be American? I am not getting your logic, Mr 45.
Admin
If it took "Jeff" 10 minutes to see what that function is trying to do, maybe he should consider a career in a call centre or perhaps in-store customer service.
Admin
Also the reform was in 1582.
Did no one notice Nick V was off by 270 years? Seriously?
Admin
2000 was a leap year. i was there.
century years only avoid being a leap year if they're not also millenium years.
Admin
Yes, it IS better to have code that is rigorously tested - you know, like language provided functions that millions of developers will use as opposed to some code you wrote yourself to use in all your applications over what, a 10 year period? Believe it or not, the former will have been tested more. The problem really comes to light with code like this that probably works in this context 99.9% of the time, until you happen to hit a specific date. For example, next time there's a leap year - or possibly the next time there isn't. Sony had this problem with the PS3 a few years ago when it was expecting a leap year in 2010: http://blog.us.playstation.com/2010/03/01/playstation-network-service-restored/ This only came about after the PS3 had been on sale for a few years and used by millions of people daily.
The above code is a proper WTF because there's plenty of cases where it's flat out wrong, so it's not really defensible. This happens nearly every time you try to reinvent the wheel because too many programmers think they know better than every other programmer out there. So what if you're porting code to a language that doesn't have a similar function, write the function for that language alone and leave it at that. Unless, of course, your goal is to ensure that all bugs are reproducible on all systems.
Admin
Admin
Many Pakistani here write bad date code to show superiority of luner calender. Prob why iPhone have problam every leep year.
Admin
Rubbish. Rounding .5 up is symmetric where as banker's "rounding" is totally arbitrary and stupid. You might as well flip a coin and decide whether you are going to round up or down.
If we have a number 5.x:
if x = 0 -> round down to 5 1 -> round down to 5 2 -> round down to 5 3 -> round down to 5 4 -> round down to 5 5 -> round up to 6 6 -> round up to 6 7 -> round up to 6 8 -> round up to 6 9 -> round up to 6
So for 5/10 values of x, the answer is 5. For 5/10 values of x, the answer is 6. That is symmetric.
And considering that rounding is about precision, you have to consider that there are unknown decimals beyond what you are looking at. So if we round to 0 d.p.:
2.5000000000000000000000000001
Using regular sensible rounding, you get 3. Using bankers rounding, you get 2. Clearly regular rounding is better because the number is closer to 3 than 2.
Admin
No - the WTF is that this code is PLAIN WRONG - at least it does not correctly incorporate the rules for leap years as defined by Pope Gregor VII (at least after my memory)
first - (year-1970) / 4 would incorrectly make 1974 , 1978 and so on a leap year, instead of 1972, 1976 and so on
second - it does not recognize that years dividible by 100 but not by 400 are NOT leap years (1900 was not a leap year) - sure this would occur 2100 for the first time, but a bug remains a bug
third - on computers which follow DST (about EVERY Windows- and Windows-Server-PC) this will produce wrong results for the days within Daylight-period (march to october) - as the starting day of DST only has 23 hours (you move the clock from 2 to 3 , stealing 1 hour) and this hour is corrected at the end ... so you are advised to use the build in date-time-functions which USUALLY support differencies created by DST (even if only by giving them another parameter)
so basically if your system is a "billing" system, I assume its tasks contain automatic escations, when a billing period is missed (even if only by 1 day) - and here you have a system that will erroneously assume every day between 23:00 and midnight to be on the next day - so you might miss you payment period due to bank working methods. I would assume a pile of annoyed customers - and this is clearly not a feature request
Admin
Not necessarily wrong, perhaps Sean’s definition of millennium is a time period of 400 years… I think perhaps one reason why programmers can not even agree which of several ‘correct’ implementations is the ‘better’ implementation is because language sucks. We cannot always even agree on what a given word means, or how to spell it. If Sean wants to call a quad-a-centurion a millennium it is perfectly acceptable. If you want to call a fish a turtle it is also perfectly acceptable. We just need to know the in-depth definition of every word’s usage, as used by another to fully judge if they are right or wrong.
Admin
It does account for leap years for the next century at least, but what about leap seconds? and what about timezones? and what about daylight savings? It is obvious the original programmer doesn't have a single clue about how to handle dates in software.
Admin
I totally agree, fuck bankers.
Admin
Admin
If we have a number 5.x:
if x = 0 -> doesn't round at all, because it's already round 1 -> round down to 5 2 -> round down to 5 3 -> round down to 5 4 -> round down to 5 5 -> the point of controversy 6 -> round up to 6 7 -> round up to 6 8 -> round up to 6 9 -> round up to 6
When you round 9 up you're deviating by the same amount as rounding 1 down, so they cancel each other. But 5 doesn't cancel with 0: one is the worst possible deviation and the other is no deviation at all. That's why there are algorithms that do not round 5 the same way every time.
Admin
While in spirit i fully agree, i wonder what do you propose when the code to refactor/rewrite is about 20 million lines or more :-<
Admin
Well if you rewrite it correctly, it'll go down at least two orders of magnitude so don't think it's impossible ;)
Do it bit by bit, and get paid a fckton doing it is what I propose.
Admin
Straight answer: it's a regionalism for "isn't," "aren't," or "am not."