-
Notifications
You must be signed in to change notification settings - Fork 603
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
Conversation
Thanks for your new PR.
Yeap, better having this PR to compare against master.
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.
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 |
Only support numbers as value parameter for the moment
bc6ef1b
to
cb79465
Compare
I've done this based on fix-391-relative-time now. Let me know what you think? |
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. |
There was a problem hiding this comment.
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 changeminWordOffset
tominimumWordOffset
andmax...
accordingly.
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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' ); |
There was a problem hiding this comment.
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" );
@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 ]; |
There was a problem hiding this comment.
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
@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
@mbirtwell thanks for your updates so far. |
@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 ( |
Ref #391
Another go at formatRelativeCount from #389.
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).