• 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: Shane Stanley <email@hidden>
  • Date: Sun, 23 Aug 2015 17:15:12 +1000

On 23 Aug 2015, at 11:06 am, Shane Stanley <email@hidden> wrote:

So you'd search for a pattern of x/y and no other slashes, and replace it with x/y/2015.

Something like:

use scripting additions
use framework "Foundation"

set anNSString to current application's NSString's stringWithString:"2/3" -- some date string
-- look for 1-2 digits, slash, followed by 1-2 digits
set theRegex to current application's NSRegularExpression's regularExpressionWithPattern:"(\\d{1,2})/(?=\\d{1,2})" options:0 |error|:(missing value)
set theMatches to theRegex's matchesInString:anNSString options:0 range:{0, anNSString's |length|()}
if (theMatches's |count|()) = 1 then -- must be M/d without year
-- get range of the month
set monthRange to (theMatches's objectAtIndex:0)'s rangeAtIndex:1
-- get month number
set theMonth to (anNSString's substringWithRange:monthRange) as text as integer
-- get year and month of now
set now to current date
set {thisMonth, theYear} to {month of now as integer, year of now}
-- bump year if month would otherwise have passed
if theMonth < thisMonth then set theYear to theYear + 1
-- replace MM/dd with MM/dd/year
set anNSString to anNSString's stringByReplacingOccurrencesOfString:"\\d{1,2}/\\d{1,2}" withString:("$0/" & theYear) options:(current application's NSRegularExpressionSearch) range:{0, anNSString's |length|()}
end if


-- 
Shane Stanley <email@hidden>
<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

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: Christopher Stone <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: "Stockly, Ed" <email@hidden>)
 >Re: date syntax not working on 10.10.5? (From: Shane Stanley <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