• 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: easy one: current date in Paris
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: easy one: current date in Paris


  • Subject: Re: easy one: current date in Paris
  • From: kai <email@hidden>
  • Date: Wed, 6 Jul 2005 00:48:17 +0100


On Tuesday, July 5, 2005, at 10:22 pm, Michelle Steiner wrote:

Here is a generalized solution (that does not take daylight savings time into account):

This daylight saving thing is a real can of worms, isn't it? Personally I can't see why we cling on to it - especially in this day and age of more flexible working hours, etc. But then I wouldn't want to start a controversy over the matter. ;)


set timezones to {{"paris", 1}, {"new york", -5}, {"los angeles", -8}}

set city to first item of (choose from list {"paris", "new york", "los angeles"} with prompt "What city's time do you wish?")

repeat with pair in timezones
if first item of pair is city then
set the_offset to item 2 of contents of pair
exit repeat
end if
end repeat
set currentdate to (current date) - (time to GMT) + (the_offset * hours)


Can anyone figure out how to avoid the repeat loop?

Well... kinda - by reducing the list to a simpler form, rather than a list of lists (and then maybe only as a scripting exercise):


-------------

set timezones to {"Paris", 1, "New York", -5, "Los Angeles", -8}
set cityList to strings of timezones
tell (choose from list cityList with prompt ¬
	"What city's time do you wish?")
	if it is false then error number -128
	set city to item 1
end tell
set tid to text item delimiters
set text item delimiters to return & return
set citytxt to return & cityList & return
set text item delimiters to return & city & return
set the_offset to item ((count paragraphs of citytxt's ¬
	text item 1) div 2 + 1) of numbers of timezones
set text item delimiters to tid
"Current time in " & city & ": " & ((current date) - ¬
	(time to GMT) + the_offset * hours)'s time string

-------------

Frankly, as you can see from the contortions and list extractions, it's probably a whole lot simpler and faster to just use 2 lists and a loop:

-------------

set cityList to {"paris", "new york", "los angeles"}
set offsetList to {1, -5, -8}
tell (choose from list cityList with prompt ¬
	"What city's time do you wish?")
	if it is false then error number -128
	set city to item 1
end tell
repeat with n from 1 to count cityList
	if cityList's item n is city then exit repeat
end repeat
"Current time in " & city & ": " & ((current date) - ¬
	(time to GMT) + (offsetList's item n) * hours)'s time string

-------------

Now - about that small matter of daylight saving...

---
kai

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: easy one: current date in Paris
      • From: kai <email@hidden>
    • Re: easy one: current date in Paris
      • From: Martin Orpen <email@hidden>
References: 
 >Re: easy one: current date in Paris (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: What am I missing
  • Next by Date: Re: Capturing parts of text string [Re: Applescript-users Digest, Vol 2, Issue 443]
  • Previous by thread: Re: easy one: current date in Paris
  • Next by thread: Re: easy one: current date in Paris
  • Index(es):
    • Date
    • Thread