- 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
And in most cases, you don't actually get either. . .
Admin
I like this better:
The last of Feb., or of Jan. will do
(Except that in Leap Years it's Jan. 32)
Then for even months use the month's own day,
And for odd ones add 4, or take it away*
Now to work out your doomsday the orthodox way
Three things you should add to the century day
Dozens, remainder, and fours in the latter,
(If you alter by sevens of course it won't matter)
In Julian times, lackaday, lackaday
Zero was Sunday, centuries fell back a day
But Gregorian 4 hundreds are always Tues.
And now centuries extra take us back twos.
*According to length or simply remember,
you only subtract for September, or November.
*************************
J. H. Conway, Jan., 1976
*************************
Explaination @ http://www.cs.wustl.edu/~ksl2/mathpoem.html
Admin
I learned Zeller's congruence algorithm. in 8th grade...29 years ago... avout page 20 of my algebra book.
wwalker
Admin
Register. The captchas will never bother you again. ;)
Admin
Admin
the best implementation of this would be:
function weekday($year,$month,$day) {if ($month < 3){
$month += 12;
$year--;
}
$Cent = $year/100;
$YearOfCent = $year % 100;
return ($day + ((($month+1)*26)/10) + $YearOfCent + ($YearOfCent/4) +
($Cent/4) - 2*$Cent ) % 7;
}
Admin
Maybe it's copied from Java's Calendar class, the central WTF that all other Java WTFs emanate from.
For the love of God, quote when you reply to someone 30 posts above yours. (POS forum can't get this quote right no matter how I format it. Ironic.)
I think you forgot an intval() in there. (If this is PHP.) Otherwise it should work, but definitely begs for a comment or three to ease maintainers' minds.
Admin
I bet you they would taste like chicken. Yum!
Admin
Apparently PHP convert the the operands to an integer when using the % operator, So it has no effect whether I use intval() or not. As for the comments, I think the code is simply enough to not need comment (although I should comment the preconditions and postconditions).
Admin
I had a teacher once (grade 3) that always tried to correct me on grammar and I would always reply, "who cares". So I will say the same thing to you, really who cares whether his spelling was incorrect, as long we know what he meant, it's fine.
Admin
I used to feel the same way. Then someone explained it to me: language is only useful if we all agree EXACT meaning. If I do not use exactly the same definition for a word that you use, we cannot communicate. This is already a big problem, and the only solution is to care enough use only words where everyone agrees on the exact meaning (given context).
There are some words/phrases that should not be used because definitions are not agreed on. (To table an item has a different meaning in England and the US) Others should not be used because in the few cases where you need the difference it isn't clear what you mean. (Normally 'can' and 'may' could be used for the same meaning, but once in a while it is critical to get the right meaning)
Not that I'm very good at it, but I've come around. Language must be used carefully and precisely; otherwise we are not communicating even though we exchange sounds.
Admin
Think of some of the longer WTFs posted here over the years.
Now suppose you are refactoring such code because the company went from 7 to 8 branch offices. No surprise that the number of offices was hardcoded in as a number all over. While doing this you come across the following line:
s = u/7;
Is this a simple date calculation (day = totaldays / DaysInWeek) or is this an attempt to evenly split the CEOs time between all offices? (DaysCeoSpendsAtEachOffice = DaysCeoSpendsOnMoral / NumberOfBranchOffices) In both cases you are dealing with dates, but you need to change one instance. In typical WTF fashion the variable names themselves are worthless for helping you. So do you change the 7 above?
Admin
Good point - it's only the submitter's contention that this is PHP, not Perl.
Admin
Slightly off-topic, but I do wonder what "isn't in my Perl reference" means. I suppose, at least, that Darin doesn't use google et al, so he won't be able to screen-scrape the Perl abortion equivalent to this. I can't remember whether it's in the standard distribution (presumably it is), but if you need Unixy APIs like mktime, Darin, I strongly recommend downloading the POSIX module from CPAN. And then checking things up through pod2man, obviously...
Can't be bothered to quote the post from way up above, but what is this concept of "optimising PHP," anyway? The whole point of PHP is that it's simple and you don't bother to optimise it. If you want an optimised web-site, use a more suitable language. (Or write your own PHP extension. Yeuch.)
Admin
Suspend disbelief for the moment and pretend that people might want to use this function on negative years, ignoring the fact that our calendar system hadn't been invented yet. We assume that intval($leap_years/25) rounds towards zero, but we want to always round down. Bear in mind that for negative a, a % 25 returns a number in the range [-24,0] and this WTF line of code almost makes sense.
floor($x / 25) == intval($x / 25) - ($x % 25 < 0 ? 1 : 0)
The real WTF is that similar treatment is not given to intval((intval($leap_years/25))/4) so that even after all this work, we'll still get the wrong answer for negative years.
This is actually not a WTF. As I mentioned before, the % operator sometimes returns negative values for negative inputs (in PHP, as well as C and Java) but we want this function to return a number in the range [0,6]. Hence the little fiddle at the end.
Edit: The real WTF is I didn't notice this thread has a page 2. Sorry if all this is redundant :(
Admin
The value $leap_years is calculated from the original $years, before we subtracted 1970. So the point where we start losing leap years is actually the year zero.
As far as I can tell it works fine... anyone care to enlighten me on this one? (Though of course it won't work if you enter a date in the Julian calendar).
Admin
I'm intrigued to know where David himself comes from. He either himself works in an outsourcing company somewhere in Asia, or he's a script-kiddie whose pwn3d everyone with his m4d c0d3z.
Admin
Well, it seems David did the biggest WTF... Why on Earth did he think that a function called "Weekday" ending with a modulo-seven - was supposed to return a timetamp? Even now, he might be breaking what wasn't broken.
Admin
Admin
Admin
Consider that for a Chinese developer, these calendar issues are alien to him. China does not use the Gregorian calendar (ending year 4704 now), have years as short as 353 days or as long as 385 days (leap years with 13 months) and the "week" concept is not as important. So probably the chinese programmer just searched for the code somewhere and copy&pasted it.
Admin
I care. It's not like I'm one of those people who regularly corrects people's spelling, but "codes" in particular bugs the hell out of me. I'm not really sure why, it's just a huge pet peeve of mine.
And yes, I will think less of you if you use the word "codes" in place of "code".
Admin
Bullcrap.
The traditional Chinese calendar is different, but China has been using the modern Gregorian calendar for years now. Anyone who has been trained enough to do software development understands the Gregorian calendar. (U.S. addresses on the other hand, are a different story. I spent hours trying to explain why sometimes zip codes had 5 digits, sometimes 9. And the whole "middle initial" of people's names? Mass confusion)
Overall, though, this code isn't surprising to me. I spent 2 years working at a Chinese outsourcing shop (maybe even the one from this story). People there think differently than we Westerners do.
But on top of that, it's like it is in the U.S....unglamorous outsourcing companies won't attract the best programmers. They have to hire lots of developers. So they will by default churn out a lot of crap. The good developers, be it in China or here, will be more expensive. You pay for cheap development, you get crappy development.
Admin
On real systems, the time_t returned is specified to be in UTC, but if you need to ensure it is UTC, or need to ensure it is the local time, you should use gmtime or localtime (respectively). Both of those are C89, and I hope you're not going to tell me C89 isn't generic. You should never need a time_t in the local timezone: All internal manipulation should be UTC (or whatever the system's time_t is), and the time should only be converted to display to the user.
Also, most filesystems do use a "time_t". (most filesystems are *NIX filesystems, and are required to use something that is at the very least equivilant to time_t, for unix filesystem semantics to work.)
The C runtime libraries are indeed generally written in C, and unless you're writing them, you shouldn't even consider implementing the same functionality yourself.
Admin
A place where I used to work -- a very big bank, it might even be the world's biggest by now -- used to mandate that each one of their top-level managers offsource a certain percentage of their work. That was when I worked there. I have no reason to believe that things have changed since.
THAT's why there's little incentive for offshore contractors to improve the product -- the money's gonna keep comin' anyway. Remember, these are the people who handle your money on a daily basis.
Admin
All of you don't seem to have much experience with PHP... before version 5.1 php could not reliably handle dates befor 1970, so if this code was supposed to handle them (which is suggested by the %7)+7)%7) stuff) in no way could they have used any of the built-in functions...
Admin
Yes, the code is terrible, in particular if the last line (return) was written as presented.
But, David is also really bad programmer, if he thinks what was written. Also, calling PHP coder "programmer" is really stilted. I will not repeat where he is wrong and it suprises me how many people in these comments call themselves programmers that think that they can read and comment or even correct someone else's code - they can't.
Let me share a funny experience with outsourcing. A major (Fortune 500) US company created a center in Central Europe. It happend that people on a project running in US needed some help, so they hired one man in that center. After five years, there was the same number of US based and CE based developers. The US based programmers were not able to do anything useful (except one, which was really excellent programmer), they didn't know even basics of object-oriented programming ("I was not trained to do ..." was their favorite sentence), and they even took GPL code and copied it into the (closed source) product - just deleted some of the comments. And that didn't happen only once. After seven years, only higher management stayed in US - there was no US developer on the project. 3/4 of them were fired, the rest went to steal GPL code to other projects within that company, the only good programmer left the company. Of course, the project continues, better than before, because it could be redesigned and rewritten when the US staff left, and the product sells pretty well.
That's my experience about how good and honest are some programmers...
Yes, I am biased - I am a former CE-based programmer on that project, I worked on it for a few years.
Admin
int DateToDay(int InDay,int InMonth,int InYear) { // Returns the day of the week from the date int OutDayID;if(InMonth<3){InMonth+=12;InYear--;}OutDayID=(InDay+(((InMonth+1)26)/10)+(InYear%100)+((InYear%100)/4)+((InYear/100)/4)-(2(InYear/100)))%7;if(OutDayID<0)OutDayID+=7;return OutDayID-1;}
Admin
cheap NFL Jersey Lewis says the Magic knew they couldcheap jordan jersey beat the Cavaliers in the Eastern Conference Finals cheap mlb jerseys when the the two teams cheap kobe jersey met for Game 2. cheap Paul Smith Shoes It took a miracle shot from LeBron James to beat Orlando cheap nfl jerseys amazing cheap nfl jerseys Bucks are looking very closely at every point guard available in the draft would make you cheap g star think Sessions replica jerseys walk, cheap lebron jersey but it's far replica NFL jerseys, NHL jerseys too early to know. In truth, the Bucks nfl jerseysthemselves haven't f teams are starting to think about what cheap diesel Villanueva would cheap football jerseys look like in their nba jerseysuniforms. One of themcheap penguins jersey might be the cheap baseball jerseys Cleveland Cavaliers. cheap NFL Jersey mlb jerseys cheap nfl jerseys James' no-show after Game 6, we're finally getting down to business. Dwight Howard nfl jerseys and Kobe Bryant will lace them up o decide cheap uggs the best team in cheap north face jacket the NBA. The Magic swept the season cheap jerseysseries from the Lakers, one of that feat (Charlotte was the other) cheap nhl jersey Raptors are they'd cheap tommy bahama also like to another selection there. With cheap moss jersey teams like L.A., Chicago, and Minnesota cheap nhl jersey selling that cheap mlb jerseys area, they're replica NFL jerseys, NHL jerseys likely to find cheap hockey jerseys someone they can work with.cheap nba jersey Portland, Houston cheap pierce jersey failed to shifts lebron james jersey back to Houston for Game 6 on Thursday as the Rockets scurry to make Jordan jerseys adjustments cheap nhl jerseys of the Blazers cheap ugg boots Grizzlies, and it's been cheap nba jerseys mentioned that that cheap nfl jerseys pick could be had as well. Most teamsbrady jersey looking to buy in cheap owens jersey are looking to buy into cheap ugg boots the late first/early second round. kobe jerseys Memphis has cheap baseball jersey picks potentially available cheap baseball jerseys in both those areas.cheap mlb jerseys Timberwolves use all three of their first round picks this year (6-18-28), and while it's all but certain they'll use cheap true religion jeans their #6 pick and probably the #18, replica jerseys that #28 could absolutely be had. For teamscheap nhl jerseys looking to buy into cheap nhl jerseys that part of the draft (see below), the Wolves cheap nhl jerseys
Admin
City Original (www.cityoriginal.com) offers cheap NFL jerseys, cheap NHL jerseys, cheap NBA jerseys, cheap MLB Jerseys, cheap Ed Hardy, cheap UGGs, cheap True Religion, cheap Diesel, cheap G-Star, cheap paul smith shoes, cheap tommy bahama, and cheap North Face products. They guarantee the lowest and cheapest price possible.