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: Yvan KOENIG <email@hidden>
- Date: Sat, 22 Aug 2015 18:27:13 +0200
> Le 2015/08/22 à 18:20, Stockly, Ed <email@hidden> a écrit :
>
> 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
>
Hello Ed
I have no time to search but the script starts to play the fool when it treated the source value 9/8
As 9/8 is not valid, it append the date corresponding to 9/7/15 then it continue too work this way.
I assume that there is an oddity in the script itself, not in the detector.
Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) samedi 22 août 2015 18:27:07
_______________________________________________
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