Have a plain text document containing a whole bunch of event start and end times. The times are in Eastern Time.
I would like to do a find/replace to convert these times from Eastern Time to Pacific Time.
The text list is formated thus:
(excepting the time “##:##[Space]?M”, all Spaces below are for readability)
6:15 AM [one Tab] Event-name [one Return]
Event-summary [one Tab] End [one Tab] 6:35 AM [two Returns]
6:45 AM …same as above
7:30 AM …same
8:20 AM …
…and continuing
10:30 AM …
11:45 AM …
12:00 PM …
1:00 PM
…and continuing
2:45 PM
6:30 PM
9:30 PM
10:00 PM
12:00 AM …
…and continuing to the following day’s events.
I tried Tex-Edit Plus and BBEdit’s Grep search/replace without much luck – Grep won’t do math.
I’m purdy dang sure AppleScript can figure this out – I have done a little AppleScripting. However, this one is behond my head.
As I see it, some kind of string-to-numeric conversion is needed and then the time shift subtraction (3 hours) to get to PST.
Thanks very much,
Model: Power Mac G4 Dual 1.42 GHz
AppleScript: 2.0
Browser: Safari
Operating System: Mac OS X (10.3.9)
Here’s an example of converting your example text. Note that the start times are the first text items in tab delimited fields for each event.
set t to "6:15 AM Event-name
Event-summary End 6:35 AM
6:15 AM Event-name
Event-summary End 6:35 AM
6:15 AM Event-name
Event-summary End 6:35 AM"
set def_tid to AppleScript’s text item delimiters
– get an event list
set AppleScript’s text item delimiters to {return & return}
set event_list to text items of t
– convert times to pacific tiem i.e. subtract 3 hours
set new_list to {}
repeat with this_event in event_list
– separate the start and end times of tab delimited text
set AppleScript’s text item delimiters to {tab}
set item_list to text items of this_event
set AppleScript’s text item delimiters to def_tid
tell item_list
set {start_time, end_time} to {item 1, item -1}
end tell
– convert to applescript date for subtraction
set {start_date, end_date} to {date start_time, date end_time}
– optional: check if end date should fall on next day
if end_date < start_date then
set end_date to (end_date + 1 * days)
end if
– subtract 3 hours from the dates and convert to text
set {pacific_start, pacific_end} to ¬
{time string of (start_date - 3 * hours), time string of (end_date - 3 * hours)}
– replace list item for this event
tell item_list
set {item 1, item -1} to {pacific_start, pacific_end}
end tell
– coerce list to tab delimited text
set AppleScript’s text item delimiters to {tab}
set new_event to item_list as string
set AppleScript’s text item delimiters to def_tid
– add modified text to the new list
set end of new_list to new_event
end repeat
– coerce the new list to blank line sepearated event text (double return)
set AppleScript’s text item delimiters to {return & return}
set new_text to new_list as string
set AppleScript’s text item delimiters to def_tid
– write the new text to file
return new_text
I didn’t know if you needed help with the reading and writing to text file part.