• 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: Can't Coerce String to Date?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't Coerce String to Date?


  • Subject: Re: Can't Coerce String to Date?
  • From: Yvan KOENIG <email@hidden>
  • Date: Sat, 14 Mar 2015 12:50:27 +0100


Le 14/03/2015 à 12:12, Thomas Fischer <email@hidden> a écrit :

Hello Yvan,

log "Now surprising behavior. If somebody may explain it, I'm interested."
try
set aString to "12 31/1943"
date aString
log "???? " & result (*???? vendredi 13 mars 2015 12:31:00*)
on error
log "The string doesn't match the current format : " & date string of (current date)
end try
try
set aString to "12 31 1943"
date aString
log "???? " & result (*???? vendredi 13 mars 2015 12:31:00*)
on error
log "The string doesn't match the current format : " & date string of (current date)
end try

On the system used in French, lhe events log is :

(*date vendredi 31 décembre 1943 00:00:00*)
(*date jeudi 31 décembre 2043 00:00:00*)
tell current application
current date
(*The string doesn't match the current format : vendredi 13 mars 2015*)
current date
(*The string doesn't match the current format : vendredi 13 mars 2015*)
(*Now surprising behavior. If somebody may explain it, I'm interested.*)
(*???? vendredi 13 mars 2015 12:31:00*)
(*???? vendredi 13 mars 2015 12:31:00*)
end tell

It will be different on system running in English.

this actually seems to be a compilation issue.
If aString is not a date, then the current date is taken (bug or feature?).

It's not what I get. To get a more explicit report I edited a bit the code.
Each attempt is now coded as:
try
set aString to "12 31 1943"
date aString
log "???? was : " & aString & " > " & result (*???? vendredi 13 mars 2015 12:31:00*)
on error
log "The string " & aString & " doesn't match the current format : " & date string of (current date)
end try

The Events log is 
(*???? was : 31 12 1943 > vendredi 31 décembre 1943 00:00:00*)
(*???? was : 31/12-43 > jeudi 31 décembre 2043 00:00:00*)
tell current application
current date
(*The string 12/31/1943 doesn't match the current format : samedi 14 mars 2015*)
current date
(*The string 12/31-43 doesn't match the current format : samedi 14 mars 2015*)
(*Now surprising behavior. If somebody may explain it, I'm interested.*)
(*???? was : 12 31/1943 > samedi 14 mars 2015 12:31:00*)
(*???? was : 12 31 1943 > samedi 14 mars 2015 12:31:00*)
(*???? was : 12 31 1943 > samedi 14 mars 2015 12:31:00*)
current date
(*The string 25 34 561943 doesn't match the current format : samedi 14 mars 2015*)
end tell

As you may see, "12/31/1943" and "12/31-43" are correctly treated as invalid dates.
What is puzzling is that "12 31/1943" and  "12 31 1943" are not treated the same way.
I don't see any logic behind these different behaviors.


Other entries, e.g.
date "25 34 561943" (!)
give an error message on my machine if I try to compile.

Yvan KOENIG (VALLAURIS, France) samedi 14 mars 2015 12:50:22


 _______________________________________________
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

  • Follow-Ups:
    • Re: Can't Coerce String to Date?
      • From: Shane Stanley <email@hidden>
References: 
 >Can't Coerce String to Date? (From: Alex Hall <email@hidden>)
 >Re: Can't Coerce String to Date? (From: Yvan KOENIG <email@hidden>)
 >Re: Can't Coerce String to Date? (From: Alex Hall <email@hidden>)
 >Re: Can't Coerce String to Date? (From: Yvan KOENIG <email@hidden>)
 >Re: Can't Coerce String to Date? (From: Thomas Fischer <email@hidden>)

  • Prev by Date: Re: Can't Coerce String to Date?
  • Next by Date: Re: Can't Coerce String to Date?
  • Previous by thread: Re: Can't Coerce String to Date?
  • Next by thread: Re: Can't Coerce String to Date?
  • Index(es):
    • Date
    • Thread