Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General principle around time measurement units/formats for various domains (JS, HTTP, HTML, etc)? #344

Open
csharrison opened this issue Oct 7, 2021 · 15 comments
Assignees
Labels
Agenda+ Status: Consensus to write We have TAG consensus about the principle but someone needs to write it (see "To Write" project)

Comments

@csharrison
Copy link

csharrison commented Oct 7, 2021

This was brought up in our discussion of a new HTML attribute in the Attribution Reporting API (WICG/attribution-reporting-api#132)

The existing TAG principles (https://w3ctag.github.io/design-principles/#milliseconds) are focused on Javascript APIs. Should those principles be extended to all Web Platform APIs including things like HTML attributes, HTTP headers, etc?

@annevk
Copy link
Member

annevk commented Oct 8, 2021

Probably not? At least HTTP uses delta-seconds, HTML uses date and time strings, and both make sense to me given the domain.

I'm not even sure if all APIs ought to use milliseconds. I believe media uses seconds (as floats) pretty consistently (at least in the media element APIs). @padenot might have thoughts here.

@padenot
Copy link

padenot commented Oct 11, 2021

I believe media uses seconds (as floats) pretty consistently (at least in the media element APIs). @padenot might have thoughts here.

Various high-level media things use seconds as double (it matters greatly that those are 64-bits double), but for Web Audio API it's a number of sample-frames divided by a sample-rate, it's possible to get an integer from it (which is important). Web Codecs uses integer microseconds, because that's what is expected by authors familiar with codecs. Authors doing advanced audio work are always using integers.

A millisecond is a very long period of time, for media at least, and being able to pick the best unit (or get an integer) and type matters a lot more than always having milliseconds I think, especially in lower level APIs.

@csharrison
Copy link
Author

Thanks folks for chiming in, looks like there isn't a ton of value in recommending milliseconds outside of JS APIs (and even then it seems like there is a lot of wiggle room).

Let me pose a slightly different question to @annevk: If we feel that different domains (HTTP / HTML) have different standards that make sense, do we feel this strong enough to write it down as a TAG design principle? Personally I think it would be great if this resource said something like "prefer integer seconds for HTTP and date/time strings for HTML".

@annevk
Copy link
Member

annevk commented Oct 12, 2021

Yeah, from other changes it does seem like the document is trying to cover the various domains so that would make sense.

cc @LeaVerou

@LeaVerou
Copy link
Member

We definitely want the document to cover the various domains, yes.

Agenda+ing to discuss, since I'm not sure we should even be recommending milliseconds for JS APIs given the existing examples provided here.

@csharrison csharrison changed the title General principle around using milliseconds for time measurement General principle around time measurement units/formats for various domains (JS, HTTP, HTML, etc)? Oct 12, 2021
@torgo torgo added this to the 2021-11-01-week milestone Oct 30, 2021
@kenchris
Copy link
Contributor

kenchris commented Dec 8, 2021

We should definitely remove the text saying to always use milliseconds. It is quite common in DOM APIs though, like setTimeout, setInterval, WebAnimations, Vibrate etc

We also have a few polling APIs using frequency instead (like Generic Sensors).

Telemetry APIs like Performance.now() often use DOMHighResTimestamp which makes sense in that domain.

Maybe we can remove the milliseconds example and instead say to stay consistent with other APIs in the same domain, like the telemetry domain uses DOMHighResTimestamp, etc

@LeaVerou
Copy link
Member

LeaVerou commented Dec 8, 2021

We discussed this today in our virtual f2f. It doesn't appear there is one universal guidance here (like what is currently in the spec), APIs across the Web Platform do different things, and often for good reason.

Therefore, the guidance needs to be more nuanced than a blanket "use milliseconds and DOMHighResTimeStamp that it is now, and possibly include a list of precedents, so that API Designers can choose what to be compatible with based on their use case.

@LeaVerou LeaVerou added the Status: Consensus to write We have TAG consensus about the principle but someone needs to write it (see "To Write" project) label Dec 8, 2021
@LeaVerou
Copy link
Member

LeaVerou commented Dec 8, 2021

@kenchris will take a stab at some initial text, and then we can iterate.

@csharrison
Copy link
Author

Related: If TAG has advice on when to use HTTP-Date vs. delta seconds (or both, like Retry-After) for header-based APIs that would be appreciated.

@annevk
Copy link
Member

annevk commented Jan 3, 2022

I'm pretty certain that if you can use offsets in HTTP, you should. They are much more reliable than timestamps.

@jyasskin
Copy link
Contributor

jyasskin commented Jan 5, 2022

For the question of HTTP headers, it's worth checking with @mnot.

@mnot
Copy link
Member

mnot commented Jan 5, 2022

Using HTTP-Date is problematic for a few reasons:

  • Parsing is all over the map, especially around error handling (e.g., see these tests)
  • parsing is relatively expensive
  • To adjust for clock sync, you need to have a Date header available (which means you need to parse two dates)
  • Because of that, potential drift is doubled to two seconds

Delta-seconds are much more straightforward. People sometimes ask for sub second resolution in HTTP headers, but we typically push back on accommodating that in specs, since the RTT for a request can easily make that meaningless at best and a footgun at worst.

People still argue for HTTP-Date or similar in headers (see eg ietf-wg-httpapi/deprecation-header#11 (comment)), mostly for developer ergonomics. IMO that doesn't overcome the deficiencies above, so any help along these lines would be welcome.

I've also toyed with the idea of a Date type in Structured Fields, but the only advantage I see over just using an integer (either delta or epoch) is the ability to display it as a date in things like devtools...

@mnot
Copy link
Member

mnot commented Jan 5, 2022

Oh, and fields that have more than one form (like Retry-After) have proven to be problematic; I wouldn't recommend that practice.

@csharrison
Copy link
Author

Thanks @mnot for the well-argued and constructive advice, it is really appreciated!

@dret
Copy link

dret commented Jan 10, 2022

agreeing with @mnot in principle, but i think even if there is no need to constrain the syntax in structured fields, it would help a lot to define and make referencable the desired semantics. after all, designers look at structured fields to figure out which data types they can/should use using that spec. having well-defined and referencable definitions for something like DateTime would help a lot (even if it's just an alias for an otherwise unconstrained integer).

@cynthia cynthia self-assigned this Mar 8, 2022
@torgo torgo modified the milestones: 2022-06-06-week, 2022-10-03-week Oct 2, 2022
@plinss plinss removed this from the 2022-10-03-week milestone Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agenda+ Status: Consensus to write We have TAG consensus about the principle but someone needs to write it (see "To Write" project)
Projects
None yet
Development

No branches or pull requests