Comments (6)
My position is:
format()
is a low level API- diffing against
now
, or whatever their anchoring value is, seems to be trivial and does not require any extra data, can be done by users before calling format()
from proposal-intl-relative-time.
Unfortunately, I don't think that this is an acceptable consensus for us.
@jswalden in the review of my patch for SM said:
If execution is slow enough -- maybe the OS pages in another process to run for awhile or something -- this test can fail. (And so for all the others, with progressively less likelihood.)
It seems to me that RTF needs to have a mode of operation that takes *two* time arguments. One for the presumed current time, and one for the historical time being talked about. It seems fine for the default to be to the current moment, but there needs to be a way to override that. (For a real-world use case, consider a web-based version of Oregon Trail, that displays a journal of things that have happened to you, and wants to say that -- as of some particular time in the game -- eight days prior you tried to ford the river and your oxen died.)
Spec change/spec issue, please come back after you've addressed it there and then in a new patch. :-)
Originally, my position was that an optional "root" for now would be enough, like:
let rtf = new Intl.RelativeTimeformat('en', {
now: Date.now()
});
rtf.format(Date.now() - 1000);
but the longer I think about how people will use it, and what are the traps we set up for them, the more I realize that by attempting to reduce the cognitive load and let them "just pass the date" we actually set them for failure for two reasons:
- I believe that most UIs that will use it will do more than just display a string. They may alter the UI depending on the delta, or have a special
now
string.
In that case, asking the user to take a Date.now
to add the delta and pass it for us, so that we substract Date.now
again, seems like a bad API design.
- By removing the need to pass
now
we remove the opportunity for the user to realize that their delta is against somenow
. That's disguising something that should not be disguised because it actually affects the UI.
If the user is using react, to build a view, that he then passes from server side to client-side for display, then realizing that there will be time between executing the call to RTF, calculating the value, and then before the screen will be displayed, is actually important for the quality of the product.
And users generally, for good reasons, are not taught to think about the time between when they call a function and when it is computed and when the output is displayed. So in this case, I'd say we should avoid creating a space for a bug that might be very had to find.
Thus, my proposal is to just take delta in milliseconds as an argument to format
.
from proposal-intl-relative-time.
@caridy can correct me if I'm wrong, but taking the delta in milliseconds as the argument for rtf.format
was the direction we were inclined to as well when we talked about it days ago.
PS: Note you can't use the below, because considering we wanted to pass now
in the API, this should happen when calling the formatter (i.e., rtf.format
), not when instantiating it. Note you can create rtf
and then call rtf.format
later.
let rtf = new Intl.RelativeTimeformat('en', {
now: Date.now()
});
from proposal-intl-relative-time.
@caridy can correct me if I'm wrong, but taking the delta in milliseconds as the argument for rtf.format was the direction we were inclined to as well when we talked about it days ago.
Another point we discussed is: taking delta in ms, what should happen if developer passes a date
as input: should we type cast it into a number? That would result in an unexpected result and we were considering throwing an exception in that case... Thoughts?
from proposal-intl-relative-time.
Yup, let's throw an exception. Date casted to number as delta ms is probably never what the dev wanted to do.
from proposal-intl-relative-time.
Thus, my proposal is to just take delta in milliseconds as an argument to format.
That's precisely my position @zbraniecki. As I mentioned before, doing the delta calculation in user-land is trivial, they can do it. By removing the now and the date from the picture, we can clean the API considerable.
from proposal-intl-relative-time.
Related Issues (20)
- Docs(MDN) : Intl.RelativeTimeFormat HOT 9
- Update status on README
- Handle cut-off logic / distance with a given Date HOT 5
- Accept BigInt in format/formatToParts HOT 2
- Ambiguous Polyfills section in docs HOT 2
- Add an option to remove the prefix HOT 2
- It would be nice to document the expected placeables in the pattern. HOT 5
- request New API for format relative time from now HOT 5
- Review @@toStringTag value HOT 1
- "an optional argument value" HOT 1
- Remove references to InitializedIntlObject HOT 3
- Create options objects with null proto HOT 1
- Question: why is minimumIntegerDigits set to 2? HOT 6
- Question: What about other NumberFormat options? HOT 2
- resolvedOptions does not need undefined check
- isFinite() does not seem to be formally defined HOT 1
- Review handling of "narrow" style HOT 6
- Incorrect "yesterday" examples HOT 6
- PartitionRelativeTimePattern accepts non-time values HOT 1
- Allow to modify the numbering system through "nu"? HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-intl-relative-time.