Re: [calsify] RFC 5545/JSCalendar questions from ECMAScript TC39 "Temporal" working group

Neil Jenkins <neilj@fastmailteam.com> Tue, 04 August 2020 03:35 UTC

Return-Path: <neilj@fastmailteam.com>
X-Original-To: calsify@ietfa.amsl.com
Delivered-To: calsify@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id C63713A0A8C for <calsify@ietfa.amsl.com>; Mon, 3 Aug 2020 20:35:29 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -0.197
X-Spam-Level:
X-Spam-Status: No, score=-0.197 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=fastmailteam.com header.b=vsb5L0bp; dkim=pass (2048-bit key) header.d=messagingengine.com header.b=AJAc/iWZ
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iRvAboTiBptE for <calsify@ietfa.amsl.com>; Mon, 3 Aug 2020 20:35:28 -0700 (PDT)
Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id BE6CF3A0A6E for <calsify@ietf.org>; Mon, 3 Aug 2020 20:34:51 -0700 (PDT)
Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E386D5C0086; Mon, 3 Aug 2020 23:34:50 -0400 (EDT)
Received: from imap7 ([10.202.2.57]) by compute4.internal (MEProxy); Mon, 03 Aug 2020 23:34:50 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= fastmailteam.com; h=mime-version:message-id:in-reply-to :references:date:from:to:cc:subject:content-type; s=fm3; bh=Wb0J d8EwvbLNyu5qt6CmZN22W1IC45V6GBBUMR6hgRY=; b=vsb5L0bpoZ8XhDuw4FIJ YYwVfJGe0fzYtUP2HFZpf2DlblmdugVC1p/Z9jut5yDB9+G/pzrRHgZFms7JIrD1 ZdcYrQ+er+a+3Kt7RsodayXNS5NJpaUTrJXCNPHMiSyy5+JUYZtTVs3o2UAzjO2O QK5H/jzF6UmdkF0KgdsIvkNZmhoMMMIF0AF5icUyGLVTHQAp0zF0yjHM4rg/CMAz qC+i/6v/TwH8xokSkt7ZUuSclc8QN9l+hYC3mecY7KVV+OVbSnDeBd8eqHtGx6dq VP+ZP5/QHYgskeJ7xW5Lm42SCelPihAPVLvFgX70nP8Uy9y6qPK/h2IcCiDf9vY3 mg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Wb0Jd8 EwvbLNyu5qt6CmZN22W1IC45V6GBBUMR6hgRY=; b=AJAc/iWZPY7vI762/fWWHu j7BxDd8R6fYPGQpMi1Vpuz2B6rtIVPPPRCm1kNHYm+YoIHy0eTBnXInu0r7hMMnh 4wtWlbv2AuUIr1DkKyjrJA5i4mMAYvhT6vs2W3L4gaL6OUT25QcAziMiVC58G7rC 1yEmVYNQFnWwXHIwATKhOsep2Imx1OXq+pRiYnr65uTTpjH4fqTbHNwx4b7HWyTk cAEmKRUy36fpxApHcEwhvdju94dy1VRZv+r1gNcYKm34JJNbhDmaBnZ1bw1pljiS cTPpb/tRoiDRz7Pe31n+MBjYKI2wubasyij2tQQb1yyHwqGdJE5GIod/szAUQ9vA ==
X-ME-Sender: <xms:WtcoXz-Qtc_Ob1QeUPKHyH09oiG9IzFUdheecG6jW0ZC3kdqK0yMuQ>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrjeehgdejfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesrgdtre erreerjeenucfhrhhomhepfdfpvghilhculfgvnhhkihhnshdfuceonhgvihhljhesfhgr shhtmhgrihhlthgvrghmrdgtohhmqeenucggtffrrghtthgvrhhnpeehuefhudejtdeive ekvdfhfffgleeflefhfeekhefhkeelkefhfeeufeevffejieenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehnvghilhhjsehfrghsthhmrghilh htvggrmhdrtghomh
X-ME-Proxy: <xmx:WtcoX_sg8XMG8wA7TyjKv-43DA0M-DA55050ablALSojQY7sWdsRuQ> <xmx:WtcoXxDlEApaVule1FL7ug5TQkXc4yOtesrfa_zoZiLe2StP6ddg8Q> <xmx:WtcoX_dTocb7OUAxa1FS1WPIaApd28ty6DwDeRl8F9DV3hMWDXnKUw> <xmx:WtcoX-YjahFIQrjvdfeF_Jbc4mnBstVdefSUCZJr5UeIIWI-ysrctw>
Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9BE3F1804C6; Mon, 3 Aug 2020 23:34:50 -0400 (EDT)
X-Mailer: MessagingEngine.com Webmail Interface
User-Agent: Cyrus-JMAP/3.3.0-136-gc39b634-fm-20200803.001-gc39b6340
Mime-Version: 1.0
Message-Id: <6d357b96-9899-4bd3-93e0-97e147a86a4d@dogfood.fastmail.com>
In-Reply-To: <CACy7CfgbPG_ugC59CZWtMwA7w4UOJR=zUkovKzvHUdeoFxnpjg@mail.gmail.com>
References: <CACy7CficiNXA_tb01c0=PWQTnXPVu_e7TgWAKUVPY-ow9C=3SQ@mail.gmail.com> <5bfd4453-e9a9-4bf4-b403-1b2f19cc790a@dogfood.fastmail.com> <CACy7CfgbPG_ugC59CZWtMwA7w4UOJR=zUkovKzvHUdeoFxnpjg@mail.gmail.com>
Date: Tue, 04 Aug 2020 13:34:49 +1000
From: Neil Jenkins <neilj@fastmailteam.com>
To: Justin Grant <justingrant.ietf.public@gmail.com>
Cc: calsify@ietf.org
Content-Type: multipart/alternative; boundary="c67f31cfdd564eb19720a3a21c0126ce"
Archived-At: <https://mailarchive.ietf.org/arch/msg/calsify/t9BWmIVYdXtcg831hmENACbQ5ZU>
Subject: Re: [calsify] RFC 5545/JSCalendar questions from ECMAScript TC39 "Temporal" working group
X-BeenThere: calsify@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <calsify.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/calsify>, <mailto:calsify-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/calsify/>
List-Post: <mailto:calsify@ietf.org>
List-Help: <mailto:calsify-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/calsify>, <mailto:calsify-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 04 Aug 2020 03:35:30 -0000

On Mon, 3 Aug 2020, at 14:46, Justin Grant wrote:
> Yep, agreed. This is a rare use case so it's definitely not worth a breaking change. Our goal is to find a deterministic, least-surprising solution for this weird case.  Ideally someone else would have already standardized how to handle this case and we could just adopt the standard, but so far I haven't found it.
> 
> Does JSCalendar include any guidance about how to calculate durations from two date/time+timezone (DATE-TIME - FORM #3) values?  If not, would you be interested in collaborating with us to define an algorithm that could be used by Temporal and included in the JSCalendar spec? This may help with interop.

We don't have anything currently defined, but I am interested in adding it; I agree it could be useful for interop.

> Finally, could you explain what you mean by "*I think you would have to change the interpretation of durations (Q1) in order to do anything different"* ?

What I mean is that the addition operation of a duration to a date is well defined, and we don't plan to change it. Therefore, the “correctness” of an algorithm for calculating a duration between dates X and Y is constrained by the simple fact that the duration "D" that results must be such that X + D = Y.

The Temporal case is further constrained because you are representing both sets of dates in overlapping time periods. Therefore to go back to the example you gave in the previous email:

> One problem is that the Addition Path and the Subtraction Path can return different results when an endpoint is in the "repeated hour" after DST ends in the fall. For example, assume that X is 2020-10-31T01:30-07:00[America/Los_Angeles] and Y is 2020-11-01T01:30-08:00[America/Los_Angeles] (the "second" 1:30AM on the day DST ends).  If we start from X, then we'd add one nominal day to get 2020-11-01T01:30-07:00[America/Los_Angeles] (the "first" 1:30AM), and then add one exact hour to get to the end. So the result is P1DT1H.  But if we start from Y, then subtracting one nominal day from 2020-11-01T01:30-08:00[America/Los_Angeles] yields 2020-10-31T01:30-07:00[America/Los_Angeles]. There is no time remainder. So the result is P1D.

As I said before, both of these durations are arguably valid in RFC5545. However in Temporal, the Subtraction one is not valid:
 * X = 2020-10-31T01:30-07:00[America/Los_Angeles]
 * Y = 2020-11-01T01:30-08:00[America/Los_Angeles]
 * D = P1D (by the subtraction method)
 * X + D = 2020-11-01T01:30-07:00[America/Los_Angeles] ≠ Y

The "Addition" algorithm however does produce the correct result, and I think is a reasonable basis for an algorithm to adopt. The one change I think it needs is to account for when the time of the earlier date is in the no-mans-land of a DST transition, and the end day is on a transition day. e.g. 
 * X = 2020-03-06T02:30-08:00[America/Los_Angeles]
 * Y = 2020-03-08T03:15-07:00[America/Los_Angeles]
If you try to use the Addition Path:
 * Let D = Y - X ignoring TZ => P2D
 * Let I = X+D => 2020-03-08T02:30 => 2020-03-08T03:30-07:00[America/Los_Angeles] according to resolution rules, which is after Y.
So I think that we just need to add an extra check at step (C): if you get an absolute time *after* the end time Y, subtract 1 day from the duration and try again. e.g.
 * Let D = P2D - 1 day => P1D
 * Let I = X+D => 2020-03-07T02:30-08:00[America/Los_Angeles]
 * Let T = Y - X in absolute time => PT23H45M
 * Result = D + T => P1DT23H45M

Neil.