• 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: CalendarLib question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CalendarLib question


  • Subject: Re: CalendarLib question
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 27 Mar 2018 14:00:14 +1100

On 27 Mar 2018, at 1:15 pm, Christian Boyce <email@hidden> wrote:
>
> Does CalendarLIb (or CalendarLibEC) include the time zone in the event date?

It allows for it. Well, the underlying framework does.

> If I run the script on a machine in the Pacific time zone, I get a (for
> example):
>
> event_start_date ==> date "Tuesday, March 27, 2018 at 3:00:00 PM"
> If I run the script on a machine in the Central time zone I get the result==>
> date "Tuesday, March 27, 2018 at 5:00:00 PM"

That's correct behavior. If you pick up the phone at 3pm and ring the person in
Texas, it will be 5pm there. That's how the calendar works, and you should get
the same result in Calendar.app.

If you want an event to show the same time regardless of the time zone it's
read in, you should use a floating date. Or convert time zones.

if you're running 10.11 or later, you could do it like this:

        -- get event info
        set theInfo to (event info for event anEvent)
        set theInfo to adjustDateForInfo(theInfo)

With this handler:

on adjustDateForInfo(theInfo)
        script dateChanger
                use framework "Foundation"
                on changeDateIn:theInfo
                        set zoneName to event_time_zone of theInfo
                        if zoneName is not missing value then
                                set theDate to event_start_date of theInfo
                                set localOffset to (current application's
NSTimeZone's defaultTimeZone()'s secondsFromGMTForDate:theDate)
                                set eventOffset to ((current application's
NSTimeZone's timeZoneWithName:zoneName)'s secondsFromGMTForDate:theDate)
                                set event_start_date of theInfo to theDate +
eventOffset - localOffset
                                set theDate to event_end_date of theInfo
                                set localOffset to (current application's
NSTimeZone's defaultTimeZone()'s secondsFromGMTForDate:theDate)
                                set eventOffset to ((current application's
NSTimeZone's timeZoneWithName:zoneName)'s secondsFromGMTForDate:theDate)
                                set event_end_date of theInfo to theDate +
eventOffset - localOffset
                        end if
                        return theInfo
                end changeDateIn:
        end script
        return dateChanger's changeDateIn:theInfo
end adjustDateForInfo

(I hope I haven't subtracted where I should have added…)

--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >CalendarLib question (From: Christian Boyce <email@hidden>)

  • Prev by Date: CalendarLib question
  • Previous by thread: CalendarLib question
  • Index(es):
    • Date
    • Thread