- 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
Eh, not right around daylight savings time transitions, I don't. The loops are quite OK. Especially if setHours is really deprecated, as my quick google-fu seems to show.
Admin
Admin
I'd go with discountTotal = 1 - (2 * 1);
Admin
So, something else instead ? Like a "wishDate.SetHours(..)" method ? If not, any (logical) reason to its absense ? I guess it's not available, as I've not seen anyone even hinting at it.
Admin
Not having setable fragments of a DateTime is just common sense - it makes sure you don't have to perform validation on every change (e.g when someone tries to set Days to 30 when Month is February). This way you have to manipulate DateTime objects consistently regardless of which fragment you're changing.
And yes, DateTime is really hard to implement nicely.
EDIT: although I'm sad we've gone through more than 50 comments already and no-one's done a "Limitations? On WISHES?" yet.... sigh
Admin
Its ugly as sin ofcourse, but it gets the job done if there is no better method for it available.
Admin
Admin
How is that any different mathematically than the solution that you're trying to fix?
Admin
So is this a submission from a web version of Pac-Man?
Admin
I mean, if you think that is true what about adding something to a date resulting in one (or more) of its fragments rolling over ? The check for, and adjustment of that would be the same for setting something. Or do I see that wrong ?
Admin
Admin
Why wouldn't you use strings for negative numbers?
Admin
Are you suggesting that (Feb 5).SetDay(30) should result in a value of (March 2)?
Admin
+1
Except... think of all the overhead you save by not invoking the while loop when the if condition isn't met!
Admin
Admin
Somehow I was thinking about hour-values not ordered in a logical sequential order when using a 12-hour clock, and somehow thought that would solve it. I guess I got caught up in my own thoughts again. I can only blame a lack of coffee.
Admin
How many programmers does it take to do Date/Time calculations?
Apparently quite a few, and they ALL get it wrong. On the other hand, simple arithmetic is way out of bounds for some people's comprehension. The learning of simple identities from 6th grade math was the part of class many slept through.
Life goes on (SIGH) Now=1393349503.
Admin
Question: Why should .SetDay() do something different than .AddDay() when encountering an impossible result ?
Admin
TDWTF needs a new sponsor...
Admin
You can see why AddDay is more intuitive than SetDay. I can see the (pseudo)code/unit test:
(April 5).SetDay(31) Assert(DateObject.Month == 4)
Admin
The date object could ofcourse just throw an error when it detects a faulty argument, but I thought that automatically adjusting it would possibly be more usefull.
Maybe the SetXxxx method could have a default "throw error" setting, using a second, not required argument to overrule it (or vise-verse).
Admin
I would suggest that (Feb 5).SetDay(30) should result in a value of (Feb 30). Of course I would also expect (Feb 30).IsValid() to return false. Alternatively it could throw ArgumentOutOfRangeException just like DateTime(2014, 2, 30) does.
Still I don't see the connection of not having a SetDay and not having a SetHour. That the first could yield invalid dates does not automatically mean the second one would do so, too. Or are there any days, where the hour is not in the range [0..23]?
Admin
Nope. "Twitch plays DateTime programming."
Admin
Yeah, but I think that would make the code even more convoluted and harder to maintain. Much better to have Add(TimePart) instead of Set(TimePart). You could say that it's relatively better. And I definitely do agree that it's more useful, so if I want a specific date and/or time, I construct one, but if I want to change an existing one, I make the change to the existing value, and let the compiler figure out where that goes.
Admin
You should not expect the same behavior because the meaning of the language is different. If someone tells you to "add days" to, say, a deadline, you will naturally adjust the other components accordingly, because that's what it means to add days. It does not mean "set the Day field to the current Day field's value plus 25".
Question: Do you think that (twenty-five plus nine) should result in (twenty-fourteen)? If so, then yes, I think that (Feb 5).AddDays(25) should result in Feb 30.
Admin
Admin
Admin
Admin
Obivously it is: Math.min(discountTotal-2discountTotal, 2discountTotal-discountTotal);
Admin
True. What does (Day before DST switch 02:30).AddDays(1) return? What about the occasional leap second?
Of course there's always a (small) chance you'll end up with an invalid date. With days this is potentially more common than with hours (as long as you use integers within the reasonable 1..31 / 0..23 ranges), but why would this keep you from adding a perfectly useful function to the interface?
As I wrote above: You could also end up with an invalid date/an exception with DateTime's constructor, so why would you leave out functions because they could have the same result?
On a side note: Banks actually use 30 days for all months when calculating prorated interests.
Admin
If dates remain hard for you for more than four hours, please consult a doctor.
Admin
Addendum (2014-02-25 13:53): At least that was my reasoning that led me to this conclusion.
Now having read the other answers my conclusion is: "With a sufficiently advanced lack of coffee any programmer is indistinguishable from a troll".
Admin
I just saw two reverses in a row and wondered what the h&ll was going on. Maybe trying to make the string get dizzy?
Admin
String.YouSpinMeRightRoundBabyRightRoundLikeARecordBabyRightRoundRoundRound()
Admin
Admin
Admin
From the Mono implementation of AddDays:
Dates are hard. Don't make them harder than they need to be.
Admin
Which means if you keep a reference to the original Collection, you can modify the original Collection and will see those changes in the view!
Admin
TRWTF is the umpteenth long argument about ways around using standard DateTime libraries, replete with "dates are hard to program" complaints and "what about THIS corner case" responses.
Can't we find something new to argue about?
Admin
Perhaps it was 80s, New Wave day at the office when that little gem was created.
Admin
My wishDate used to be Ellen Page. Apparently now I need to come up with a new wishDate.
Admin
That's exactly what he did, he wouldn't touch these mocha utilimajiggies, and wrote a very brief and clear alternative.
So what gives?
Admin
Admin
Bah. A mere child. I prefer Elaine Page myself.
Admin
Because if you reverse an M it still looks like an M, right?
Admin
Admin
.NET if far more complex than that. Whether or not an object is actually mutable to the point where changing it's values results in the generation of a new object depends entirely on what the compiler thinks your trying to do. The trick to writing a high performance math library in .NET languages is being incredibly careful, as if walking on glass, to allow it to do in-place modification without triggering the mechanisms that do a create-and-replace.
Admin
Yeah, I can't remember how many times that someone has incorrectly guessed at what the compiler would do. As a (non-real world) example:
Isn't as bad as it appears thanks to string interning.
Admin
Did they test that reversing stripping code on URLs like "http://thpppt.example.com/"?
Admin
My protocol-chopper works like any protocol chopper, except in the chomper I flip it, reverse it and take the protocol down.
Sponsored by https://xkcd.com/153/