time to gmt

Hi Nigel,

Setting System Preferences to 24 hour clock didn’t make it work, but adding PM to the times did work.

on TZtoTZ(TZ1date, TZ1, TZ2)
	return (do shell script ("eraTime=$(TZ=" & TZ1 & " date -jf '%Y-%m-%dT%H:%M:%S' '" & (TZ1date as «class isot» as string) & "' '+%s') ; TZ=" & TZ2 & " date -r  \"$eraTime\" '+%Y-%m-%dT%H:%M:%S'") as «class isot») as date
end TZtoTZ

set dt1 to date ("10/26/2013 12:00 PM")
set dt2 to date ("10/27/2013 12:00 PM")

(TZtoTZ(dt2, "Europe/Berlin", "GMT") - TZtoTZ(dt1, "Europe/Berlin", "GMT")) / hours --> 25.0

Where do you get the locations from like “Europe/Berlin”?

Thanks,
kel

That’s alright, I need to see ‘environ’.

Thanks,
kel

the 12/24 hour setting in Date & Time is just the display mode,
the system locale settings are located in Language & Text > Region

In this particular case, I just used “Europe/Berlin” because that’s what juergen said was his time zone in post #6. One way to get the time zone on the local computer is, as in post #16, to parse the POSIX path pointed to by the symbolic link “/etc/localtime”:

set localTZ to (do shell script ("readlink '/etc/localtime' | sed 's|/usr/share/zoneinfo/||'"))

This was interesting, I started to dig a little into the zoneinfo files that lies below /usr/share.

When I use the command zdump zoneinfo/US/Hawaii I get the current time back, according to the manual, in utc. So, they don’t do much useful, the commands to read tzone files from the shell. I think you’ll have to set the LC_TZ to something for their usefullness to kick in.

I was hoping to get the offset or something, instead I ended up with the knowledge that leap seconds aren’t included in posix time (seconds since epoch.) :confused: (man time2posix)

What you’re seeing is correct; you’re just not looking at the full picture. Change your script to this:

set dt1 to date ("26.10.2013 12:00")
set dt2 to date ("27.10.2013 12:00")
log dt1
log dt2

(dt2 - dt1) / hours 

Now go to System Preferences, Language & Text, and change the Medium format for time display so that it also includes the timezone. Run the script and look at the logged values. You might now agree with AppleScript :wink:

If you want to do much with AS dates, the key is to ignore the string value, and just deal with the underlying components.

Hello everybody,

I found a pretty good list here:

http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/timezone.html

Here’s a better list that contains the daylight savings times offset:

https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

It’s better to use the same list as the mac does, that is the IANA Time Zone Database. Here you can download the plain text versions of the files that are serialized in /usr/share/zoneinfo. When downloading these plain text files you can look into these files and see the history of time settings.

I’ll just add to what is written above: I believe there is a way to decompile the zoneinfo files. but zdump gives you some output, zdump -v exactly what DJ Bazzie Wazzie said. You should get further pointers by looking at man zdump.

As a user, the most usage you have of the zone-info database is the timezone names really, and you’ll use those to set the TZ variable with them, then use the date to see the new time. Perfect for making a world clock with AppleScript. Berlin London Paris New York Tokoyo. :slight_smile:

To utilize, and have fun with the different timezones, then have a look at this page.

You should also have a thourough look at man date,I believe the %F format to be the «class Isot» counterpart in AppleScript.

It’s equivalent to the “yyyy-mm-dd” part. The time part can be obtained with “%T”. So in my TZtoTZ handler, “%Y-%m-%dT%H:%M:%S” can be reduced to “%FT%T”. Thanks for the heads-up! :slight_smile:

The formatting is actually done by strftime.

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

Hi DJ Bazzie Wazzie,

Great site. It looks like everything is in there. Interesting files:

I agree. People can adjust to getting up when the sunrises without any help. :slight_smile:

Thanks,
kel

Hi McUsr,

I’ve been searching through unix for info, but haven’t checked out dump yet.

I was thinking exactly about making a world clock along with timers, etc. Great minds. :slight_smile:

Nice shortcut with the %F. It makes Nigels script more readable also.

Thanks,
kel

Off Topic.

Time has always been a nuisance, just ask the slave serving under the tyrant of scicily, when said tyrant, moved the time stone higher up, for getting more daylight on it, and hence prolong the working hours.

And the watch makers of Florence, who got their eyes stabbed out by angry factory workers that suddenly, had to follow the clock, and abandon daylight governing the length of their workday. But, the utilization of the clock, made Florence the most productive creator of fabrics from the weaveries, and made her prosper.

Our problems seems meagre. :slight_smile: (Especially with Nigel’s handlers.)

It is good to be usefull at times. :slight_smile:

Hi Nigel,

Your script is working great.

I was trying to find a country and location that had -11 hours somewhere in the Pacific. It’s interesting that Guam is far to the east but in the same time zone as well as some other islands. I finally found American Samoa with -11. I was thinking that the main reason for all the squiggly time zone lines in the Pacific is for trading reasons.

Interesting stuff.

Thanks,
kel

That is why Samoa and Tokelau moved to the other side of the dateline in 2011/2012

http://www.bbc.co.uk/news/world-asia-16351377

Hi Juergen,

I don’t recall hearing about Tokelau. Is that the island that is being flooded by global warming?

kel

Hello.

:smiley: I couldn’t help it, here is a small “WorldClock” while we were at this topic.

# /usr/share/zoneinfo contains the files.
# to deduct which timezones you want to display:
# visit: http://www.timeanddate.com/
set worldtimes to do shell script "for i in Australia/Melbourne Canada/Atlantic Us/Central Us/Hawaii GMT Europe/London Europe/Paris Europe/Berlin
do
	printf \"%-40s\" $i; export TZ=$i ; date
done |tr ' ' ' '
"
tell application "TextEdit"
	tell (make new document at front)
		set text of it to worldtimes
		set font of every character to "Andale Mono"
		set size of every character to 14
	end tell
	tell its front window
		#	set {item 3 of its bounds, item 4 of its bounds} to {800, 300}
		set _bounds to bounds
		set item 3 of _bounds to (item 1 of _bounds) + 650
		set item 4 of _bounds to (item 2 of _bounds) + 300
		set bounds to _bounds
		
	end tell
end tell
do shell script "open -b \"com.apple.textedit\""

Edit

I forgot Hawaii! I am not looking forward to thinking about Hawaii during the winter here :slight_smile: , maybe that’s why I forgot it, pine-apple trees are so much more attractive than pines.

Edit++

Added open -b to assure that the text edit window is brought to front.

Hi McUsr,

Nice script and table. You might want to add sizing to the document.

BTW, pineapples grow close to the ground. :slight_smile: Something like an aloe plant with thinner leaves. We just had some pineapple and they were so sweet!

I can’t wait to get this yard back in shape, so I can spend more time on the computer! :smiley:

Great example with the time zone script.

Thanks a lot,
kel

I have set the size for the resulting window above, which should work for
a resolution of 1920X1200.

I am not envious really, it must be wonderful to live such a place, where scraping ice of your cars windows in the morning rarely happens. :smiley:

I have other ideas with this, I wonder if quicklook, will respect sizes set for a html document.