• 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: Sun, 23 Aug 2015 16:36:25 +0200


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



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
December 11
11 December
Décembre 11
11 Décembre
Diciembre 11
11 Diciembre
Sep. 4
Sept. 9
9/8
9/7/15
9/7/45
09/06/2015
9/5/2015
10:11
13:11
10:11 am
13:11 am
13:11 pm
13:11 PM"
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


Hello Ed.
As you may see, I added some strings.
Here is what I got on my French system using YYYY/MM/DD 24 hours

"--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
--December 11 --> vendredi 11 décembre 2015 12:00:00
--11 December --> vendredi 11 décembre 2015 12:00:00
--Décembre 11 --> Error --> missing value ne comprend pas le message « date ».
--11 Décembre --> vendredi 11 décembre 2015 12:00:00
--Diciembre 11 --> Error --> missing value ne comprend pas le message « date ».
--11 Diciembre --> vendredi 11 décembre 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 # it deciphers YYYY/MM/DD
--9/7/45 --> jeudi 7 septembre 2045 12:00:00 # As the 3rd number is not a dayNum, it treats it as MM/DD/YYYY
--09/06/2015 --> dimanche 6 septembre 2015 12:00:00
--9/5/2015 --> samedi 5 septembre 2015 12:00:00
--10:11 --> dimanche 23 août 2015 22:11:00 # Curious, here date "10:11" is date "dimanche 23 août 2015 10:11:00"
--13:11 --> dimanche 23 août 2015 13:11:00
--10:11 am --> dimanche 23 août 2015 10:11:00 # takes care of the string am
--13:11 am --> dimanche 23 août 2015 13:11:00
--13:11 pm --> dimanche 23 août 2015 13:11:00
--10:11 pm --> dimanche 23 août 2015 22:11:00" # takes care of the string pm

As you see, it seems that when a month name is given using a non-English wording, it's correctly deciphered only if it's on the correct side of the day number.


Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) dimanche 23 août 2015 16:36:20


 _______________________________________________
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

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: Looking for someone with El Capitan to test AppleScript
  • Next by Date: Re: 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