• 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: My script won't be running stably
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: My script won't be running stably


  • Subject: Re: My script won't be running stably
  • From: Yvan KOENIG <email@hidden>
  • Date: Thu, 23 Mar 2017 15:07:37 +0100

Le 23 mars 2017 à 13:30, ILJA SHEBALIN <email@hidden> a écrit :

Hi, Yvan

Thanks for your input. Could you please elaborate on what does addition of 100 do?


Sincerely Yours,
Ilya Shebalin
E-mail: email@hidden,
           email@hidden 
Skype: llja.arbenin



23.03.2017, в 14:17, Yvan KOENIG написал(а):

It would be fine to replace :

set locale_Date to date requested_date
set short_date to short date string of result
set time_string to time string of locale_Date
set Unix_day to text 1 thru 2 of short_date
set Unix_month to text 4 thru 5 of short_date
set Unix_year to text 7 thru 8 of short_date


by


set locale_Date to date requested_date
set timeSring to time string of locale_Date
set Unix_day to text -2 thru -1 of ((100 + (day of locale_Date)) as string)
set Unix_month to text -2 thru -1 of ((100 + (month of locale_Date)) as string)
set Unix_year to text -2 thru -1 of (year of locale_Date as string)

This way your code will not be dependent of the local settings.


Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) jeudi 23 mars 2017 13:17:15


When AppleScript returns the day value, it may be a one digit one.
To pad it with a leading zero, we may use
text -2 thru -1 of ("00"&theDay)
But, using
text -2 thru -1 of ((100 + theDay) as text) is faster.
100+theDay --> 106
text -2 thru -1 of (106 as text) --> "06"

In real life I don't use the intermediate variables and use a more correct scheme to adjust the time.

# ISO 8601 prescribes, as a minimum, a four-digit year [YYYY] to avoid the year 2000 problem.

set requested_date to (current date) as string
log "requested_date : " & requested_date
(*requested_date : jeudi 23 mars 2017 à 14:57:30*)
tell ((date requested_date) - 0.5 * minutes) to set Unix_long_date to (its year as text) & "/" & text -2 thru -1 of (((its month) + 100) as text) & "/" & text -2 thru -1 of (((its day) + 100) as text) & space & its time string
log "Unix_long_date : " & Unix_long_date
(*Unix_long_date : 2017/03/23 14:57:00*)


# Now assume that requested_date is "12/12/12 00:00:10"

set requested_date to "12/12/12 00:00:10"
tell ((date requested_date) - 0.5 * minutes) to set Unix_long_date to (its year as text) & "/" & text -2 thru -1 of (((its month) + 100) as text) & "/" & text -2 thru -1 of (((its day) + 100) as text) & space & its time string
log "Unix_long_date : " & Unix_long_date
(*Unix_long_date : 2012/12/11 23:59:40*)


--with your code:
set locale_Date to date requested_date
set short_date to short date string of result
log "short_date here : " & short_date & ". Yes, 4 digits for the year" 
(*short_date here : 12/12/2012. Yes, 4 digits for the year*)
set time_string to time string of locale_Date
log "time_string : " & time_string 
(*time_string : 00:00:10*)
set Unix_day to text 1 thru 2 of short_date
set Unix_month to text 4 thru 5 of short_date
set Unix_year to text 7 thru 8 of short_date
log "Unix_year : " & Unix_year & ", which is wrong. It must be 12" 
(*Unix_year : 20, which is wrong. It must be 12*)
# I moved the year component to match IEEE components ordering
set Unix_short_Date to Unix_year & "/" & Unix_month & "/" & Unix_day
set localeDateAdjusted to locale_Date - 0.5 * minutes
set timeStringAdjusted to time string of localeDateAdjusted
log "timeStringAdjusted : " & timeStringAdjusted 
(*timeStringAdjusted : 23:59:40*)
set Unix_long_date to Unix_short_Date & space & (timeStringAdjusted as text)
--> "20/12/12 23:59:40"
# Yes, you code returns the date with an offset of one day.


Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) jeudi 23 mars 2017 15:03:27


 _______________________________________________
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: 
 >My script won't be running stably (From: ILJA SHEBALIN <email@hidden>)
 >Re: My script won't be running stably (From: Yvan KOENIG <email@hidden>)
 >Re: My script won't be running stably (From: Yvan KOENIG <email@hidden>)

  • Prev by Date: Re: Thoughts on Workflow acquisition?
  • Next by Date: Lists to XML ?
  • Previous by thread: Re: My script won't be running stably
  • Next by thread: Re: My script won't be running stably
  • Index(es):
    • Date
    • Thread