• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: date syntax not working on 10.10.5?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: date syntax not working on 10.10.5?


  • Subject: Re: date syntax not working on 10.10.5?
  • From: Yvan KOENIG <email@hidden>
  • Date: Sat, 22 Aug 2015 19:27:50 +0200


Le 2015/08/22 à 19:10, Stockly, Ed <email@hidden> a écrit :

But the conversion can also be done with a handler -- the code just becomes a bit longer:


Well that worked just fine, even with the time string from the OP.

It errors on the mm/dd, which is better than giving an incorrect result.

All the other date strings worked.


"--Sunny September 4 --> Friday, September 4, 2015 at 12:00:00 pm
--Fri., September 1 --> Tuesday, September 1, 2015 at 12:00:00 pm
--Fri. Sept. 2 --> Wednesday, September 2, 2015 at 12:00:00 pm
--Fri Sep 3 --> Thursday, September 3, 2015 at 12:00:00 pm
--Sep. 4 --> Friday, September 4, 2015 at 12:00:00 pm
--Sept. 9 --> Wednesday, September 9, 2015 at 12:00:00 pm
--9/8 --> Error --> missing value doesn’t understand the “date” message.
--9/7/15 --> Monday, September 7, 2015 at 12:00:00 pm
--09/06/2015 --> Sunday, September 6, 2015 at 12:00:00 pm
--9/5/2015 --> Saturday, September 5, 2015 at 12:00:00 pm
--10:11 --> Saturday, August 22, 2015 at 10:11:00 am
--13:11 --> Saturday, August 22, 2015 at 1:11:00 pm
--10:11 am --> Saturday, August 22, 2015 at 10:11:00 am
--13:11 am --> Saturday, August 22, 2015 at 1:11:00 pm"

Tinkering with some various date and time and location preferences seems to work for all but the mm/yy versions.

I wonder how well it works for our European friends.

Also, combining the two handlers into one seems to work.

Thanks, it looks like this solves a years-long issue.
------------

use framework "Foundation"
use scripting additions -- required for 'current date'
local thisDate
on getDatesIn:aString
-- convert string to Cocoa string
set anNSString to current application's NSString's stringWithString:aString
-- create data detector
set theDetector to current application's NSDataDetector's dataDetectorWithTypes:(current application's NSTextCheckingTypeDate) |error|:(missing value)
-- find first match in string; returns an NSTextCheckingResult object
set theMatch to theDetector's firstMatchInString:anNSString options:0 range:{0, anNSString's |length|()}
-- get the date property of the NSTextCheckingResult
set theDate to theMatch's |date|()
return theDate
end getDatesIn:

on makeASDateFrom:theNSDate
set theCalendar to current application's NSCalendar's currentCalendar()
set comps to theCalendar's componentsInTimeZone:(missing value) fromDate:theNSDate -- 'missing value' means current time zone
tell (current date) to set {theASDate, year, day, its month, day, time} to ¬
{it, comps's |year|(), 1, comps's |month|(), comps's |day|(), (comps's hour()) * hours + (comps's minute()) * minutes + (comps's |second|())}
return theASDate
end makeASDateFrom:

set dateStrings to "Sunny September 4
Fri., September 1
Fri. Sept. 2
Fri Sep 3
Sep. 4
Sept. 9
9/8
9/7/15
09/06/2015
9/5/2015
10:11
13:11
10:11 am
13:11 am"
set stringsAndDates to {}
repeat with thisDate in paragraphs of dateStrings
try
set thisDate to thisDate as text

set theDate to (my getDatesIn:thisDate)
set theASDate to (my makeASDateFrom:theDate)
set the end of stringsAndDates to "--" & thisDate & " --> " & theASDate as text
on error errMsg number errNum
set the end of stringsAndDates to "--" & thisDate & " --> " & "Error --> " & errMsg
end try
 end repeat

set AppleScript's text item delimiters to {return}
return stringsAndDates as text
 

I added an extraneous source : --13:11 pm

When I ran the script on my machine whose default format is now YYYY/MM/DD it returned :

"--Sunny September 4 --> vendredi 4 septembre 2015 12:00:00
--Fri., September 1 --> mardi 1 septembre 2015 12:00:00
--Fri. Sept. 2 --> mercredi 2 septembre 2015 12:00:00
--Fri Sep 3 --> jeudi 3 septembre 2015 12:00:00
--Sep. 4 --> vendredi 4 septembre 2015 12:00:00
--Sept. 9 --> mercredi 9 septembre 2015 12:00:00
--9/8 --> Error --> missing value ne comprend pas le message « date ».
--9/7/15 --> mercredi 15 juillet 2009 12:00:00
--09/06/2015 --> dimanche 6 septembre 2015 12:00:00
--9/5/2015 --> samedi 5 septembre 2015 12:00:00
--10:11 --> samedi 22 août 2015 22:11:00
--13:11 --> samedi 22 août 2015 13:11:00
--10:11 am --> samedi 22 août 2015 10:11:00
--13:11 am --> samedi 22 août 2015 13:11:00
--13:11 pm --> samedi 22 août 2015 13:11:00"

When the default format is DD/MM/YYYY it return:

Résultat :

"--Sunny September 4 --> vendredi 4 septembre 2015 12:00:00
--Fri., September 1 --> mardi 1 septembre 2015 12:00:00
--Fri. Sept. 2 --> mercredi 2 septembre 2015 12:00:00
--Fri Sep 3 --> jeudi 3 septembre 2015 12:00:00
--Sep. 4 --> vendredi 4 septembre 2015 12:00:00
--Sept. 9 --> mercredi 9 septembre 2015 12:00:00
--9/8 --> Error --> missing value ne comprend pas le message « date ».
--9/7/15 --> jeudi 9 juillet 2015 12:00:00
--09/06/2015 --> mardi 9 juin 2015 12:00:00
--9/5/2015 --> samedi 9 mai 2015 12:00:00
--10:11 --> samedi 22 août 2015 22:11:00
--13:11 --> samedi 22 août 2015 13:11:00
--10:11 am --> samedi 22 août 2015 10:11:00
--13:11 am --> samedi 22 août 2015 13:11:00
--13:11 pm --> samedi 22 août 2015 13:11:00"


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.


Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) samedi 22 août 2015 19:27:24





 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: date syntax not working on 10.10.5?
      • From: "Stockly, Ed" <email@hidden>
References: 
 >date syntax not working on 10.10.5? (From: Michael Grant <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Christopher Stone <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Michael Grant <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Michael Grant <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: "Stockly, Ed" <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Yvan KOENIG <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Michael Grant <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Michael Grant <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Michael Grant <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: "Stockly, Ed" <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: "Stockly, Ed" <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: "Stockly, Ed" <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: "Stockly, Ed" <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: "Stockly, Ed" <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Re: date syntax not working on 10.10.5?
  • Next by Date: Looking for someone with El Capitan to test AppleScript
  • Previous by thread: Re: date syntax not working on 10.10.5?
  • Next by thread: Re: date syntax not working on 10.10.5?
  • Index(es):
    • Date
    • Thread