But why should you support a wrong notated date in the first place? If someone types “31/2/99” shouldn’t he be given an error? Why should you try to fix that because he probably meant “31/1/99” or “31/3/99” and certainly didn’t meant “3/3/99”. Never trying to fix wrong inputted data into something unexpected, right?
Didn’t miss it, the given parameter was a static string
Well, this particular work around a grammatical and syntactical ambiguity works for me. I must say that I’m forgiving, because after all, AppleScript is a damn cute language. I love the lists, and the fact that they are made just so, that you can easily translate code from other languages back and forth, which makes it very easy to learn things in. -Also to remove recursion. :lol:
That’s not MacUsrII’s issue, though. Sticking to m/d/y order, suppose the string is “31/1/2010”. That’s a valid date. But if you run your script today, current date will produce a date with a month containing only 30 days. So when you set its day to 31, it will roll over to 1. To be safe, you need to set the day to a value valid for every month before you change the month --then set the correct day.
That is correct, and the month will be incremented as well, so it rolls over to the first of next month for instance. This is really Nigel Garveys world. It is a feature as much as a bug in other situation, where this is a great advantage during date calulations.
Setting the day to 1 covers 2 cases.
The first case is when todays daynumber of a month, is greater than the month you are wanting to end up with, and you start off by setting the month
The second case is when you set a day number first, and that daynumber is greater than the possible daynumber of the current month.
Either way, it is a risk of overflow of days into next month. And if you are to calculate the probability of this happening, then you must calculate with a probability of 50% since it either happens, or don’t, and then the likelihood will be far greater than you’d intuitively expect.
And yet when I look at DJ’s code again, it’s not a problem. That’s because the maximum roll-over is three days, but he’s subtracting five days at the end – effectively making it a non-issue.
I see, I have updated the code to set the day first and then the month. Seems that non-English date notations (Dutch=dd/mm/yy) never have to worry about this and therefore I didn’t really saw the problem.