From: "Christian" <christian.lynbech@tieto.com>
To: Emacs development discussions <emacs-devel@gnu.org>
Subject: Timezone handling problem in icalendar.el/icalendar-import-*
Date: Wed, 16 Dec 2009 14:39:20 +0100 [thread overview]
Message-ID: <ytqp1vivca2f.fsf@uw000475.eu.tieto.com> (raw)
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)
next reply other threads:[~2009-12-16 13:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-16 13:39 Christian [this message]
2009-12-16 14:18 ` Timezone handling problem in icalendar.el/icalendar-import-* Andreas Schwab
2009-12-16 18:38 ` Christian Lynbech
2009-12-16 20:40 ` Ulf Jasper
2009-12-17 10:09 ` Christian
2009-12-17 20:57 ` Ulf Jasper
2009-12-18 7:47 ` Christian
2009-12-18 19:38 ` Ulf Jasper
2009-12-18 22:40 ` Christian Lynbech
2009-12-19 12:16 ` Ulf Jasper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ytqp1vivca2f.fsf@uw000475.eu.tieto.com \
--to=christian.lynbech@tieto.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.