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

[feature] Calendar function handles formats only arg #3666

Merged
merged 5 commits into from Apr 25, 2020

Conversation

josephjaniga
Copy link
Contributor

Found the issue ticket #3658, thought it looked like a nice place to start for my first PR on GitHub. Made the recommended changes to overload the calendar function and added a unit test to the suite to cover my use case.

Corrected the formatting on calendarjs unit test file

Corrected autoformatting
@icambron
Copy link
Member

icambron commented Jan 9, 2017

This looks good to me

@@ -14,6 +15,12 @@ export function getCalendarFormat(myMoment, now) {
}

export function calendar (time, formats) {
// #3658 - Adding overload to the calendar function in order to allow:
Copy link
Contributor

Choose a reason for hiding this comment

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

You can say in a comment above the if along the line of accept format only, but don't include the PR/issue number, there is git blame for that.

Copy link
Contributor

@ichernev ichernev left a comment

Choose a reason for hiding this comment

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

LGTM

@josephjaniga
Copy link
Contributor Author

Got a commit in this morning, cleaned up that comment.

@ichernev
Copy link
Contributor

ichernev commented Mar 2, 2017

Merged in a2df2a3

@ichernev ichernev changed the title Calendar Function - Single Parameter Formats Overload [feature] Calendar function handles formats only arg Mar 2, 2017
@ichernev ichernev closed this Mar 2, 2017
ichernev added a commit that referenced this pull request Mar 2, 2017
[feature] Calendar function handles formats only arg
@ichernev
Copy link
Contributor

@josephjaniga the code doesn't take into account that time argument can be any moment input, which includes objects. Also it doesn't take into account formats being a function.

To implement this properly (if at all) you need to do key-testing to figure out if its moment-input or formats object, and also allow for functions. Also avoid using typeof whenever possible, we have a bunch of utility functions that try to do a better job.

I have to revert this if these are not addressed, otherwise we make the API much worse and edge-casey.

@josephjaniga
Copy link
Contributor Author

I can take a look at this and get it sorted, looking through the docs for those utility functions you mentioned.

@ichernev
Copy link
Contributor

Well, it just needs to work in all cases, not some of them. The current code doesn't work if formats is a function, or you pass an object for moment construction as sole first arg (in which case it will be mis-interpret as a format). http://momentjs.com/docs/#/parsing/object/

ichernev added a commit that referenced this pull request Mar 18, 2017
…formats"

This reverts commit a2df2a3, reversing
changes made to a52400e.
fbonzon pushed a commit to fbonzon/moment that referenced this pull request Oct 28, 2017
…rload-formats"

This reverts commit a2df2a3, reversing
changes made to a52400e.
@marwahaha
Copy link
Member

@josephjaniga - thanks for the contribution. In order for us to merge this, you have to address @ichernev 's changes.

@josephjaniga
Copy link
Contributor Author

Sorry I've been on quite a bit of a hiatus. I am going to bring this one back from the dead. I've re-read everything relevant from the past year, merged down the missed commits, checked the other issues and PRs to make sure this is still a desired feature.

I've added some utilities to help checking for input types and have all of the use cases working. Just finishing up on a few final unit tests. Fixing to add about 10 more to the suite.

Will update here once that is done. I didn't see anything about updating the docs - can someone point me in the right direction?

…endar functionality to properly identify time and formats inputs. added a bunch of unit tests
@josephjaniga
Copy link
Contributor Author

Finished my tests, triple checked to make sure I didn't include any new ES6 habits in there and made sure everything is passing locally. Pushed up to CI for final judgement.

@josephjaniga
Copy link
Contributor Author

@marwahaha Looks like everything passed. 😈 Let me know how it looks and I'll look to see what to do about those docs

@marwahaha marwahaha removed this from the 2.18.0 milestone Apr 11, 2018
@josephjaniga
Copy link
Contributor Author

Just following up, let me know if there is anything I can do to help keep this moving

@ichernev ichernev merged commit 8eb71ae into moment:develop Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants