I am designing an AppleScript which contains a hard-coded date to which the script refers multiple times throughout the duration of the execution.
An example is as follows:
property someDate : date "Monday, 1 January 2018 at 01:00:00 PM"
As one can see, the format of the timestamp is appropriate for my region and country. Another example would be: Saturday, April 15, 2006 4:29:04 PM
or 12/25/04
– which is the format for other regions such as the US – mm/dd/yy
.
The following questions arise
- If my AppleScript will be run in other regions/countries
(those with different timestamp formats eg.mm/dd/yy
instead of my
dd/mm/yy
), how does AppleScript behave with the above declaration? - How should I ensure that AppleScript will correctly convert the timestamp from my format into the respective format used by the end user's device?
The proper conversion becomes critical if the format of the date changes to the previously mentioned dd/mm/yy
and is then used in a mm/dd/yy
environment (region or country). In that case, the order may not be apparent.
Example Case
property someDate : date "02/01/18"
as dd/mm/yy
would be hard-coded with the intention of representing 02 January 2018, but when used in a different region (those using mm/dd/yy
); naturally, this will become 01 February 2018. See the issue?
As my research into this leads nowhere fast (and should be specific to AppleScript), I hope somebody who has implemented similar code could assist me in clarifying the two points above. Thank you.
Best Answer
This works for me using the latest version of Sierra
In this script, I set a predetermined date value as a variable. With my region set up to United States, in system preferences, I ran the script and logged the results. The first three lines of the results in the following image, were the values returned with my system set to United States region. Next I went back to system preferences and switched my region to Hungary and ran the script again. The last three lines of the results in the image, reflect the date and time values as if I was on a computer in Europe (Hungary)