From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Max Nikulin Newsgroups: gmane.emacs.bugs Subject: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones Date: Thu, 14 Apr 2022 20:19:04 +0700 Message-ID: <4a23f3a4-fe8f-d396-49d8-10034803be63__24786.1105761089$1649942426$gmane$org@gmail.com> References: <5ed963b2-3fa8-48d8-627e-bc0571d15b43@gmail.com> <149de00f-115b-5367-414f-c7700ef8966b@cs.ucla.edu> <2dd15844-01b3-0144-740c-185ec8488a81@cs.ucla.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22623"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Cc: emacs-orgmode@gnu.org, 54764@debbugs.gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 14 15:20:21 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nezOW-0005gh-LY for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 14 Apr 2022 15:20:20 +0200 Original-Received: from localhost ([::1]:56652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nezOV-0002pW-9z for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 14 Apr 2022 09:20:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nezOF-0002o3-3O for bug-gnu-emacs@gnu.org; Thu, 14 Apr 2022 09:20:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33478) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nezOE-0007eo-1c for bug-gnu-emacs@gnu.org; Thu, 14 Apr 2022 09:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nezOD-0002rw-T9 for bug-gnu-emacs@gnu.org; Thu, 14 Apr 2022 09:20:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Max Nikulin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Apr 2022 13:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54764 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 54764-submit@debbugs.gnu.org id=B54764.164994235410969 (code B ref 54764); Thu, 14 Apr 2022 13:20:01 +0000 Original-Received: (at 54764) by debbugs.gnu.org; 14 Apr 2022 13:19:14 +0000 Original-Received: from localhost ([127.0.0.1]:55608 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nezNS-0002qq-4R for submit@debbugs.gnu.org; Thu, 14 Apr 2022 09:19:14 -0400 Original-Received: from mail-lj1-f173.google.com ([209.85.208.173]:35537) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nezNQ-0002qd-PW for 54764@debbugs.gnu.org; Thu, 14 Apr 2022 09:19:13 -0400 Original-Received: by mail-lj1-f173.google.com with SMTP id h11so6000882ljb.2 for <54764@debbugs.gnu.org>; Thu, 14 Apr 2022 06:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=pmiyCfaKtoLb5GO/yT7sGNWW6EI28ufgGlHhNOoNHAI=; b=oR37Fs05z0brXuqW7BYrwzFY4wf5amRI/UU1pihvL2pu8570zM0Rb2gdGUEsDN6LzH xXUJNSUohkfMoT0fq8898uHGSwJKIYY8/wLEJBHhLKwKqaywpJMC/TdXgqfm+Eh/b/wV K436iBHsZ8U9hO1d4UZDyilh42HGKgZgbehlKrNjp3t3srmwdqnHj8PFol61F9xppTZz uAhcnjpLW6y8duzQqle1eOMXY5Rngf86pL0nbb507v0tLLVpzll9P1SHlDfM3YRjCbH3 vm1By8CJnRdTHAM70jNSVc3aRSqMqCKCv1a1d/LPRaxvvPO1JkWc7I2Jap+Q7hJy7ggl 25zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :subject:content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=pmiyCfaKtoLb5GO/yT7sGNWW6EI28ufgGlHhNOoNHAI=; b=WWbRTRrnvPd5bPBw5rmqBj0xhjuxpkw8oZW6+AwEXl2L2T2KkCa72Iw7Zsa42lDnLm LPdGU5fPOtWORFC5CU/KyhzoIlVW+tXKhXEuX+nIpzt+mNTucr9uZTASp0iUcbgN9AEg UcuUpCQaGFhCbpGP9Kl91nQwhzO3ZcUteTG9/uYnOb+QIqIakJDu6Hc7sDM9Spx8aICU voZyBXqLR9oqpOF74ipT4MjR0hPyNdl5BNZywHND8Gr/AoXBc5qmsv0hXg5KGpblfPu2 ibuvsoISJsNfb9mchfl5wgjjrhA6d04hpk/nisvp/qvLgoTyHyhFI1dobcZWwYpd/LBL pjzg== X-Gm-Message-State: AOAM533QbWRTic06xwVYqVKMxRUh8q2RgHqFHDViTNKonxmf+x3wScMK FUo9vJ7oOfI60iwhujBUxfY= X-Google-Smtp-Source: ABdhPJx6cOTVmGDCJsmCefgAQQHJ+Srp3XJEoXEmdHyOEQgR5N3lQal+GfqT6sri4Xw0+RY97S57Cw== X-Received: by 2002:a2e:bf01:0:b0:247:dfe7:62dc with SMTP id c1-20020a2ebf01000000b00247dfe762dcmr1575175ljr.365.1649942346472; Thu, 14 Apr 2022 06:19:06 -0700 (PDT) Original-Received: from [192.168.0.101] (nat-0-0.nsk.sibset.net. [5.44.169.188]) by smtp.googlemail.com with ESMTPSA id z19-20020a19e213000000b0046d052030aasm243472lfg.66.2022.04.14.06.19.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Apr 2022 06:19:05 -0700 (PDT) Content-Language: en-US In-Reply-To: <2dd15844-01b3-0144-740c-185ec8488a81@cs.ucla.edu> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:229865 Archived-At: On 14/04/2022 01:35, Paul Eggert wrote: > On 4/13/22 07:40, Max Nikulin wrote: >> >> I do not see a way to get 23:30 EAT +0300. > > Are you asking for a function F where you say, "I want to give F a > possibly-ambiguous decoded local time D, and for F to return all > timestamps that map to D"? If so, encode-time doesn't do that, because > the underlying C API (namely, mktime) doesn't do that. All mktime and > encode-time do is give you *one* timestamp that maps to D; it won't give > you any other timestamps. I am just trying to convince you that new API still can not handle ambiguities in response to: >>> Unfortunately it makes the function more convenient to >>> use incorrectly. This was part of the motivation for the API change. >>> The obsolescent calling convention has no way to deal with ambiguous >>> timestamps like 2022-11-06 01:30 when TZ="America/Los_Angeles". Completely ignoring DST in old API is a bug. Possibility to omit DST and ZONE is a feature for convenience and it is not related to correctly/incorrectly. It has no common with allowing 6-values SECONONDS...YEAR list. I am aware of mktime and my opinion is that libc in such cases (dealing with formats for humans) is hardly usable for applications more complex than "hello world". I do not want all ambiguous time values. I want to provide hints how they should be resolved and get in response an additional value that says in which way it is actually resolved. > If you're worried about possibly-ambiguous decoded local times, you > could probe (say) one day before and one day after encode-time's result > to see if the UTC offset changes, and let that guide you to find other > possible timestamps that map to the decoded time. Although this is just > a heuristic it should be good enough. I would prefer to avoid dances with +/-1 day timestamps. I would not be surprised when one day they will give wrong result. During computations it is available to which interval of time current time offset is valid. Such value may be included in result of conversion. So date-time + "America/Los_Angeles" input should not be reduced to timezone offset in the output. Zone internal object or identifier is important for calculation of other date-time values based on the origin value. > I doubt whether you need to do that, though. Code that is not careful > about local time offsets doesn't care how ambiguous decoded times are > resolved. And code that does care should record UTC offsets anyway, and > you can use those offsets to disambiguate the decoded times. Something > like this, say: > >  (defun encode-and-format-time (time tz) >    (let ((etime (encode-time (parse-time-string time)))) >      (format-time-string "%F %T %Z %z" etime tz))) > > With this definition, (encode-and-format-time "2021-01-31 23:30:00 > +0300" "Africa/Juba") yields "2021-01-31 23:30:00 EAT +0300", which is > the timestamp you want. I want hints like "in the case of ambiguity resolve to transition time immediately before/immediately after transition" or "provide suitable time prior to/after to transition". I hope, they may work without explicitly providing time zone offset to the input that anyway requires additional calculations. ±n hours may mean ±n*3600 seconds or time with same minutes and seconds values but hours value is changed by n even if a 30 min DST transition happens in between. If agenda interval start falls on skipped time span in local time then the value immediately after transition should be used (and maybe user should be warned by additional entry). For agenda end interval vice versa local time immediately before transition is more suitable. `parse-time-string' has another set of problems. It is impossible to specify particular format like for strptime(3). Actually parsing a string to numerical values and resolving ambiguities in numerical values are different tasks and it may be useful to have separate functions for them. I am unsure however concerning implementing constraints to parse free-form dates. >> `encode-time' should only accept time zone as time offset and should >> not allow default or named value that may be ambiguous. > > If we're talking about Org's encode-time substitute, you can of course > do what you like. But Emacs encode-time has supported ambiguous > timestamps for some time and I expect it's used by apps that don't care > how ambiguous decoded times are resolved, which means we shouldn't > remove that support without having a very good reason. There is no reason to impose such restrictions for helpers in Org since Org relies on resolving ambiguities with minimal efforts. `encode-time' supports just one kind of ambiguities. Even though it is the most common one, it is rather (partially false) impression than real support. The truth is that most of developers are not aware of real complexity of dealing with time. Documentation rarely describes limitations and corner cases that should be handled. Even when correct time handling gets more priority it appears that available libraries are full of bugs and require ugly workarounds. >> should be possible to provide hints to `encode-time' to get >> deterministic behavior in the case of time transitions > > Yes, that feature is already there. The hint is the UTC offset, as > illustrated above. No, UTC offset is another feature and implementing the hints I have tried to describe may require implementing from scratch full stack of time handling functions. In some cases offset should be replaced by time zone identifier to avoid incorrect result in further calculations. So I still do not see any point in mandatory DST and ZONE fields in new interface of `encode-time'. I do not see an alternative to convert SECONDS...YEAR values to timestamp assuming local time zone as well. Anyway DST is not available in advance and sometimes DST value is not coupled with step in local time, so its ability to resolve ambiguities is limited.