all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Questions about encode-time and decode-time
Date: Thu, 25 Mar 2021 10:20:38 +0200	[thread overview]
Message-ID: <83a6qrk5k9.fsf@gnu.org> (raw)
In-Reply-To: <828s6bbriw.fsf@gmail.com> (message from Pascal Quesseveur on Thu, 25 Mar 2021 08:51:03 +0100)

> From: Pascal Quesseveur <pquessev@gmail.com>
> Date: Thu, 25 Mar 2021 08:51:03 +0100
> 
> Hi Elli, Thank you for the time spent answering me. I must admit that
> I don't know much about timezones. I simply tried to understand what
> was happening following a time error in the decoding of a Icalendar
> appointment. According to what I understand the data of the VTIMEZONE
> block is decoded into a string of the type
> "STD-01:00DST-02:00,M3.5.0/02:00:00,M10.5.0/03:00:00" and associated
> with the TZID. Then this string is used in encode-time operations.

This has no chance of working correctly on Windows around the DST
change date.  We need some code to convert these DST specifications to
what Windows can understand; patches welcome.

> As you told me those strings weren't handled properly on Windows, I
> tested with a simple ID. Now I know I should have used CET but I am
> suprised by the result of:
> 
> (decode-time (encode-time (list 0 30 9 14 3 2021 nil -1 "CET")))
> --> (0 30 10 14 3 2021 0 nil 3600)
> 
> I thought I would get (0 30 9 14 3 2021 0 nil 3600).  To get that
> value I have to call:
> 
> (decode-time (encode-time (list 0 30 9 14 3 2021 nil -1 "CET")) "CET")
> 
> The docstring says: The optional ZONE is omitted or nil for Emacs
> local time, ... So what is the Emacs local time? 

Whatever DST information is stored on your Windows system -- the same
information that Windows itself uses to automatically switch from
Standard time to Daylight Savings time.

The problem here is the difference between the rules Windows uses
natively to switch into and from DST, and the rules the C runtime
library uses when TZ is set to the likes of "CET".  The former is
generally quite accurate and follows the rules used by Posix systems,
but the relevant Windows APIs don't support the Posix-style DST string
rules such as "STD-01:00DST-02:00,M3.5.0/02:00:00,M10.5.0/03:00:00".
The latter, also known as "USA rules for DST", assume that DST is
entered on 02:00 on the first Sunday in April and exited on 01:00 of
the last Sunday in October -- these are the old USA DST rules, which
were changed even in the US long ago.

So when you use "CET", the C library uses different DST rules from
those used when you omit the timezone.  Thus the discrepancy you
observe.



  reply	other threads:[~2021-03-25  8:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 17:11 Questions about encode-time and decode-time Pascal Quesseveur
2021-03-23 18:27 ` Pascal Quesseveur
2021-03-23 19:21   ` Eli Zaretskii
2021-03-24  7:27     ` Pascal Quesseveur
2021-03-24 13:40       ` Eli Zaretskii
2021-03-24 14:36         ` Pascal Quesseveur
2021-03-24 17:29           ` Eli Zaretskii
2021-03-25  7:51             ` Pascal Quesseveur
2021-03-25  8:20               ` Eli Zaretskii [this message]
2021-03-25 11:26                 ` Pascal Quesseveur
2021-03-25 11:45                   ` Eli Zaretskii
2021-03-25 12:48                     ` Pascal Quesseveur

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=83a6qrk5k9.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=help-gnu-emacs@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.