Re: date syntax not working on 10.10.5?
Re: date syntax not working on 10.10.5?
- Subject: Re: date syntax not working on 10.10.5?
- From: "Stockly, Ed" <email@hidden>
- Date: Sat, 22 Aug 2015 16:20:41 +0000
- Thread-topic: date syntax not working on 10.10.5?
Here is the result from the script below:
--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--> Monday, September 7, 2015 at 12:00:00 pm
--9/7/15--> Sunday, September 6, 2015 at 12:00:00 pm
--09/06/2015--> Saturday, September 5, 2015 at 12:00:00 pm
--9/5/2015--> Saturday, August 22, 2015 at 10:11:00 am
--10:11--> Saturday, August 22, 2015 at 1:11:00 pm
--13:11--> Saturday, August 22, 2015 at 10:11:00 am
--10:11 am--> Saturday, August 22, 2015 at 1:11:00 pm
In some, the date provided is invalid, wrong weekday, but it returns a date based on the date info, which is the same as the previous behavior and just what we want.
The MM/DD issue is bad, since the results are totally incorrect. Not sure how to fix that.
The time issue makes no sense.
I wonder if it’s possible to track down where the errors are (bridgeScript; data detectors)
BTW, thanks for your sticking with this, guys. Since few of the dates come over in purely numerical formats, I could add a routine that asks the user to simply confirm that the script’s guess was correct, or detect the numerical format and require user input.
That would eliminate most of the errors.
Ed
--------------------------
use framework "Foundation"
use script "BridgePlus"
on getDatesIn:aString
set anNSString to current application's NSString's stringWithString:aString
set {theDetector, theError} to current application's NSDataDetector's dataDetectorWithTypes:(current application's NSTextCheckingTypeDate) |error|:(specifier)
set theMatches to theDetector's matchesInString:anNSString options:0 range:{0, anNSString's |length|()}
set theDates to current application's NSMutableArray's array()
repeat with i from 1 to theMatches's |count|()
set thisMatch to (theMatches's objectAtIndex:(i - 1))
(theDates's addObject:(thisMatch's |date|()))
end repeat
return theDates
end getDatesIn:
set theString 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 theDates to ASify from (my getDatesIn:theString)
set listOfStringsDates to {}
repeat with x from 1 to count of theDates
set the end of listOfStringsDates to "--" & paragraph x of theString & "--> " & item x of theDates as text
end repeat
set AppleScript's text item delimiters to {return}
return listOfStringsDates as text
_______________________________________________
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