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

Add relative time formatting #395

Closed
wants to merge 15 commits into from

Conversation

mbirtwell
Copy link
Contributor

Ref #391

Another go at formatRelativeCount from #389.

  • It has the fix-205-format-duration branch merged in
  • It's in the duration module
  • I've renamed it to formatTimeOffset, which I think is a bit better (but naming is still hard).
  • It uses formatMessage and Globalize.plural rather than my hacky alternatives
  • I've included a skeleton implementation of the formatDuration function as per Support relative time #205 implemented using my formatTimeOffset method

Also I've created this as a pull request against master because otherwise the diff was massive and you couldn't really see what I'd done. I understand that you consider formatDuration to be the real goal here and so may chose to merge this in to fix-205-format-duration (or not at all - but I like to be optimistic).

@rxaviers
Copy link
Member

Thanks for your new PR.

Also I've created this as a pull request against master...

Yeap, better having this PR to compare against master.

  • It's in the duration module

Ok for now. Let's rename it "relative-time". If this module doesn't add too many bytes, it could live inside the existing date module.

  • It has the fix-205-format-duration branch merged in
  • I've renamed it to formatTimeOffset, which I think is a bit better (but naming is still hard).
  • It uses formatMessage and Globalize.plural rather than my hacky alternatives
  • I've included a skeleton implementation of the formatDuration function as per Support relative time #205 implemented using my formatTimeOffset method

Updates... I have updated our API according to what we discussed (#389 (comment)). I've closed #205 in favor of the clean #391. I've rebased my old fix-205-format-duration branch on top of up-to-date master, made the changes according to #391 and pushed it into a new branch called fix-391-relative-time.

Can you rebase your changes on top of fix-391-relative-time please? Use .formatRelativeTime() and relativeTimeFormatter() names instead of your custom-named .formatTimeOffset(). Note, you don't need to implement anything based on Date instances for now (if you don't want to). Keep your implementation based on (number, unit). We can add Date instance support in upcoming commits.

rxaviers and others added 2 commits February 16, 2015 12:23
Only support numbers as value parameter for the moment
@mbirtwell mbirtwell force-pushed the fix-205-format-duration branch from bc6ef1b to cb79465 Compare February 18, 2015 15:07
@mbirtwell
Copy link
Contributor Author

I've done this based on fix-391-relative-time now. Let me know what you think?

@rxaviers
Copy link
Member

Awesome. I've scanned through your code and saw you got the spirit. I will do a better review soon (couple of days).

A quick comment though, make sure you follow jQuery's style guide.

* - minWordOffset [Optional Number] The maximum offset when special offset words like
* yesterday and tomorrow will be looked for. Some languages provide several of these.
* default null -> use all available
* Set to 0 to not use any except today, now etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting option...

  • Does any other programming language have something similar?
  • Given Ecma-402 names are in the extensive form (e.g., minimumFractionDigits) and we're (kinda) following it where we can, it would be good to change minWordOffset to minimumWordOffset and max... accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why minWordOffset is here, but maxWordOffset is there. I recommend having the options descriptions in one place (there) and having here saying: "see .relativeTimeFormatter() for details"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was only meant to be maxWordOffset (minWordOffset was a typo).
I don't know of any other libraries which provide a similar option but I thought I had a use case which for suppressing the use of yesterday in favour of always using the x days ago form, but I changed my mind in the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright about minWordOffset. Thanks.

About maxWordOffset, I can easily think of a use case where "1 day ago" is preferred than yesterday. Although, I don't think of any use case where one wants yesterday, but not before yesterday. Do you have one?

@mbirtwell
Copy link
Contributor Author

Sorry one of my commits (from a week ago) was been created with my work email address. I've signed to CLA for that email address as well now.

@@ -91,4 +94,6 @@ require([
document.getElementById( "requirements" ).style.display = "none";
document.getElementById( "demo" ).style.display = "block";

document.getElementById( "relative-time").innerText = en.formatRelativeTime( -35, 'second' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need extra space and to replace ' for ":

- document.getElementById( "relative-time").innerText = en.formatRelativeTime( -35, 'second' );
+ document.getElementById( "relative-time" ).innerText = en.formatRelativeTime( -35, "second" );

@rxaviers
Copy link
Member

rxaviers commented Mar 5, 2015

@mbirtwell sorry for the delayed response. Thanks for the updates. I have added a couple of review comments.

*/
return function( value, numberFormatter, pluralGenerator, properties ) {

var relativeTime, message = properties[ "relative-type-" + value ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message = needs to go in its own line http://contribute.jquery.org/style-guide/js/#assignments

@rxaviers
Copy link
Member

rxaviers commented Mar 5, 2015

@mbirtwell it's looking great. Please, just let me know when you have updates.

Most interesting is removing an incorrect example and adding instance method example
@rxaviers
Copy link
Member

@mbirtwell thanks for your updates so far.

@rxaviers rxaviers changed the title Add a formatTimeOffset method Add relative time formatting Mar 26, 2015
@rxaviers
Copy link
Member

@mbirtwell, I went ahead and made the final fixes in a new commit.

I want to let you know I really appreciate your work here. Thanks and keep in touch. Your further contributions are welcome.

PS: Although CLA task has been marked as failing. I've checked it manually and it is correct (3/1/2015 8:47:57 Michael Birtwell michael.birtwell@starleaf.com I AGREE).

rxaviers added a commit that referenced this pull request Mar 26, 2015
@rxaviers rxaviers closed this in 655d821 Mar 26, 2015
rxaviers added a commit that referenced this pull request Mar 26, 2015
- Style updates.
- Add default CLDR validation.
- Minor edits.

Amends 47cbe1207a30ac8d3ba9b0ab3ef8a6107e2b421a
Ref #391
Ref #395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants