On 19 Aug 2015, at 10:36 am, Michael Grant <email@hidden> wrote:
I don't want to start an argument or anything, but as far as I'm aware AppleScript has done a perfectly adequate job of guessing dates and times from strings for many years.
First, it's not really AppleScript that's been doing the guessing -- it's merely been passing the job along. And second, for many of us it hasn't been "perfectly adequate". For example, where I am the standard short date format is dd/MM/yy, but yours is probably MM/dd/yy. I often have people send scripts to me that fail because of assumptions about date order. Nearly every time someone posts a script here that uses a string to make a date, I have to edit it before I can try it out. That's far from my idea of adequate.
Why "fix" what ain't broken?
Because it was actually broken. The change made in 10.6 that I referred to was made for that very reason. And the advice given is also there for good reason.
Aren't computers supposed to be getting better at heuristics, not worse?
They are, but the people who program them are also getting less myopic. And once you start looking at the bigger picture of how dates are formatted, let alone the fact that different calendars can be used, you realise that a scheme that once looked good to a bunch of geeks in one small geographic area doesn't fare so well in the big world.
So heuristics are being refined in things like data detectors, where for example a date might be highlighted in an email or other document. But it's still just a guess, and it's based on assumptions about language, calendar, and geography.
Look at any Web page, database or other application that wants you to enter a date. There'll be a calendar widget or menus -- anything but a text field asking you to type in a full date string.
(Also, as I pointed out, the string I was trying to use *does* match one of the formats I've got set in the preferences.)
You have no AM/PM string showing and a 24-hour clock?
And lets say you do match your preferences, and it works. Then one day, for whatever reason, you decide to change your settings, or perhaps run your scripts on someone else's computer. Are you happy that they might all fail?
A lot of people made the same argument about Unicode when it was introduced -- that it was supposedly fixing something that wasn't broken. Turned out it wasn't such a waste of time after all.
Having said that, of course you should be able to make a date from a string. But you need to be able to control the format that will be used for the parsing, which standard AS doesn't let you do, or you should read the format in use (again, difficult to do in AS) and make sure the string you're parsing matches. FWIW, the former is a little easier in 10.11.
|