Date: Thu, 20 Oct 2005 02:52:13 +0100
From: "Nigel Garvey" <email@hidden>
Subject: Re: Days and hours
To: "AppleScript Users" <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=ISO-8859-1
"Mark J. Reed" wrote on Wed, 19 Oct 2005 17:23:28 -0400:
I have one other question in this general topic area: given that (date "some
date string") honors your current system preferences,
Actually, while experimenting with the month-translation script I posted
earlier, I found that only preferences for non-Unicode language date
formats are so honoured. If your preferred date language is Welsh, Oromo,
Turkish, etc, AppleScript uses the last WorldScript-compatible language
to which the machine was set.
what's the easiest way
to initialize a date object in a way that *doesn't* honor them? Say I want
to pass around uncompiled code as text and have it work wherever my
correspondents happen to be regardless of their prefs. Is this the only way?
set myDate to current date
set year of myDate to 1968
set month of myDate to May
set day of myDate to 5
set time of myDate to (20 * 60 + 47) * 60
There's a potential problem with this method, in that unless all the
elements of the current date are compatible with the date you want to
create, you'll get errors. If the script's run on 29th February 2008, the
second line will error if the target's in a non-leap year. The third line
will error if an April date's set on the last day of March, etc. For
safety, you need to set either the month or the date twice -- the first
time, done before anything else, to a safe value such as January or 1.
It's possible to do the whole thing in one line:
tell (current date) to set {day, year, its month, day, time, myDate} to
{1, 1968, May, 5, 20 * hours + 47 * minutes, it}
NG