• 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: Coerce date saved as text back to Applescript's date format?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coerce date saved as text back to Applescript's date format?


  • Subject: Re: Coerce date saved as text back to Applescript's date format?
  • From: has <email@hidden>
  • Date: Mon, 20 Dec 2004 21:44:56 +0000

jj wrote:

One more thing: the string must be formatted according to the International
preference pane, or it will error.

For system-independent date string parsing, see AppleMods' Date library <http://applemods.sourceforge.net/mods/Data/Date.php> [1]. It currently supports about a dozen (mostly European) languages, and adding more is straightforward. Example:


set parserObj to _Date's makeParserForLanguage("dddd dd mmmm yyyy, hh:MM:SS tt (z)", "French")
set {theDate, GMTOffset} to parserObj's parseText("Mardi 30 mai 2000, 03:30:00 am (-0200)")
--> {date "Tuesday, May 30, 2000 3:30:00 am", -7200}



Note that the Date library's datestring parser isn't as flexible or forgiving as the one used by AS, which can be an advantage and/or a disadvantage depending on circumstances. For example, you can't specify a flexible regex-like pattern like "dddd,? *dd" to skip an optional comment and any number of spaces between a weekday and a day. If you need this kind of flexibility, you'll need to preprocess the string with a regex to tidy it up before parsing it. OTOH, it will reliably parse a date like "1/2/2005" according to your chosen format, whereas AppleScript can interpret this string as February 1st, January 2nd, or break altogether depending on an individual machine's system settings.


HTH

has

[1] If you've not used AppleMods' libraries before, you'll need to download and install AppleMods' Loader system first. Go to <http://applemods.sourceforge.net/getstarted.html> to get started. Install Loader and add the Date library to the ASLibraries folder, then use the LoaderWizard applet to generate the required library-loading code to paste at the top of your script.
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: Stop a script at a certain time?
  • Next by Date: help with a script
  • Previous by thread: Re: Coerce date saved as text back to Applescript's date format?
  • Next by thread: getting across network to older OS
  • Index(es):
    • Date
    • Thread