Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

[Future] Add type option for numeric vs. text formatting #9

Closed
zbraniecki opened this issue Jan 16, 2017 · 15 comments
Closed

[Future] Add type option for numeric vs. text formatting #9

zbraniecki opened this issue Jan 16, 2017 · 15 comments

Comments

@zbraniecki
Copy link
Member

ICU provides two functions for formatting relative date: text and numeric - the difference is that in text mode it attempts to use human readable terms like yesterday and last week instead of numeric 1 day ago and 1 week ago.

I'd like to suggest adding this in form of type option:

let rtf = new Intl.RelativeTimeFormat('en-US', {
  type: 'text'
});
rtf.format(new Date() - 1000 * 60 * 60 * 24); // 'yesterday'


let rtf2 = new Intl.RelativeTimeFormat('en-US', {
  type: 'numeric'
});
rtf2.format(new Date() - 1000 * 60 * 60 * 24); // '1 day ago'

I'd suggest the text value to be the default.

@caridy
Copy link
Collaborator

caridy commented Mar 17, 2017

instead of type, should this be style and whatever is style today should be called something else? I'm bikeshedding on the names here because type sounds weird.

@littledan
Copy link
Member

Do we actually want the numeric style? When do you want to see "1 day ago", as opposed to always using text when it's available?

@rxaviers
Copy link
Member

cc @srl295 and @JCEmmons who could shed some light about the ICU design approach for allowing both forms...

@littledan
Copy link
Member

@caridy It's hard for me to see how we could use style when that's already in use for the size. We could call it something else, but nothing immediately comes to mind for me.

@caridy
Copy link
Collaborator

caridy commented Jun 27, 2017

It seems reasonable that we drop this feature for the v1, and maybe bringing it back if needed. We need a label for this.

@caridy caridy changed the title Add type option for numeric vs. text formatting [Future] Add type option for numeric vs. text formatting Jun 27, 2017
@zbraniecki
Copy link
Member Author

Do we actually want the numeric style? When do you want to see "1 day ago", as opposed to always using text when it's available?

I can see it being valuable for some technical UI for consistency between "1 month ago" and "2 months ago" etc.
But I also agree with @caridy that we can drop it from v1 and just make sure that our API can handle it later.

@srl295
Copy link
Member

srl295 commented Sep 7, 2017

the numeric form may fit better when it's along side other numbers, such as "The server caught fire: 3 days ago, 2 days ago, 1 day ago". where the text form may be better as a standalone singleton: "The server last caught fire: yesterday"

@zbraniecki
Copy link
Member Author

But I also agree with @caridy that we can drop it from v1 and just make sure that our API can handle it later.

I'm no longer sure if we can drop it from v1. We implemented the v0 spec in SpiderMonkey and are now trying to use it in Firefox UI with some bestFit algorithm.

Basically, the numeric approach is required for any naive operations that don't do timezone and time-delta calculations, while text form is only applicable if you're willing to write your bestFit algo to handle that.

Thus, I'm leaning toward either recommending we do numeric only in v1, or that we add the param to v1 with defaulting to numeric.

@zbraniecki
Copy link
Member Author

@rxaviers @littledan

@littledan
Copy link
Member

@zbraniecki I don't quite understand; do you have a bug thread somewhere that provides more context?

@zbraniecki
Copy link
Member Author

Yeah! It's basically rxaviers epoch vs date bestFit dillema - https://bugzilla.mozilla.org/show_bug.cgi?id=1407240

@rxaviers
Copy link
Member

rxaviers commented Nov 29, 2017

@zbraniecki Yeap, the ability to "disable the textual forms" (e.g., to disable "Yesterday" and get "1 day ago") could be useful given your use case and @srl295's comment above.

The "hardest part" to me here seems the options names:

  • numeric vs text: I understand that the "numeric" style will disable the Yesterday-like strings, but I think it wouldn't be perfectly clear to me if I was looking at this my first time why numeric has text in it like "day ago", and the fact that "text" and "numeric" styles are identical for most of the cases except -2, -1, 0, 1, and 2.
  • ICU returns "yesterday" for "absolute unit" and "1 day ago" for "relative unit"; I see their point, but the absolute unit vs. relative unit terminology doesn't sound great to me either.

Among the two, I still prefer the numeric vs. text. I'm wondering if we had additional choices...

@zbraniecki
Copy link
Member Author

@rxaviers we merged the numeric vs text. If you come up with better naming, file a new issue pls! :)

@rxaviers
Copy link
Member

rxaviers commented Dec 5, 2017

Sounds good. Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants