• 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: Alex Zavatone <email@hidden>
  • Date: Fri, 21 Aug 2015 21:24:54 -0400
  • Sun-java-system-smtp-warning: Lines longer than SMTP allows found and wrapped.

I think anyone who is interested in using these date things will want to read the spec on date formats.

What you care about are the Date and Time Formatting

http://www.w3.org/TR/NOTE-datetime

https://en.wikipedia.org/wiki/ISO_8601

http://www.cs.tut.fi/~jkorpela/iso8601.html

https://www.ietf.org/rfc/rfc3339.txt

The standard is ISO 8601

The RFC is 3339

I've got some iOS Objective-C code for converting back and forth from an NSString to an NSDate that we've used on iOS to be all fat and happy with date strings received from an XML web service.

If anyone's interested, I can post if needed.



On Aug 21, 2015, at 5:54 PM, Stockly, Ed wrote:

> I have a confession to make.
>
> After testing AppleScriptObjC stuff, I never looked at it again. It seemed
> pretty cool, but beyond the scope of what I had time and need for.
>
> However, if I could get data detectors back, even if it was just for
> dates, that would be worth it.
>
> This dead horse you've flogged has convinced me to take the leap.
>
> Where do I start?
>
>
> Ed Stockly
> LA Times
>
>
>>
>> On Aug 20, 2015, at 11:13 AM, Stockly, Ed <email@hidden> wrote:
>>
>>
>> I used to be able to do this:
>>
>> Date "September 4"
>> Date "Fri., September 4"
>> Date "Fri. Sept. 4"
>> Date "Fri Sep 4"
>>
>> Date "Sep. 4"
>>
>> Date "Sept. 4"
>>
>> Date "9/4"
>>
>> Date "9/4/15"
>>
>> Date "09/04/2015"
>>
>> Date "9/4/2015"
>>
>>
>>
>>
>>
>>
>> At the risk of flogging a dead horse, I should point out that there is an
>> alternative API for *guessing* dates from strings. It's data detectors, a
>> technology resurrected from OSes of old, and it's what  used when, for
>> example, you hover over a date in
>> an email or document. It actually searches through a string for
>> potential dates, rather than treating the whole string as a single date.
>> It does a sort of enhanced regular-expression search based on your locale.
>>
>> So as an exercise, let's throw a variation of the above at it (and I've
>> set my date format to US for this):
>>
>> use framework "Foundation"
>> use script "BridgePlus"
>> on getDatesIn:aString
>> setanNSString to current application'sNSString's stringWithString:aString
>> set {theDetector,
>> theError} to current application'sNSDataDetector's
>> dataDetectorWithTypes:(current application'sNSTextCheckingTypeDate)
>> |error|:(reference)
>> settheMatches to
>> theDetector's matchesInString:anNSStringoptions:0
>> range:{0,
>> anNSString's |length|()}
>> settheDates to current application'sNSMutableArray's array()
>> repeatwith i from 1
>> to theMatches's
>> |count|()
>> setthisMatch to (theMatches'sobjectAtIndex:(i - 1))
>> (theDates'saddObject:(thisMatch's|date|()))
>> end
>> repeat
>> returntheDates
>> 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"
>> set theDatesto ASifyfrom (mygetDatesIn:theString)
>> -->{
>> date "Friday, September 4, 2015 at 12:00:00 PM",
>> date "Tuesday, September 1, 2015 at 12:00:00 PM",
>> date "Wednesday, September 2, 2015 at 12:00:00 PM",
>> date "Thursday, September 3, 2015 at 12:00:00 PM",
>> date "Friday, September 4, 2015 at 12:00:00 PM",
>> date "Wednesday, September 9, 2015 at 12:00:00 PM",
>> date "Monday, September 7, 2015 at 12:00:00 PM",
>> date "Sunday, September 6, 2015 at 12:00:00 PM",
>> date "Saturday, September 5, 2015 at 12:00:00 PM"
>> }
>>
>>
>>
>> As you can see, it picked up all but the m/d form -- because it's parsing
>> the complete string, it presumably errs on the side of caution given that
>> #/# might be a fraction.
>>
>> Now that might well be good enough for your use: you could prompt only if
>> it failed, or do an initial count of slashes. It depends on what's
>> acceptable to you.
>>
>> But if you run it with the string that started this thread:
>>
>> set theDates
>> to ASify
>> from (my getDatesIn:"10:11")
>> -->{
>> date "Friday, August 21, 2015 at 10:11:00 PM"
>> }
>>
>>
>>
>> You will see that, for some unknown reason, it guessed wrong. That's
>> probably worth logging as a bug, but the point is that unless the format
>> of the string and the expected format of the string match, it's just
>> guesswork. Educated guesswork, for sure --
>> but as you can see, not infallible.
>>
>> (Oh, and data detectors are very neat, and aren't limited to dates...)
>>
>> --
>> Shane Stanley <email@hidden>
>> <www.macosxautomation.com/applescript/apps/
>> <http://www.macosxautomation.com/applescript/apps/>>
>>
>
>
> _______________________________________________
> 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


 _______________________________________________
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>)

  • Prev by Date: Re: date syntax not working on 10.10.5?
  • Next by Date: Re: date syntax not working on 10.10.5?
  • 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