Hi, daehl.
Thanks for writing up and posting your research. I hope you wonât mind a few observations:
1.
More accurately, date â1/1/2000â compiles on your machine (and on mine) to an AppleScript date object representing midnight on 1st January 2000. This compiled object is presented to your view in Script Editor as date âSaturday, January 1, 2000 12:00:00 AMâ, because thatâs the way dates are configured in your Date and Time preferences. On my machine, I see date âSaturday 1 January 2000 00:00:00â. But if I sent my compiled script to you, youâd see the date in your own format, not mine, when you looked at it in Script Editor. The point is that, once compiled, the date is usable on anyoneâs machine.
Here the date isnât realised until the scriptâs run (adding slightly to the running time). Itâs interpreted according to the preferences on the running machine, so the above works for you and me, but would error on a machine configured for yyyy/mm/dd short dates. Similarly, if youâd written date (â1/2/2000â as string), your machine would produce date âSunday, January 2, 2000 12:00:00 AMâ when it ran the script, mine would produce date âTuesday 1 February 2000 00:00:00â. Hard-coded date strings arenât transportable.
There is, of course, a problem when posting to a forum like this, since you can only post the source code, not the compiled script. However you write a date, itâs bound not to work for someone, unless they edit it for themselves. Before Leopard, it was possible to use this unofficial coercion:
"2000/1/1" as «class isot» as date
. but the â2000/1/1â has to be a string, not Unicode text, so it probably doesnât work with Leopard.
2.
The time of a date is returned as an integer anyway. No need for the coercion. The date would error on machines outside the USA, since thereâs no fourteenth month of the year.
3.
AppleScript has the predefined constants weeks, days, hours, and minutes, whose values are the number of seconds in those periods. (The names are in the plural so that you can use expressions like 2 * weeks for the number of seconds in a fortnight.) So you could write:
return ((date "1/1/1") - (date "1/1/0")) div days
--> Returns: 366 (days)
5.
The official range of dates that AppleScript will accept, irrespective of the editor used, is (in my format) date âWednesday 1 January 1000 00:00:00â to date âFriday 31 December 9999 23:59:59â. AppleScript can go beyond these limits internally to give itself headroom and floor-room in its date calculations.
9.
AppleScript (itâs not Script Editor) doesnât mind if years less than 1000 are entered, but it interprets them as shorthand for nearby four-digit years. When I first started AppleScripting in 1997, two digits were taken to mean years beginning with â19â and three digits as years beginning with â1â. Shortly after that, the interpretation depended on the system date at the time of the interpretation. (Iâm not sure if this was introduced in time for the end of the century or whether AppleScript could do this already.) Currently, both my Jaguar and Tiger machines interpret year numbers between â91â and â99â in date strings as years between 1991 and 1999, and any other two-figure year numbers as years between 2000 and 2090.
date ("1/1/91" as string)
--> date "Tuesday 1 January 1991 00:00:00"
date ("1/1/90" as string)
--> date "Sunday 1 January 2090 00:00:00"