date calculation incompatibilities with panther?

I know there are certain date manipulations that can be done in tiger that will generate errors in panther. Unfortunately I cannot seem to find any list of what they are and possible work arounds. I’m trying to make an AS Studio app backwards compatible here and have no way to test. Can anyone point me to the definitive list?

Thanks.

Hi,

two new things in Tiger are:

¢ capability of setting a date’s month using an integer
¢ the date value properties hours, minutes, seconds

Hello

It would be useful to bookmark this address:

http://www.apple.com/applescript/releasenotes/

Yvan KOENIG (from FRANCE mercredi 27 décembre 2006 12:17:09)

Thanks you guys. What about work arounds though? For instance what if you needed to do these things in panther?


(* some or all of this might not work in panther *)

set cd to current date
set new_date to cd -- new date
set month of new_date to 6
set year of new_date to 2000 -- not sure if this would work in panther
set ch to hours of cd
set cm to minutes of cd
set another_new_date to (current date) + 1 * days + 3 * hours -- not sure if this would work or not in panther

(* not sure if any of this would work in panther *)
set cd to current date
set aBirthday to date "Wednesday, January 15, 1975 12:00:00 AM"
set abs_date to aBirthday
set this_year to year of cd
set year of abs_date to this_year
if abs_date < cd then
	set year of abs_date to (this_year + 1)
end if
set the_diff to round ((abs_date - cd) / days) -- the number of days until the birthday

set result to {new_date, ch, cm, another_new_date, abs_date, the_diff}

There’s nothing in your script that should fail on any version of AppleScript going back as far as I can remember - that’s at least the pre-Mac OS X days.

Hi,

your second part works fine in Panther,
the lines with ** had to be changed.
Probably you have to adjust the set-{cd, cm}-line to work with AM/PM,
I use 24 hour mode

set cd to current date
set Time_cd to time string of cd -- **
copy cd to new_date -- new date -- **
set month of new_date to June -- **
set year of new_date to 2000 -- not sure if this would work in panther
set oldDelims to AppleScript's text item delimiters -- **
set AppleScript's text item delimiters to {":"} -- **
tell text items of Time_cd to set {ch, cm} to {its item 1, its item 2} -- **
set AppleScript's text item delimiters to oldDelims -- **
set another_new_date to (current date) + 1 * days + 3 * hours -- not sure if this would work or not in panther

(* not sure if any of this would work in panther *)
set cd to current date
set aBirthday to date "Wednesday, January 15, 1975 12:00:00 AM"
set abs_date to aBirthday
set this_year to year of cd
set year of abs_date to this_year
if abs_date < cd then
	set year of abs_date to (this_year + 1)
end if
set the_diff to round ((abs_date - cd) / days) -- the number of days until the birthday

set result to {new_date, ch, cm, another_new_date, abs_date, the_diff}

Hi Camelot,

unfortunately not.
As written before, to set a date’s month as integer isn’t possible,
and there are no hours, minutes and seconds date value properties in Panther

Hello Stephan

You forgot to define Time_cd

Yvan KOENIG (from FRANCE mercredi 27 décembre 2006 19:50:14)

Thanks Yvan, I fixed it.
To avoid the error with the “strange” date format in set-aBirthday-line
I copied and pasted the changed lines and forgot some :wink:

Hi.

Another way to get the hours and the minutes on older systems is to get the time and then perform the appropriate, simple maths. To set the month to the nth month of a year, you can either set it to item n from a list of months, or set the month to December the previous year and set the day to n * 32 and then to the required day of the month. Edit: Actually, a better idea would be to set the month to January of the same year and then set the day to n * 32 - 31. (Subtracting one less than the multiple ensures that we never try to set the day to 0.) I’ve edited the script below.

set cd to current date
copy cd to new_date
set month of new_date to item 6 of {January, February, March, April, May, June, July, August, September, October, November, December}
-- Or:
set month of new_date to January -- Start with a date in January.
set day of new_date to 6 * 32 - 31 --  Set the day high enough to overflow into the 6th month.
set day of new_date to day of cd -- Then set the actual day required.

set year of new_date to 2000
-- Setting the 'day' to 6 * 32 - 31 above deliberately overflows the January date into the
-- sixth month of the year. Don't forget that overflows can also happen accidentally,
-- such as when the month of 31 December 2006 is set to September (1 October 2006),
-- or when the year of 29 February 2000 is set to 2001 (1 March 2001).

set ct to time of cd
set ch to ct div hours
set cm to ct mod hours div minutes
set another_new_date to (current date) + 1 * days + 3 * hours

set cd to current date
set aBirthday to date "Wednesday 15 January 1975 00:00:00"
set abs_date to aBirthday
-- abs_date and aBirthday are the same date object.
-- To change abs_date's year will be to change aBirthday's year.
-- If you don't want that, create a separate date object by changing
-- the above line to: copy aBirthday to abs_date.
set this_year to year of cd
set year of abs_date to this_year
if abs_date < cd then
	set year of abs_date to (this_year + 1)
end if
set the_diff to round ((abs_date - cd) / days) -- the nearest number of 24-hour periods until the birthday
-- Or:
set the_diff to (abs_date - (cd - (time of cd))) div days -- the number of calendar days until the birthday

-- set result to {new_date, ch, cm, another_new_date, abs_date, the_diff}
set theResult to {new_date, ch, cm, another_new_date, abs_date, the_diff} -- It's pointless setting AppleScript's 'result' variable.

Thanks y’all. Very helpful. Thanks for the info about “the same date object” – that resolved a weird problem too.

It’s occurred to me this morning that it would be better to set the month to January of the same year and then set the day to n * 32 - 31. I’ve edited my post above and have included some extra commentary about the last two lines of the script.