-
Notifications
You must be signed in to change notification settings - Fork 47
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
Advice on JS passing points-in-time or offsets-from-now #425
Comments
https://www.mnot.net/blog/2007/05/15/expires_max-age lists some other considerations, such as that point-in-time has more potential for invalid inputs. (If we did cookies today and ignored all their other problems they'd use max-age, for sure.) |
I think JS APIs avoid most of the issues in mnot's blog post by accepting a number of milliseconds past the Epoch, rather than HTTP's complicated date format. Unless I've missed something, the paragraph that's relevant to us is
|
It also seems true that with an offset you at least cannot give times in the past (or at least that's more easily enforceable). |
I would guess that Also, almost all of the time I want something like "in X units of time" rather than "at time X", and making the input be "at time X" requires me to do more math. Seems simpler to not make the developer do math. For longer durations I like the idea of accepting Durations, which are completely unambiguous and avoid the need for readers to figure out the math: |
What about both? Then a) UAs are not blocked by |
@LeaVerou, your "both" seems to be about accepting both a number and a Temporal object, once Temporal is ready? That's fine, but the question for this thread is whether to accept points-in-time or offsets-from-now. Before Temporal is shipped, both of those are simple numbers, so "both" would require us to define two names for each time-accepting API. |
It was somewhat orthogonal: regardless of what guidance we go with wrt points-in-time vs offsets-from-now (which I suspect somewhat depends on the use case, but I agree offsets-from-now is more commonly needed), these APIs should accept both |
I think another point in favor of "points in time" not mentioned here yet is the favorability for how its read after being set, and its format consistency with read/write. This is relevant to Storage Buckets and Cookie Store API that isn't quite relevant to say I'd assume reading expiration as "points in time" (ex. |
This came up in WICG/storage-buckets#79, which is asking whether to have a
setExpires(Date.now() + offset)
or asetMaxAge(offset)
method. It seems like it'd be useful to write some general advice about whether to prefer interfaces that expect a point in time, or interfaces that expect an offset relative to now.In favor of offsets:
setExpires(offset)
is a plausible developer mistake. This might go away once Temporal is ready, if General principle around time measurement units/formats for various domains (JS, HTTP, HTML, etc)? #344 concludes that we should move new APIs toTemporal.Instant
andTemporal.Duration
instead of untyped numbers.setTimeout()
, but there are definitely examples of points in time, like cookie expiration times and the matchingCookieInit.expires
.In favor of points in time:
doIn(goalTime - Date.now())
, and each of those gets skewed by the amount of time between the call and when the method internally converts back to a point in time.I've probably missed several considerations on both sides.
The text was updated successfully, but these errors were encountered: