From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Christian" Newsgroups: gmane.emacs.devel Subject: Timezone handling problem in icalendar.el/icalendar-import-* Date: Wed, 16 Dec 2009 14:39:20 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: ger.gmane.org 1260970801 27941 80.91.229.12 (16 Dec 2009 13:40:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Dec 2009 13:40:01 +0000 (UTC) To: Emacs development discussions Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 16 14:39:54 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NKu6b-0004WW-K3 for ged-emacs-devel@m.gmane.org; Wed, 16 Dec 2009 14:39:54 +0100 Original-Received: from localhost ([127.0.0.1]:49228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NKu6b-0002BA-Ia for ged-emacs-devel@m.gmane.org; Wed, 16 Dec 2009 08:39:53 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NKu6U-00026T-8w for emacs-devel@gnu.org; Wed, 16 Dec 2009 08:39:46 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NKu6P-0001vd-3L for emacs-devel@gnu.org; Wed, 16 Dec 2009 08:39:45 -0500 Original-Received: from [199.232.76.173] (port=58206 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NKu6O-0001vN-Vv for emacs-devel@gnu.org; Wed, 16 Dec 2009 08:39:41 -0500 Original-Received: from ebb06.tieto.com ([131.207.168.38]:53788) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NKu6O-0003xQ-DY for emacs-devel@gnu.org; Wed, 16 Dec 2009 08:39:40 -0500 X-AuditID: 83cfa826-b7b83ae0000037a5-e6-4b28e3182977 Original-Received: from FIHGA-EXHUB01.eu.tieto.com ( [131.207.136.34]) (using TLS with cipher AES128-SHA (AES128-SHA/128 bits)) (Client did not present a certificate) by ebb06.tieto.com (SMTP Mailer) with SMTP id 30.30.14245.813E82B4; Wed, 16 Dec 2009 15:39:36 +0200 (EET) Original-Received: from uw000475.eu.tieto.com (10.48.99.26) by inbound.tieto.com (131.207.136.49) with Microsoft SMTP Server id 8.2.176.0; Wed, 16 Dec 2009 15:39:35 +0200 User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.50 (gnu/linux) X-Brightmail-Tracker: AAAAAhIa6uUSGwEJ X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:118650 Archived-At: I have detected a problem with timezone handling in icalendar.el; unfortunately I know far too little about timezones to be able to say what the correct fix is. The problem was discovered in trying to use icalendar to parse some Microsoft Exchange 2007 appointments on a SuSE 10.1 Linux system. I am using emacs version "23.1.50.1" (from CVS) and the icalendar distributed with that. The appointments are recorded in timezone GMT+2 whereas I am in timezone GMT+1. But when extracting the appointment using `icalendar-import-buffer', all times where an hour off. Basically, it was as if the appointment was registered in GMT rather than GMT+2. After a lot of huffing and puffing, I narrowed it down to the following piece of code: (format-time-string "%Y-%m-%dT%T%z" (encode-time 0 30 11 16 12 2009 "(STD?)-02:00(DST?)-03:00,M3.-1.0/03:00:00,M10.-1.0/04:00:00")) ;=> "2009-12-16T09:30:00+0100" When evaluated, this returns a time of 09:30 but it should have reported 10:30. Checking the man page for `tzset', however, I read the following: The second format is used when there is daylight saving time: std offset dst [offset],start[/time],end[/time] ... Mm.w.d This specifies day d (0 <= d <= 6) of week w (1 <= w <= 5) of month m (1 <= m <= 12). Week 1 is the first week in which day d occurs and week 5 is the last week in which day d occurs. Day 0 is a Sunday. and sure enough, if I change the week specification from "-1" to "5" as in: (format-time-string "%Y-%m-%dT%T%z" (encode-time 0 30 11 16 12 2009 "(STD?)-02:00(DST?)-03:00,M3.5.0/03:00:00,M10.5.0/04:00:00")) ;=> "2009-12-16T10:30:00+0100" I now get the correct start time of 10:30. In other words, at least on this particular Linux system, a week specification for DST start/end of "-1" is not supported, making `encode-time' falling back to GMT. Instead one should use "5" to indicate the last week of the month. I have no idea whether this is a bug in icalendar, SuSE 10.1 or Linux as such. One fix (but I doubt it is the correct one) is to change the function `icalendar--convert-tz-offset' into the following (one `if' form has been inserted following the comment of "FIX"): (defun icalendar--convert-tz-offset (alist dst-p) "Return a cons of two strings representing a timezone start. ALIST is an alist entry from a VTIMEZONE, like STANDARD. DST-P is non-nil if this is for daylight savings time. The strings are suitable for assembling into a TZ variable." (let ((offset (car (cddr (assq 'TZOFFSETTO alist)))) (rrule-value (car (cddr (assq 'RRULE alist)))) (dtstart (car (cddr (assq 'DTSTART alist))))) ;; FIXME: for now we only handle RRULE and not RDATE here. (when (and offset rrule-value dtstart) (let* ((rrule (icalendar--split-value rrule-value)) (freq (cadr (assq 'FREQ rrule))) (bymonth (cadr (assq 'BYMONTH rrule))) (byday (cadr (assq 'BYDAY rrule)))) ;; FIXME: we don't correctly handle WKST here. (if (and (string= freq "YEARLY") bymonth) (cons (concat ;; Fake a name. (if dst-p "(DST?)" "(STD?)") ;; For TZ, OFFSET is added to the local time. So, ;; invert the values. (if (eq (aref offset 0) ?-) "+" "-") (substring offset 1 3) ":" (substring offset 3 5)) ;; The start time. (let* ((day (icalendar--get-weekday-number (substring byday -2))) (week (if (eq day -1) byday (substring byday 0 -2)))) ;; FIX for bad week spec (if (equal week "-1") (setq week "5")) (concat "M" bymonth "." week "." (if (eq day -1) "0" (int-to-string day)) ;; Start time. "/" (substring dtstart -6 -4) ":" (substring dtstart -4 -2) ":" (substring dtstart -2))))))))) ------------------------+----------------------------------------------------- Christian Lynbech | christian #\@ defun #\. dk ------------------------+----------------------------------------------------- Hit the philistines three times over the head with the Elisp reference manual. - petonic@hal.com (Michael A. Petonic)