From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guido Van Hoecke Subject: Re: Problem with Google Calendar Synchronization Date: Thu, 09 May 2013 15:24:15 +0200 Message-ID: References: <87vc6vxf06.fsf@thinkpad.tsdh.de> <874ned6fhj.fsf@ucl.ac.uk> <87a9o41ns3.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:45909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaQpZ-0006um-GE for emacs-orgmode@gnu.org; Thu, 09 May 2013 09:24:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UaQpX-0001x5-UE for emacs-orgmode@gnu.org; Thu, 09 May 2013 09:24:21 -0400 Received: from mail-wg0-x22b.google.com ([2a00:1450:400c:c00::22b]:45084) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaQpX-0001wy-Kl for emacs-orgmode@gnu.org; Thu, 09 May 2013 09:24:19 -0400 Received: by mail-wg0-f43.google.com with SMTP id c11so3057059wgh.10 for ; Thu, 09 May 2013 06:24:19 -0700 (PDT) In-Reply-To: <87a9o41ns3.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Thu, 9 May 2013 10:54:36 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: orgmode --=-=-= Content-Type: text/plain Eric, Eric S Fraga writes: > Guido Van Hoecke writes: > > [...] > >> My ics file had a.o. my elder sister's birthday, and unfortunately her's >> as well as mine is (way) before the start of the epoch, so mktime >> returns a negative timestamp at line 63 and strftime at line 143 doesn't >> grok it. > > Ah, I see. The script should at least not break just because some of us > (me included) are older than Unix... ;-) > > The fix should be straightforward. Could you try adding the lines > > if (timestamp < 0) timestamp = 0; > > after the call to mktime in the datetimestamp function? This should at > least make the script not crap out although obviously the date will be > wrong (set to start of epoch). If this works, I will update the script > on Worg and put in a warning message of some sort, maybe even in the > entry itself. With this change the script assigns the wrong date, but no longer stops. > Suggestions on how to handle this case would be welcome, of course. I created a patch so that the date and time string is built directly from the iCal data for times before the epoch. This function produces valid date/time strings albeit without weekday info. Patch file is attached. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=ical2org.patch --- ical2org.awk.orig 2013-05-09 14:15:14.000000000 +0200 +++ ical2org.awk 2013-05-09 15:11:44.000000000 +0200 @@ -27,7 +27,7 @@ # no further revision log after this as the file was moved into a git # repository... # -# Last change: 2011.01.28 16:08:03 +# Last change: 2013.05.09 15:11:44 #---------------------------------------------------------------------------------- # a function to take the iCal formatted date+time, convert it into an @@ -60,12 +60,31 @@ # print "adjusted : " timestamp # print "Time stamp : " strftime("%Y-%m-%d %H:%M", timestamp); + if(timestamp < 0) timestamp = 0; return timestamp; } +# a function to comvert the iCal date+time string into a date time string; +# it uses the datetimestamp subroutine to compute the value to feed to strftime; +# if the iCal date falls before time 0, the string is built from the iCal input; + +function datetimestring(input) +{ + # try to create datetimestring from the datetimestamp + timestamp = datetimestamp(input); + if (timestamp > 0) + return strftime("%Y-%m-%d %a %H:%M", datetimestamp(datetmp)); + + # this is a date before the start of the epoch + # create the yyyy-mm-dd hh:mm string from the input (without day of week) + datespec = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])T([0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]*", "\\1-\\2-\\3 \\4:\\5", "g", input); + # print "==> datespec:" datespec; + return datespec; +} + BEGIN { ### config section - max_age = 7; # in days + max_age = -1; #7; # in days # set this to -1 to get all entries or to N>0 to only get # that start or end less than N days ago ### end config section @@ -90,6 +109,7 @@ indescription = 0; lasttimestamp=-1; + print "#+TITLE: Main Google calendar entries" print "#+AUTHOR: Eric S Fraga" print "#+EMAIL: e.fraga@ucl.ac.uk" @@ -140,12 +160,12 @@ /^DTSTART;VALUE=DATE/ { datetmp = gensub("([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])(.*[\r])", "\\1T000000\\2", "g", $2) - date = strftime("%Y-%m-%d %a %H:%M", datetimestamp(datetmp)); + date = datetimestring(datetmp); if(max_age>0) lasttimestamp = datetimestamp(datetmp); } /^DTEND;VALUE=DATE/ { datetmp = gensub("([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])(.*[\r])", "\\1T000000\\2", "g", $2) - time2 = strftime("%Y-%m-%d %a %H:%M", datetimestamp(datetmp)); + time2 = datetimestring(datetmp); date = date ">--<" time2; if(max_age>0) lasttimestamp = datetimestamp(datetmp); } @@ -154,7 +174,7 @@ # we ignore the seconds /^DTSTART[:;][^V]/ { - date = strftime("%Y-%m-%d %a %H:%M", datetimestamp($2)); + date = datetimestring($2); if(max_age>0) lasttimestamp = datetimestamp($2); # print date; } @@ -165,7 +185,7 @@ /^DTEND[:;][^V]/ { # print $0 - time2 = strftime("%Y-%m-%d %a %H:%M", datetimestamp($2)); + time2 = datetimestring($2); date = date ">--<" time2; if(max_age>0) lasttimestamp = datetimestamp($2); } --=-=-= Content-Type: text/plain Kind regards, Guido -- Accident: A condition in which presence of mind is good, but absence of body is better. -- Foolish Dictionary --=-=-=--