• 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: Conversion of ISO Date String to AppleScript Date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conversion of ISO Date String to AppleScript Date


  • Subject: Re: Conversion of ISO Date String to AppleScript Date
  • From: Jim Underwood <email@hidden>
  • Date: Mon, 06 Mar 2017 02:15:12 +0000
  • Thread-topic: Conversion of ISO Date String to AppleScript Date

Shane et al,

So here's my simple, but more verbose than I'd like, error trapping for an ISO date/time string that includes time zone data (remember I allow only local time zone):

From W3C Spec of ISO 8601 the time zone data can be in these forms:
TZD  = time zone designator (Z or +hh:mm or -hh:mm)
Even though the spec indicates the TZD is to be used ONLY when time is included, I'm checking for it in anything AFTER the date.  So, my validation should trap:

"2017-03-05-05:00"

"2017-03-05Z"

"2017-03-05T13:01:02-05:00"

"2017-03-05T13:01:02+05:00"

"2017-03-05T13:01:02Z"




    if (length of pDateStr > 10) then

      set endISO to (text 11 thru -1 of pDateStr)

      if ((length of pDateStr) > 19 ¬

        or (offset of "Z" in endISO) > 0 ¬

        or (offset of "+" in endISO) > 0 ¬

        or (offset of "-" in endISO) > 0) then

        

        error "Time Zone codes NOT allowed" number 1001

      end if

    end if

    

  on error errMsg number errNum

    if errNum = 1001 then

      set errMsgAddl to return & errMsg

    else

      set errMsgAddl to ""

    end if

    error "[ERROR]" & return & "INVALID Date Format: " & pDateStr & errMsgAddl

  



If anyone can improve on my code, it will be welcomed.

One thing, I'm avoiding use of RegEx just because I don't want to require Satimage.osax, or use the more complicated ASObjC.  (but maybe there's a simple way . . .)

Best Regards,

Jim Underwood
aka JMichaelTX


From: <applescript-users-bounces+jmichael=email@hidden> on behalf of JMichael <email@hidden>
Date: Sun, Mar 5, 2017 at 5:05 PM
To: "ASUL (AppleScript)" <email@hidden>
Subject: Re: Conversion of ISO Date String to AppleScript Date



So if you get a string like "2016-01-05T13:01:15Z", rather than erroring, you're going to return a potentially erroneous date. Perhaps you should also test for a maximum length, at least.

That is an excellent point.  Thank you.
I will add additional data validation to check for any characters that indicate time zone.
 _______________________________________________
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: 
 >Re: Conversion of ISO Date String to AppleScript Date (From: Ed Stockly <email@hidden>)
 >Re: Conversion of ISO Date String to AppleScript Date (From: Ed Stockly <email@hidden>)
 >Re: Conversion of ISO Date String to AppleScript Date (From: Ed Stockly <email@hidden>)
 >Re: Conversion of ISO Date String to AppleScript Date (From: Ed Stockly <email@hidden>)
 >Re: Conversion of ISO Date String to AppleScript Date (From: Shane Stanley <email@hidden>)
 >Re: Conversion of ISO Date String to AppleScript Date (From: Jim Underwood <email@hidden>)
 >Re: Conversion of ISO Date String to AppleScript Date (From: Shane Stanley <email@hidden>)
 >Re: Conversion of ISO Date String to AppleScript Date (From: Jim Underwood <email@hidden>)

  • Prev by Date: Re: Conversion of ISO Date String to AppleScript Date
  • Next by Date: Re: Conversion of ISO Date String to AppleScript Date
  • Previous by thread: Re: Conversion of ISO Date String to AppleScript Date
  • Next by thread: Re: Conversion of ISO Date String to AppleScript Date
  • Index(es):
    • Date
    • Thread