Live data from Hacker News

Code that breaks 2 or 3 times every month

ngzhian.github.io

1–10 of 20 posts

Re: Code that breaks 2 or 3 times every month

#3
post #2

umm... it's because the date 31st isn't in those months... Simply, they're switching to February 2006, because you did not specify a day.

Sure enough. But is it a sane thing to do for a "convert readable date to date object" function to silently amend the current day-of-month to a otherwise underdpecified date?

I really don't see the use case for that anywhere.

Re: Code that breaks 2 or 3 times every month

#4
post #3
post #2

umm... it's because the date 31st isn't in those months... Simply, they're switching to February 2006, because you did not specify a day.

Sure enough. But is it a sane thing to do for a "convert readable date to date object" function to silently amend the current day-of-month to a otherwise underdpecified date? I really don't see the use case for that anywhere.

Moreover, often this is not what you want. Generally you'll want either "the last past day that had that number" (logging of activity), or "the first future day that has that number" (appointment planning). But having a date that can be randomly in the past or the future sounds a bit strange.

Re: Code that breaks 2 or 3 times every month

#5
Once I recognized a certain test pass on all days except on Mondays.

The test created models for a few days and tested for a sum of the current week. The dates where all relative (today, yesterday, etc.), so when the test run on a Monday some records where for the last week and that's why the sum wasn't the same.

But I guess your problem is harder to debug.

Re: Code that breaks 2 or 3 times every month

#6
post #3
post #2

umm... it's because the date 31st isn't in those months... Simply, they're switching to February 2006, because you did not specify a day.

Sure enough. But is it a sane thing to do for a "convert readable date to date object" function to silently amend the current day-of-month to a otherwise underdpecified date? I really don't see the use case for that anywhere.

I would expect to use the first day of a month as a default, just like when time is not specified it should use 00:00 as default. Taking the current time/day as a default sounds off.

Probably hard to fix backwards compatible though...

Re: Code that breaks 2 or 3 times every month

#9
I made an app that generated reports. The queries ran quickly when I tested it directly on the database but when I ran my app it would hang on a particular query. Sometimes.

I started making some small seemingly insignificant changes to my code and suddenly my app generated all the reports quickly. All was well until the next month when I had to generate the same reports and my app failed on the same query. I solved it by reverting the small insignificant change I made the previous month. WTF.

I looked into it and there's a wealth of information on the topic[0]. Apparently, how my code passed the query to the database differed to how I tested my query directly on the database which cause the database to compile the query differently and use different execution plans.

My most recent fix was to add another index which the database suggested. Let's hope it works next month.

[0] http://www.sommarskog.se/query-plan-mysteries.html

Re: Code that breaks 2 or 3 times every month

#10
post #6
post #3

Earlier quoted context omitted.

Sure enough. But is it a sane thing to do for a "convert readable date to date object" function to silently amend the current day-of-month to a otherwise underdpecified date? I really don't see the use case for that anywhere.

I would expect to use the first day of a month as a default, just like when time is not specified it should use 00:00 as default. Taking the current time/day as a default sounds off. Probably hard to fix backwards compatible though...

Agreed; I expect date parsers to give me earliest-available value for a field if it's not specified, with the exception being the current year rather than 0 AD or whatever.

Javascript:

    new Date("Feb 2006")
    > Wed Feb 01 2006 00:00:00 GMT-0800 (Pacific Standard Time)
Ruby:

    require 'time'
    Time.parse "Feb 2006"
    => 2006-02-01 00:00:00 -0700
Post reply on HN