Hi Austin,

Thanks for your help!  I ended up going with the second method
(entry.gd$when[0].startTime, etc.) and a similar regex to the one on
this page: http://delete.me.uk/2005/03/iso8601.html (without the parts
relating to 'offset').

It seems to be working great so far!

Cheers.

On Mar 24, 5:34 pm, "Austin (Google)" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Thanks for bringing this issue up.  Actually since I never try to access my
> calendar with a different local timezone, so I never actually discover this
> dilemma.  Yes you are right, it appears that both google.gdata.DateTime and
> the native JavaScript Date object both are quite "smart" in converting the
> date information to your local timezone on your browser (which comes from
> your OS).
>
> It seems like there is no way within JavaScript Date object to re-set the
> timezone -http://www.w3schools.com/jsref/jsref_obj_date.asp
>
> So one way is you can get is deal with your time through UTC timezone
> (GMT-0), so you will call getUTCMonth(), getUTCXXX() and so on.
>
> Another way you can get the actual time information consistent with your
> calendar timezone is to retrieve the datetime string label directly (without
> using google.gdata.DateTime object).  You just need to write some regex to
> parse out all differnet information.  You can get the raw datetime string
> like this -
>
> entry.gd$when[0].startTime
>
> Hope it helps,
> Austin
>
>
>
> On Sun, Mar 23, 2008 at 6:21 PM, G <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > I've taken the sample script from the URL at the bottom of this post,
> > and modified it slightly to suit.  It retrieves upcoming google
> > calendar events and outputs them as a list in a styled div element.
> > The script works great, except that the dates & times change relative
> > to the time zone setting on the viewer's computer.  I would prefer if
> > they were displayed in the time zone specified in the calendar, or
> > (even better) in a time zone that I specify.  Does anyone know how to
> > accomplish this, if it is possible?  Here is the script:
>
> > /*  Output Google Calendar Events in a Styled <div> element */
>
> > /* Callback function for the Google data JS client library to call
> > when an error occurs during the retrieval of the feed.  Details
> > available depend partly on the web browser, but this shows a few basic
> > examples. In the case of a privileged environment using ClientLogin
> > authentication, there may also be an e.type attribute in some cases.
> > */
> > function handleGDError(e) {
> >  if (e instanceof Error) {
> >    /* alert with the error line number, file and message */
> >    alert('Error at line ' + e.lineNumber + ' in ' + e.fileName + '\n'
> > + 'Message: ' + e.message + '\n' + '\n' + 'Please contact the
> > webmaster.');
> >    /* if available, output HTTP error code and status text */
> >    if (e.cause) {
> >      var status = e.cause.status;
> >      var statusText = e.cause.statusText;
> >      alert('Root cause: HTTP error ' + status + ' with status text
> > of: ' + statusText);
> >         }
> >        }
> >  else {
> >    alert(e.toString());
> >  }
> > }
>
> > /* Callback function for the Google data JS client library to call
> > with a feed of events retrieved.  Creates an unordered list of events
> > in a human-readable form.  This list of events is added into a div
> > called 'events'.  The title for the calendar is placed in a div called
> > 'calendarTitle' */
> > function listEvents(feedRoot) {
> >  var entries = feedRoot.feed.getEntries();
>
> >  var eventDiv = document.getElementById('events');
> >  eventDiv.innerHTML = '';
>
> >  /* set the calendarTitle div with the name of the calendar */
> >  // document.getElementById('calendarTitle').innerHTML = "Calendar: "
> > + feedRoot.feed.title.$t;
>
> >  /* output message if there are no events */
> >  if (entries.length === 0) { eventDiv.innerHTML = '<p>No Results Were
> > Found</p>'; return; }
> >  else {
>
> >  /* otherwise, create a new unordered list */
> >  var ul = document.createElement('ul');
>
> >  /* loop through each event in the feed */
> >  var len = entries.length;
> >  for (var i = 0; i < len; i++) {
> >    var entry = entries[i];
> >    var title = entry.getTitle().getText();
> >    var where = entry.getLocations()[0].getValueString();
> >    var startDateTime = null;
> >    var startJSDate = null;
> >    var times = entry.getTimes();
> >    if (times.length > 0) {
> >      startDateTime = times[0].getStartTime();
> >      startJSDate = startDateTime.getDate();
> >      endDateTime = times[0].getEndTime();
> >      endJSDate = endDateTime.getDate();
> >     }
> >    var entryLinkHref = ((entry.getHtmlLink() !== null) ?
> > entry.getHtmlLink().getHref() : '#');
>
> >  /* format the dates; 12-hour format with month names */
> >  var monthnames = new Array("Jan", "Feb", "March", "April", "May",
> > "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
>
> >        /* start date & time */
> >                var starthours = ((startJSDate.getHours() === 0) ? 12 :
> > (startJSDate.getHours() > 12) ? startJSDate.getHours() - 12 :
> > startJSDate.getHours());
> >                var startminutes = ((startJSDate.getMinutes() < 10) ? '0' +
> > startJSDate.getMinutes() : startJSDate.getMinutes());
> >                var startampm = ((startJSDate.getHours() > 11) ? 'p.m.' : '
> > a.m.');
>
> >                var startdate = monthnames[startJSDate.getMonth()] + ' ' +
> > startJSDate.getDate() + ', ' + startJSDate.getFullYear();
> >                var starttime =  starthours + ':' + startminutes + ' ' +
> > startampm;
>
> >        /* end date & time */
> >                var endhours = ((endJSDate.getHours() === 0) ? 12 :
> > (endJSDate.getHours() > 12) ? endJSDate.getHours() - 12 :
> > endJSDate.getHours());
> >                var endminutes = ((endJSDate.getMinutes() < 10) ? '0' +
> > endJSDate.getMinutes() : endJSDate.getMinutes());
> >                var endampm = ((endJSDate.getHours() > 11) ? 'p.m.' : '
> > a.m.');
>
> >                var enddate = monthnames[endJSDate.getMonth()] + ' ' +
> > endJSDate.getDate() + ', ' + endJSDate.getFullYear();
> >                var endtime =  endhours + ':' + endminutes + ' ' + endampm;
>
> >        /* create the date string */
> >            var dateString = ((startdate == enddate && starttime ==
> > endtime) ? startdate + ' ' + starttime : (startdate == enddate &&
> > starttime != endtime) ? startdate + ' ' + starttime + ' - ' +
> > endtime : startdate + ' ' + starttime + ' - ' + enddate + ' ' +
> > endtime);
>
> >  /* output the event in HTML */
> >  var li = document.createElement('li');
> >  entryLink = document.createElement('a');
> >  entryLink.setAttribute('href', entryLinkHref);
> >  entryLink.setAttribute('title', 'Open Event Details in a New
> > Window');
> >  entryLink.setAttribute('target', '_blank');
> >  entryLink.appendChild(document.createTextNode(title + ''));
> >  li.appendChild(entryLink);
> >  ul.appendChild(li);
> >                var ul2 = document.createElement("ul");
> >                var li2 = document.createElement("li");
> >                      li2.appendChild(document.createTextNode(dateString));
> >                ul2.appendChild(li2);
> >                var li3 = document.createElement("li");
> >                          li3.appendChild(document.createTextNode('Where: '
> > + where ));
> >                ul2.appendChild(li3);
> >                ul.appendChild(ul2);
> >  }
> >  eventDiv.appendChild(ul);
> >  }
> > }
>
> > /* Uses Google data JS client library to retrieve a calendar feed from
> > the specified URL.  The feed is controlled by several query parameters
> > and a callback function is called to process the feed results. */
> > function loadCalendar(calendarUrl) {
> >  var service = new google.gdata.calendar.CalendarService('gdata-js-
> > client-samples-simple');
> >  var query = new
> > google.gdata.calendar.CalendarEventQuery(calendarUrl);
> >  query.setOrderBy('starttime');
> >  query.setSortOrder('ascending');
> >  query.setFutureEvents(true);
> >  query.setSingleEvents(true);
>
> >  /* set the maximum results */
> >  query.setMaxResults(10);
> >  service.getEventsFeed(query, listEvents, handleGDError);
> >  }
>
> > /* Determines the full calendar Url based upon the calendarAddress
> > argument and calls loadCalendar with the calendarUrl value. */
> > function loadCalendarByAddress() {
> >  var calendarAddress = ' (removed)  ';  // Google Calendar Address
> >  var calendarUrl = 'http://www.google.com/calendar/feeds/'+
> > calendarAddress + '/public/full';
> >  loadCalendar(calendarUrl);
> >  }
>
> > /* Loads the Google data JavaScript client library */
> > google.load("gdata", "1");
> > function init() {
> >        /* init the Google data JS client library with an error handler */
> >           google.gdata.client.init(handleGDError);
>
> >        /* load the calendar */
> >           loadCalendarByAddress();
> >  }
>
> > google.setOnLoadCallback(init);
>
> > ___________________________________
> > Script source (slightly modified):
>
> >http://gdata-javascript-client.googlecode.com/svn/trunk/samples/calen...- 
> >Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to