- 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
Languages are constantly evolving as ignorant people, pretending to be clever, constantly misuse it.
Admin
new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(1).AddDays(-1);
Admin
Of course you've made a nice heisenbug there if this is executed very very close to local midnight any day of the year. So the problem is 365 (366?) times worse than you think it is. Should've captured DateTime.Today() once in a temp and then decomposed the temp.
Datetime.Now() is even more dangerous since depending on how far you're decomposing it the window of rollover risk happens hourly, minutely, secondly, or even more often.
Ideally these kinds of accessors would have something like a [Volatile] attribute that the compiler could use to detect defective uses like this.
Admin
The corollary to that is always "when you use a library, use it properly". All date-time libraries that I've seen contain a function to add "one month" (however many days it comes out as) to a date, and I'd be surprised if such a library didn't have that.
Admin
"All date-time libraries that I've seen contain a function to add "one month" (however many days it comes out as) to a date"
Now that is TRWTF - because that's not a clearly defined concept.
Admin
It sounds more like you're an oxygen-deprived moron who doesn't understand the difference between "constant and evolving" and "constantly evolving". You may want to look into adverbs and their purpose in English grammar.
Admin
Having test code that runs in CI ? in a TDWTF entry ? I call BS.
Everybody knows that TRWTF is to have such code running in production for at least 10 months.
Admin
Like the way some people (mis)use the word fascist?
Admin
If you don't overthink it, (I know, I know, we're programmers, occupational hazard) it's pretty easy to add one month to any date. There's really no ambiguity. I'll do it right now and test my results with GNU date v8.22, to demonstrate.
One month after the 3rd of January 2017 CE was February 3rd.
linux> date -I --date "03-jan-2017 +1 month" 2017-02-03
One month after the 30th of January 2017 CE was March 2nd.
linux> date -I --date "30-jan-2017 +1 month" 2017-03-02
One month after the 30th of January 2000 CE was March 1st.
linux> date -I --date "30-jan-2000 +1 month" 2000-03-01
Simple. You just increment the month by one, and if the result has a day number higher than the number of days in that month, push the overflow into the next month. You win.
Admin
Forum software removed the newlines between my "date" commands and the answers returned, grrrr.
They were cut and pasted directly from an SSH session to a linux host.
Admin
Last of this month? Easy! "Date(now.year, now.month+1, 0)", normalizing over- and underflows is the library's problem.
Admin
No. It's like acceleration vs speed. Speed changes constantly = with a constant rate of change= with a constant acceleration. Still, I think it's not true for languages, so even if using constantly is possible, continously is still a better word.
Addendum 2018-02-16 04:14: Damn, I should read all the comments before posting, this has already been said.
Admin
Adding one month twelve times in a row does not always yield the same result as adding a year (i.e. twelve months).
Admin
You've defined a clear and unambiguous process. Why is that 'adding a month', though? It isn't, it's just one example of what that unclearly defined concept might mean.
In English, 'a month later' does not have an exact definition: its meaning varies based on context.
Admin
I'm sure Shakespeare appreciates your assessment of him. :)
Admin
TDWTF, you are TRWTF. You take the time to come back and mark featured comments, yet you let all this noisy spam stay. You should be ashamed of yourselves.
Admin
TRWTF is that Date.Time.Now is actually a property, so no parens
https://msdn.microsoft.com/en-us/library/system.datetime.now%28v=vs.110%29.aspx