javascript - How do you account for time-zone offset when retriving an "All Day" event from Google Calendar API? -


i have ajax call retrieve information public google calendar:

$.ajax({       url: "https://www.google.com/calendar/feeds/{calid}/public/full?start-min={starttime}&start-max={endtime}&alt=json-in-script&callback=?";       datatype: 'json',       timeout: 3000,       success: function( data ) { processdata(data);}, }); 

within function processdata(data) have following statement:

starttime = new date(data.feed.entry[i].gd$when[j].starttime); 

which stores in starttime date() object date particular event starts. google uses iso 8601 time format: yyyy-mm-ddthh:mmtzd (eg 1997-07-16t19:20+01:00) , works fine. however, "all day" events format in form: yyyy-mm-dd (eg 1997-07-16) (which allowed w3 http://www.w3.org/tr/note-datetime) , in case new date() interpret gmt. is, correct particular date local time zone if event created in local time-zone. in particular case, when retrieving "all day" event on, say, april 7th 2014 happening in time zone return string if 5 hours earlier

  new date("2014-04-07") 

returns sun apr 06 2014 19:00:00 gmt-0500 (cdt) off 5 hours. (see following question more details on date parsing)

have ever had deal issue when using google calendar? , if so, how did solve it? should using different method instead of new date() account time zone?

google's json response contains parameter feed.timezone, contains olson's time zone id i'd need way convert (hopefully ajax call or that) id actual offset. found following question in forum problem parameter api needs actual city , not time zone id making me somehow make translation time zone id city pass url string.

any appreciated!

when iso 8601 strings offset "work fine", leaving parsing date constructor, or doing yourself? browsers won't correctly parse iso string, , more won't correctly parse string offset. there's answer here shows how parse iso string offset browsers.

in regard how deal dates, issue has business logic answer. if interpreted iso 8601 string, in timezone west of greenwich (or more hour west during daylight saving time), result in date 1 day before. if wish treat local date, you'll need first test string see if it's date , if so, treat local, e.g.

if (/^\d{4}-\d{2}-\d{2}/.test(datestring) {   // treat date } else {   // treat date , time } 

parsing string local date pretty simple:

// expect date string in iso 8601 format yyyy-mm-dd // date created local date function parselocaldatetime(s) {   s = s.split(/\d+/g);   return new date(s[0], --s[1], s[2]); } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -