[calsify] Subtraction vs. DST disambiguation

Justin Grant <justingrant.ietf.public@gmail.com> Wed, 30 September 2020 21:50 UTC

Return-Path: <justingrant.ietf.public@gmail.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 C43DE3A0CC4 for <calsify@ietfa.amsl.com>; Wed, 30 Sep 2020 14:50:44 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.098
X-Spam-Level:
X-Spam-Status: No, score=-2.098 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
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 d9U5VIJGfZfS for <calsify@ietfa.amsl.com>; Wed, 30 Sep 2020 14:50:39 -0700 (PDT)
Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 57D673A0C1D for <calsify@ietf.org>; Wed, 30 Sep 2020 14:50:39 -0700 (PDT)
Received: by mail-ej1-x634.google.com with SMTP id dd13so5028545ejb.5 for <calsify@ietf.org>; Wed, 30 Sep 2020 14:50:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=zrl3zDR/oMFLbTd23stnrFobI5dHas6tB+wUwL0SphM=; b=SXR5SwbmIoHRNQ2Wtu0mm5jblCXpTOX7SF/JPrpMF5g2JYDE3tEiq9eHSq9cmBJarT udCSSwqszrJ0KDBIGEUpJYPCsWOAtEzZ00gdzGOtFgCzrPAd9lmC9oxebm4W2Sel37Ph U8c3lXo8ZVwVLXa5WYL02MjdIjUBuUHTOUiSgNhF2i5+v/c9kbFslAh7948ArE19At+8 yPSjz7wiTFGXOUGVG2gzczcUmD5zE52pGX4x3+DPAiJSD+nOpaGV+doyMBaxj/sB55+f C49QmWOAPYSYGNMx2y/Hyd0XB0FkxfMCOUO+QmWv5xqa0ij/tzqduYcRwlxYSKhrr8Um x/cA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=zrl3zDR/oMFLbTd23stnrFobI5dHas6tB+wUwL0SphM=; b=lHvjGqdhLdCfYtsFfX8J91Sdso3nsgdJrvHd1IAMpshNjjPqe3WEVAfp4QtF7zBfHb 24BRSLGY2JlSBm6u14A47U4PSB7iElV6uGrslTV3c0xetiY2cpKZJUOgx/y/swB6GhRi aSGzJQI1ovR54yvOiYI9uwz2krA0uFieJ78RzWYn95VQAf0aEE7RfTn7nOIuH6rCIIf3 UYuNDqN6Oxhr/3H0KfoxlOZq+oboNz3643T0bTpjSkmiV+2Bs0kpqZhmPzW7uCedkJBi CrikAmxVtSMpKuVz3ul5NtSb0Xl3fOXMaI8Fw34GvQze4NI8EF1EGGvhfAQCH0OKpTyc zkQw==
X-Gm-Message-State: AOAM530OIM73lACX2jnJtb00OTDZy9KpNy4UXB4oJufVlFvxRdeoG8No LUXaF6BWb776l0iHKFMpFecqNjGmSj861M7Z1leoXiUQlb4=
X-Google-Smtp-Source: ABdhPJzurkvMHYU3COWZ3l2wRO2z06jiFMHuKa9Oa1FBLkvUMWK4PRhN1fyGeXNMidSvdb2Q9xKxtvLooUC5r50RS2U=
X-Received: by 2002:a17:906:c447:: with SMTP id ck7mr4867130ejb.358.1601502637527; Wed, 30 Sep 2020 14:50:37 -0700 (PDT)
MIME-Version: 1.0
From: Justin Grant <justingrant.ietf.public@gmail.com>
Date: Wed, 30 Sep 2020 14:50:26 -0700
Message-ID: <CACy7CfgLvQN=B0_+quGbFLLDNupraSuvxk9a++Y4LUDc_V2nkA@mail.gmail.com>
To: calsify@ietf.org
Content-Type: multipart/alternative; boundary="000000000000d1157605b08ee315"
Archived-At: <https://mailarchive.ietf.org/arch/msg/calsify/F-vtf-0bTWn6LAAc59qmpp2rloU>
Subject: [calsify] Subtraction vs. DST disambiguation
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: Wed, 30 Sep 2020 21:50:51 -0000

Hi Neil (and others!) -

This email is a follow-up to our previous discussions about how Temporal
and JSCalendar should specify the subtraction algorithm. We previously
agreed that, in order to make subtraction reversible with subsequent
addition of the same value, we'd reverse the order of operations so with
subtraction of a positive duration (or adding a negative duration) the time
portion would be subtracted first, and then the date portion.

I think I found another potential problem with subtraction: DST
disambiguation of nominal times that end up in the middle of a DST-skipped
period. The default behavior is to use the earlier offset, which results in
one hour later than the invalid time. This makes the clock time impact of
the addition operation one hour longer.

But what if you're subtracting days and the endpoint of the subtraction is
in the middle of a skipped period?  In that case, clock time is still
advanced one hour, which makes the subtraction result one hour shorter.

For example: `2020-03-09T02:30-07:00[America/Los_Angeles]` -` P1D`
The result is `2020-03-08T03:30-07:00[America/Los_Angeles]`
And if I add `P1D` to that result, I get
`2020-03-09T03:30-07:00[America/Los_Angeles]`, which is one hour later than
my original time.  It's not reversible.

I'm not sure there's any way to avoid this problem. We could choose to
reverse the disambiguation behavior and pick the later offset, but that
doesn't solve the reversibility problem, because we'd just get a
one-hour-earlier result instead of a one-hour-later one. It'd also
introduce interesting behavior where the same result in nominal time is
resolved to a different result in exact time depending on whether a
subtraction or an addition was being performed.

There's also another, more obscure problem: in rare cases time zone
discontinuities can be a full day long, e.g. Samoa's 2011 switch to
opposite sides of the International Date Line where `2011-12-30` was
skipped. In that case, I could get into an infinite loop while subtracting
`P1D` from `2011-12-31T12:00+14:00[Pacific/Apia]` because after subtracting
one day in nominal time, we'd add that one day right back to end up with
the same result:  noon on Dec 31.

Note that this is only an issue when subtracting full days, because
subtracting times will always use exact time.

Anyone have any ideas for how we should handle this case?  Should we use
the later offset for disambiguation when subtracting full days, but use the
earlier offset for disambiguation in all other cases?  Or is there some
other, more-targeted solution?  Or is the weirdness with the date-line
change rare enough that we shouldn't worry about it?

Cheers,
Justin Grant
https://github.com/tc39/proposal-temporal