Hacker News new | ask | show | jobs
by nickpsecurity 3809 days ago
Should be able to type or sanity check them like anything else. What specific issue are you worried about?
1 comments

2011-02-28 + 1m1d = 2011-03-29

2011-02-28 + 1d1m = 2011-04-01

(edit: stupid leap-year!)

February 2012 has got 29 days.
This is why everyone hates working with time and date functions. :-)
Oh it's been a pleasant trip down memory lane for me let me tell ya. Probably why I haven't done that sort of thing in a long time haha.
Why does that happen? I'd think they were equivalent. I don't do time-series or anything to be clear. I would just expect the a + b = b + a principle to apply for the m/d value.
because 1m = [28d,29d,30d,31d] depending on which month you are in. By adding 1d, pre or post, it can alter the definition of 1m.
Sure (assuming that's how a "month" is defined in this context -- I haven't actually read the whole article, so I'm not sure); but why do you find the Java syntax less confusing? They look pretty equivalent, except for one is shorter than the other.
By splitting the addition up into two discrete calls, the ordering is made much more explicit, there's no room for ambiguity.

In C#, the largest part of a TimeSpan is a day, you can't have a TimeSpan of "one month and one day", because adding that to a DateTime would add a different amount of absolute time depending on the DateTime. You can have a TimeSpan of "32 days", and adding that to any DateTime yields a consistent result.

1h4m is 1 hr then 4 min. Order is explicit unless language rules obfuscate it.
Ih ok. Sounds like we can keep first style just make order of operations clear and with rules to catch this. Second syntax woukd appear to require same checks. Again, equivalent intent and problems with more verbosity in 2.
2011-02-28 + 1m1d = (2011-02-28 + 1m) + 1d = 2011-03-28 + 1d = 2011-03-29

2011-02-28 + 1d1m = (2011-02-28 + 1d) + 1m = 2011-03-01 + 1m = 2011-04-01

Also, you have these overflow rules:

2011-03-31 + 1m = 2011-04-30

2011-04-30 - 1m = 2011-03-30