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

Re: Rép: date/Snow Leopard changed


  • Subject: Re: Rép: date/Snow Leopard changed
  • From: Christopher Nebel <email@hidden>
  • Date: Wed, 2 Sep 2009 14:31:05 -0700

On Sep 2, 2009, at 11:47 AM, Yvan KOENIG wrote:

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.

Right, that's an old feature called relative dates -- you can specify a time "of" another date object.  The time string still has to match the system formatting, of course.  A "date" string may contain a date only, time only, or a date and a time.

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.

"Date" strings with only a date or only a time follow the same rules as before: with no time, the time is presumed to be midnight; with no date, the date is presumed to be the current date.  Therefore, 'date "6:01"' and 'date "6:01" of (current date)' are equivalent.

The reason 'date "6:01"' worked for Yvan and not Michelle is that she's using the US locale, which uses a 12-hour clock, and therefore the "AM" or "PM" is required.  Yvan, however, is using French, which uses a 24-hour clock, so the AM/PM is optional.

Date input is actually somewhat more lenient than the release notes say it is -- there were some changes that made it in shortly before release.  For example, the official US format uses a comma between the month-day and the year (e.g., "Sep 2, 2009"), but it will still accept a date string without a comma.  In general, though, you should try to match the system format as closely as possible.

One other thing to watch out for is that CFDateFormatter uses different heuristics for interpreting two-digit years, so AppleScript now uses a cut-off of 1950 (that is, "50" is 1950, "49" is 2049), where the older API used a cut-off of 1991.


--Chris Nebel
AppleScript Engineering

 _______________________________________________
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: Tim Mansour <email@hidden>
References: 
 >Rép: date/Snow Leopard changed (From: Yvan KOENIG <email@hidden>)

  • Prev by Date: Re: Help the shocked make a transition
  • Next by Date: Re: Texand Lists Continued
  • Previous by thread: Rép: date/Snow Leopard changed
  • Next by thread: Re: Rép: date/Snow Leopard changed
  • Index(es):
    • Date
    • Thread