Re: [Cbor] Encoding Arbitrary Time Ratios

Emile Cormier <emile.cormier.jr@gmail.com> Mon, 05 April 2021 23:39 UTC

Return-Path: <emile.cormier.jr@gmail.com>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 29A203A2C88 for <cbor@ietfa.amsl.com>; Mon, 5 Apr 2021 16:39:46 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.097
X-Spam-Level:
X-Spam-Status: No, score=-2.097 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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=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 tqE9JWmMjwNv for <cbor@ietfa.amsl.com>; Mon, 5 Apr 2021 16:39:41 -0700 (PDT)
Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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 AD3943A2CB4 for <cbor@ietf.org>; Mon, 5 Apr 2021 16:39:41 -0700 (PDT)
Received: by mail-pl1-x62a.google.com with SMTP id e10so2091349pls.6 for <cbor@ietf.org>; Mon, 05 Apr 2021 16:39:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oadwWZdctqL+XMt6RI50G4+XPbcvCUzWjVxDAm2PsSQ=; b=KubB+92x8b2VEUnJul99DBuvbvfdSzkJd588958rgc07JeNLOBGptubT4jap924GKR WX9V/ovYiEmxvRgEoC5/xBOAEwWfNV2zcSL47lR2RnV+th3eZeR362pmPCNJVnRc0qmt xzMBm8MPHoQuBCCh+0W7El0JPf1TsWLEqoogioNa3pQKNrSrGew9mYA6nJQbpROYgH8F P6/E/2QQDCJT4kFSrfZMdb3Qc4KrPa39E3HmURd3UQPtBVNbXQrXK+rF8W1HzVYxtQNS P4m/Z/MJjZjfEuKXAN5QL5sJbF88a/ItlQ5vjTpIzYtiQjC7hLEBnvkyR86lmyNebSNF kp5Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oadwWZdctqL+XMt6RI50G4+XPbcvCUzWjVxDAm2PsSQ=; b=CkcUdltPHL3nqVhueXgO6ZQBn8tiUCtEavLlkJ6wp6JhoCRqAkuN1N5CpGzYf7FXW8 6Ir1czqpRmL/CI7Tqn1WunBP14MYpBQB1XF63xyWevKiGgfauxJ7VH9kB3OFXL3XlpWP oNLEU4uoEPixrV7YiEy6RpOyOg6UBvjd/52XfnpnrFsjjZi2oXNMm8/oEdKV3M1ubRYK K7QIsVADQez6D8wbzQgGQ2dRn98Pjewg/9UiEd0fRnIZQ51fsxT1L0fN48akR7VknqLL zF+tiK50cnZnK6Z+5P4KT/tyUaaDs+2pRfUoCWYoVJEOUn4+BMiaNJgrVZy418fj0Tez X+GA==
X-Gm-Message-State: AOAM530DNvNwuuaq78O9JIrMlfyxP3BLjBfeDsQFJsmHpvXYU33pSNLU +/pirFptn4TWpAGS+l0dpuR4eHen9AyHVDaY5H8=
X-Google-Smtp-Source: ABdhPJzy198gT39yYrLjwfuccV9smeCs/Js5t+Y1k6I2v59txPgjUbVY67Vm+4o/yCJy3DFdhlRErJ4xGHxXFxtvT5Q=
X-Received: by 2002:a17:90a:5898:: with SMTP id j24mr1521926pji.110.1617665979530; Mon, 05 Apr 2021 16:39:39 -0700 (PDT)
MIME-Version: 1.0
References: <CAM70yxBF2XeewhsXOGv06kTVitz1kNHkYLHGqm3gX0Vyc2c2YA@mail.gmail.com> <2403465.MzrCfxQRY8@tjmaciei-mobl1> <CAM70yxAvoZmURMZHNY3-pKceU0mPbny=-QRAEeEzM2P0pcYrAg@mail.gmail.com> <2096114.vpHZ4K6Zy5@tjmaciei-mobl1>
In-Reply-To: <2096114.vpHZ4K6Zy5@tjmaciei-mobl1>
From: Emile Cormier <emile.cormier.jr@gmail.com>
Date: Mon, 05 Apr 2021 20:39:28 -0300
Message-ID: <CAM70yxBJe32LT3dZ-NEC+-On1BEg0Sgbsa7A-1h+V0Q-jFe-Gg@mail.gmail.com>
To: Thiago Macieira <thiago.macieira@intel.com>
Cc: cbor@ietf.org
Content-Type: multipart/alternative; boundary="00000000000013439405bf4236f4"
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/WdM2I_a5J2poLL3EZ6CkC5t6feo>
Subject: Re: [Cbor] Encoding Arbitrary Time Ratios
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 05 Apr 2021 23:39:46 -0000

On Mon, Apr 5, 2021 at 7:28 PM Thiago Macieira <thiago.macieira@intel.com>
wrote:


> I can accept indicating the number of days. I don't find that a
> particularly
> useful encoding, since it does little to save space, but does add
> complexity.
> I don't find saving 2 bytes because we can encode the whole number of days
> until June 2149 a compelling value.
>

My main motivation is not to save space. It's to save the computational
cost of an intermediate ISO8601 date string when both ends simply want to
exchange a std::chrono::sys_date (while preserving the date semantic). It's
the same motivation (presumably) as for tag 1. Not only is the Y/M/D to
days computation complex, you also have to check for invalid dates (e.g.
January 32nd, February 29 on a non-leap-year, etc).


> Please don't require rational numbers or BigFloat to represent time. The
> only
> valid encodings should be integers and floating point, and maybe not even
> the
> latter.
>

I can support that (no rational nor BigFloat), as long as there's a
mechanism to exchange dates as the number days since epoch without losing
the 'date' semantic.

I'm afraid the ship has already sailed regarding floating point
representation of time in the existing CBOR time tags. Javascript
'natively' handles time as floating point milliseconds. In Python, it's
floating point seconds.

We _could_ constrain a new, proposed "numeric date" tag to have an
integer-only data item, but it would not be consistent with the other
existing time tags which support both integer and floating point.
Javascript folks might complain about the lack of floating point.


> Semantically indicating a date without time would be far more valuable,
> regardless of how it gets encoded. Simply expressing a time point that
> happens
> to be midnight UTC on a particular date is not that. So I support this
> idea.
>

I'm also not fond of expressing dates as time-date values that coincide
with midnight.

I'm glad to hear about support for a numeric date tag in the same spirit as
tag 1. I'm happy to drop my "scaled ratio" idea if I can at least
efficiently transfer a std::chrono::sys_date without performing Gregorian
calendar conversions. All other likely use cases for
std::chrono::time_point (in seconds, ms, us, or ns) can be handled by the
existing tags.

Similarly, it would be useful to have just a time within a day.
>

That could be expressed with the CBOR duration tag (1002) as the duration
since midnight. Of course, the application would have to know to interpret
this duration as the time of day. std::chrono::duration is the recommended
way to store the time of day efficiently in C++. The new
std::chrono::hh_mm_ss in C++20 is intended more for display purposes.

Perhaps a key could be added in tag 1002 to indicate that the duration
represents a time of day?

Cheers,
Emile Cormier