• 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
Rép: date/Snow Leopard changed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rép: date/Snow Leopard changed


  • Subject: Rép: date/Snow Leopard changed
  • From: Yvan KOENIG <email@hidden>
  • Date: Wed, 2 Sep 2009 20:47:26 +0200


Oops I responded to has when thinking that I was responding here.


Le 2 sept. 2009 à 19:39:51, has a écrit :

Robert Poland wrote:

Going through my scripts in Snow Leopard I ran into one that is being
stubborn;

set WakeUpTime to "6:01"
set SleepTime to "21:01"
set nowTime to (current date)
set wakeTime to date (date string of nowTime & ":" & WakeUpTime) --
NOTE use of ":"
set bedTime to date (date string of nowTime & ":" & SleepTime) -- NOTE
use of ": "

As indicated in the 10.6 release notes, date specifiers have become much more strict about how date strings are formatted. (The flip-side is that their internationalisation support is greatly improved.)

In any case, you shouldn't need to use string mashing to obtain a date at a particular time. Haven't tried it in 10.6 yet, but here is the traditional way of doing it:

date "6:01" of (current date)

I was surprised but it works.
So it seems that I wrongly understood what is written in the RN-AppleScript:

Parsing of date strings now uses CFDateFormatterCreateDateFromString, which means that custom
date formats, Unicode-only locales such as Arabic, and non-Gregorian calendars are now all handled correctly.
However, it is also much more restrictive about deviating from the system date format. Previous versions
would accept anything that looked even vaguely like a date: the string could omit components, reorder
others, add or omit punctuation, and so on. In AppleScript 2.1, the string must exactly match one of the
system date formats (full, long, medium, or short; see System Preferences > International > Formats for
examples), including all punctuation and whitespace. The only difference allowed is to use either a two- or
four-digit year, regardless of what the format uses.
Some scripts used partial date specifiers as a way to get dates relative to the current date, such as date
"1/31" for January 31 of the current year, or date "15" to get the 15th of the current month. To do this
in AppleScript 2.1, get a base date and then set the desired components using the properties of the date
object. For example, to get January 31 of the current year:
set d to date "1/31/2000"
set year of d to year of (current date)
d --> date "Saturday, January 31, 2009 12:00:00 AM"
Alternatively, start with current date as the base. To get the 15th of the current month:
set d to current date
set day of d to 15
set time of d to 0
d --> date "Friday, May 15, 2009 12:00:00 AM"
This technique works with all versions of AppleScript, and can be used for scripts that must run on 10.6 and
10.5 and earlier.

So, I thought that date "6:01" of (current date) was wrong.

It's not. Good news.

Looking closer, I discovered that the ref to (current date) is not required:

date "06:01" 
gives the same result than
date "06:01" of (current date).

I wish to know Chris Nebel (or Chris Page) opinion about such a behavior.

Yvan KOENIG (VALLAURIS, France) mercredi 2 septembre 2009 20:28:44



 _______________________________________________
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: Rép: date/Snow Leopard changed
      • From: Christopher Nebel <email@hidden>
  • Prev by Date: Re: date/Snow Leopard changed
  • Next by Date: Re: date/Snow Leopard changed
  • Previous by thread: Re: Script to mail contents of safari web page.
  • Next by thread: Re: Rép: date/Snow Leopard changed
  • Index(es):
    • Date
    • Thread