So, we are always facing the same problem - but it can't be solved.
When a given string is ambiguous the return value is OK in some countries but wrong in others.
I’m thinking we could come up with a solution that figures out what the current local setting is at runtime and then handle appropriately.
The problem is not to ask the script to decipher according to its runtime settings, it's to ask it to decipher according to the sender ones.
If a french customer/provider send you a file containing the date 14/07/1789, it is 1789/07/14 in ISO 8601 format but on your machine, it will be deciphered as 1789/14/07 because I'm quite sure that you use the MM/DD/YYYY format when the sender typed a DD/MM/YYYY one. This is why now, use YYYY/MM/DD, at least when I write to non-french correspondants.
Happily, most of the time I knew which date format used by my correspondents. When an English one send me a text containing "07/14/1789", I don't try to use date "07/14/1789" which would return mercredi 7 janvier 1789 00:00:00. I use the handler swapDDMM and I know that an English user receiving a french date would have to use the handler swapDDMM.
"1/12/2015" if day of date result is 1 then set myFormat to "dd/MM" else set myFormat to "mm/DD" end if
set EnglishDate to "07/14/1789" if myFormat is "dd/MM" then set aDate to date (my swapDDMM(EnglishDate)) else set aDate to date EnglishDate end if log result (*date mardi 14 juillet 1789 00:00:00*)
set FrenchDate to "14/07/1789" if myFormat is "DD/mm" then set aDate to date FrenchDate else set aDate to date (my swapDDMM(FrenchDate)) end if log result (*date "dimanche 7 février 1790 00:00:00"*)
#=====
on swapDDMM(str) set {MD, DM, YYYY} to my decoupe(str, "/") return DM & "/" & MD & "/" & YYYY end swapDDMM
#=====
on decoupe(t, d) local oTIDs, l set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d} set l to text items of t set AppleScript's text item delimiters to oTIDs return l end decoupe
#=====
Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) dimanche 23 août 2015 12:06:55
|