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 mydd/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.
property someDate : date "Monday, 1 January 2018 at 01:00:00 PM"
in Script Editor the ` at` gets dropped, but compiles. Alsocurrent date
returns the same format but without theat
. That said, setting it back to my normal setting it does not compile and returnsSyntax Error Invalid date and time date Monday, 1 January 2018 at 01:00:00 PM.
. I which you'd answer the question I previously asked, which was: Why are you setting aproperty
to a fixeddate
, what purpose does it serve in the script?set someDate to date "..."
would work too (thus not limiting myself to a property declaration). I hope that answers the last part. Another way could be toset someDate to the current date
set the month of someDate to 1
set the day of someDate to 2
set the year of someDate to 2018
. Hoping to not only write a concise timestamp but also learn the proper way of implementing a global solution.current date
in epoch time to a plist file and use that value to calculate against. I suppose it could be stored in a property upon first run. Either way you'd be able to calculate against it.property
but do it in epoch time and not human readable date like you're trying to do.