• Quite (unregistered) in reply to Mike Kellogg

    Languages are constantly evolving as ignorant people, pretending to be clever, constantly misuse it.

  • Fun fun fun! (unregistered)

    new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(1).AddDays(-1);

  • WTFGuy (unregistered) in reply to Ulli

    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.

  • anonymous (unregistered) in reply to P

    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.

  • Dave (unregistered) in reply to anonymous

    "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.

  • Free Bird (unregistered) in reply to Object delete.

    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.

  • marcodave (unregistered)

    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.

  • DCL (unregistered) in reply to Watson

    Like the way some people (mis)use the word fascist?

  • medievalist (unregistered) in reply to Dave

    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.

  • medievalist (unregistered) in reply to medievalist

    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.

  • löchlein deluxe (unregistered)

    Last of this month? Easy! "Date(now.year, now.month+1, 0)", normalizing over- and underflows is the library's problem.

  • Virginia Nutu (google) in reply to Anonymous

    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.

  • Free Bird (unregistered) in reply to medievalist

    Adding one month twelve times in a row does not always yield the same result as adding a year (i.e. twelve months).

  • Dave (unregistered) in reply to medievalist

    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.

  • Mike Kellogg (google) in reply to Quite

    Languages are constantly evolving as ignorant people, pretending to be clever, constantly misuse it.

    I'm sure Shakespeare appreciates your assessment of him. :)

  • Ulysses (unregistered)

    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.

  • Dot net WTF (unregistered) in reply to WTFGuy

    TRWTF is that Date.Time.Now is actually a property, so no parens


Leave a comment on “All the Rest Have Thirty One…”

Log In or post as a guest

Replying to comment #:

« Return to Article