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

Just one pipe? #4

Closed
HeathNaylor opened this issue Dec 24, 2015 · 13 comments
Closed

Just one pipe? #4

HeathNaylor opened this issue Dec 24, 2015 · 13 comments

Comments

@HeathNaylor
Copy link

Is there only the time ago pipe right now? Does this need contributions?

@urish
Copy link
Owner

urish commented Dec 24, 2015

Yes, only time ago at the moment. Contributions are always appreciated!

Are there any other pipes that you need?

@HeathNaylor
Copy link
Author

I guess I would need to know the intended scope of this package. If would this completely wrap around moment and use pipes for things like formatting or is it intended to be used for more edge case manipulations?

@urish
Copy link
Owner

urish commented Dec 28, 2015

Summarizing some of the leanings from angular-moment, it seems like formatting and timezone related functions are also valuable.

I always like to see if a specific feature is valuable to some users before developing it, so user needs greatly shape the set of features in the library.

That's also why I asked whether there is something particular that you need...

@HeathNaylor
Copy link
Author

Formatting was the one I was looking for specifically.

@urish
Copy link
Owner

urish commented Dec 28, 2015

Something like {{myDate | amDateFormat:'MM.DD.YYYY HH:mm:ss'} ?

@HeathNaylor
Copy link
Author

Yea, that would work. This brings up interesting questions about the use of moment in angular. Would we be using the pipe system to generate moment objects that we then send into other moment pipes or would we simple use javascript native date objects and only use moment for display of the native date objects?

I am needing to take today's date and set it to the beginning of the day. This would be easy with a angular pip of {{myDate | amStartOf:'day'}} but I would need the then start a counter every second to get the HH:mm:ss output I am looking for and then pass that into {{myMomentDate | amDateFormat:'HH:mm:ss}}.

The alternative is to use js native date and just do:

var start = new Date();
start.setHours(0,0,0,0);

{{start | amDateFormat:'HH:mm:ss'}}

How do you envision moment being used within a more complex date oriented application?

@urish
Copy link
Owner

urish commented Dec 28, 2015

This is a good question. Based on my experience from angular-moment, a set of composable pipes can make a lot of sense.

In general, we have 3 types of pipes there:

  1. Convert arbitrary value into a moment(). e.g. parsing a moment from a given string, like amParse does.
  2. Manipulate an existing moment() object and return a new one, e.g. adding or subtracting time.
  3. Converting a moment() to user readable format. amTimeAgo, amDateFormat and amCalendar come into mind.

I think we can start by implementing amDateFormat. In any case, all of the methods can supporting getting a native Date object as input.

Thoughts?

@HeathNaylor
Copy link
Author

I am good with starting with just native Date objects for the time being. Moving forward should we have all of the methods support both native Date objects and Moment objects or should we have specific methods for Moment objects and different methods for Date objects. Seems to me that amTimeAgo should work off both Date and Moment objects.

@urish
Copy link
Owner

urish commented Dec 29, 2015

Yes, that makes sense to me. If you can help with contributing amDateFormat (+ relevant unit tests) that will be awesome!

@HeathNaylor
Copy link
Author

I have already started on that and will do more tonight. Forgive my lack of experience, I am new to Angular 2. Can you only use Pipes from within the component template (HTML) or is it possible to use them from within the component class itself?

@urish
Copy link
Owner

urish commented Dec 30, 2015

Questions are always welcome :)

Pipes are intended to be used from template. Nothing is stopping you from creating an instance of the class directly within Javascript and call the methods (that's what we do in the unit-tests), though, in this case, you can simply call moment methods directly inside your Component class - there is no need to go through the pipe. Does this make sense to you?

@HeathNaylor
Copy link
Author

Makes sense to me. Would we then need to import moment into any component that intends to use it? Moving further conversation of this into a gitter room for now unless you want to keep the log here. https://gitter.im/HeathNaylor/angular2-moment

@urish
Copy link
Owner

urish commented Jan 12, 2016

So we already have a amCalendar pipe (#6) :-)

@urish urish closed this as completed Jan 13, 2016
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

No branches or pull requests

2 participants