time to gmt

Yep, that was it. I have to remember the pipes for common names.

Edited: nice script library. Very fast. One more question. I was reading about AppKit and thinking about trying some of that. Is that in Foundation or do you need to add?
use framework “AppKit”

Edited: that’s ok. I see that they automatically add AppKit in an Xcode project along with Foundation.

Thanks a lot,
kel

on us_datum()
	return (month of date ("01 02 03" as text) is January)
end us_datum

us_datum()

Edit: More generally:

on users_date_order()
	set {year:y, month:m, day:d} to date ("01 02 03" as text)
	set order to {missing value, missing value, missing value}
	
	set item (y mod 10) of order to "year"
	set item (m as integer) of order to "month"
	set item d of order to "day"
	
	return order
end users_date_order

users_date_order()

PS. It looks as if we could do with some kind of “time to GMT” system on this BBS! (For the benefit of US and Canadian readers: MacScripter’s message times are show in the rest of the world as crude offsets from US time. Since the US clocks didn’t go back an hour yesterday with much of the rest of the northern hemisphere, the times we see are currently an hour out.)

In simple terms, Foundation is the nuts and bolts, like strings, arrays, yada, yada. AppKit is the stuff for building apps with UI, like windows, buttons. There is some cross-over, but that’s the general idea.

If you like playing with dates and time, there’s some cool stuff, especially some of the new stuff in NSCalendar. Methods like -isDateInTomorrow and -isDate:inSameDayAsDate:.

Hello.

Excellent handlers as always Nigel!

It is good to know the why’s isn’t it? By the way, the/your code below work through the whole year since it relies on the Unix subsystem, at least as long as «class isot» isn’t broken. :slight_smile:

on civilTimeToGmtFromLocalTZInSeconds(anASDate)
		return (anASDate - (TZtoTZ(anASDate, (do shell script "readlink /etc/localtime |sed -n 's_/[^/]*/[^/]*/[^/]*/\\([^/]*\\)/\\([^/]*\\).*_\\1/\\2_p'"), "GMT")))
	end civilTimeToGmtFromLocalTZInSeconds
	
	on TZtoTZ(TZ1date, TZ1, TZ2)
		return (do shell script ("eraTime=$(TZ=" & TZ1 & " date -jf '%FT%T' '" & (TZ1date as «class isot» as string) & "' '+%s') ; TZ=" & TZ2 & " date -r \"$eraTime\" '+%FT%T'") as «class isot») as date
	end TZtoTZ

Thank you. :slight_smile:

Of course, in the users_date_order() hander, it’s only really necessary to extract two of the date’s property values. The third index can be obtained by simple arithmetic. So the ‘month’ extraction, say, and its coercion to integer could be avoided like this:

on users_date_order()
	set {year:y, day:d} to date ("01 02 03" as text)
	set order to {missing value, missing value, missing value}
	
	set item (y mod 10) of order to "year"
	set item d of order to "day"
	set item (6 - y mod 10 - d) of order to "month"
	
	return order
end users_date_order

users_date_order()

Nigel,
Nice script. :cool: Tricky.

Shane,
I was just reading the release notes the other day with all the additions. There were a couple of additions to NSUserNotification also. Good article at your site.

McUsr,
Is that a different script than the one you posted before (Nigel’s optimized one)?

Nope, but this time it is posted for a different reason, as Nigel stated a couple of posts above: Time To GMT is really unusable for transitions between timezones as it doesn’t follow the changes between standard and daylight savings times in individual timezones promptly, but does so indirectly by going through some US timezone . It is an ugly hack, a bug, or something that ought to be fixed anyway. (But then probably a whole lot of legacy code would be broken. Alas. )

Edit

I’am happy to tell that Shane Stanley informed me that Apple Fixed this in 10.8. (I was using 10.6 at the time I wrote the above.

Darn. I thought that the adjustments to daylight savings time internationally was adjusted automatically in the time to gmt on the computer. If it’s delayed, that’s not good.

Maybe you can recalibrate the times. Shift it.

Are you sure? One of the changes listed here:

developer.apple.com/library/mac/releasenotes/AppleScript/RN-AppleScript/RN-10_8/RN-10_8.html

is:

Hello.

Thanks for the update Shane!

I was on 10.6 saying that. I’m glad they have fixed it. (Later I figured out it wasn’t any reason they would keep it.) :slight_smile:

Edit

And thanks for the link to the release-notes for Mountain Lion too, I’ll guees I am about to be experience a lot of changes in one go now. :slight_smile: (Templates I have truly missed!)

Hi McUsr,

I was reading the release notes the other day and the changes weren’t that bad. There were more add-ons than deprecations.

Have a good day,
kel

Hello.

It is not that the change will be all bad, it won’t, it is just that I come from Snow Leopard, so I get all the changes from Lion and Mountain Lion as well. So there unevitably be some problems during the transition. In the end, I think this will be much better. :slight_smile: