Giter Site home page Giter Site logo

Just one pipe? about ngx-moment HOT 13 CLOSED

urish avatar urish commented on July 22, 2024
Just one pipe?

from ngx-moment.

Comments (13)

urish avatar urish commented on July 22, 2024

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

Are there any other pipes that you need?

from ngx-moment.

HeathNaylor avatar HeathNaylor commented on July 22, 2024

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?

from ngx-moment.

urish avatar urish commented on July 22, 2024

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...

from ngx-moment.

HeathNaylor avatar HeathNaylor commented on July 22, 2024

Formatting was the one I was looking for specifically.

from ngx-moment.

urish avatar urish commented on July 22, 2024

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

from ngx-moment.

HeathNaylor avatar HeathNaylor commented on July 22, 2024

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?

from ngx-moment.

urish avatar urish commented on July 22, 2024

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?

from ngx-moment.

HeathNaylor avatar HeathNaylor commented on July 22, 2024

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.

from ngx-moment.

urish avatar urish commented on July 22, 2024

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

from ngx-moment.

HeathNaylor avatar HeathNaylor commented on July 22, 2024

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?

from ngx-moment.

urish avatar urish commented on July 22, 2024

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?

from ngx-moment.

HeathNaylor avatar HeathNaylor commented on July 22, 2024

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

from ngx-moment.

urish avatar urish commented on July 22, 2024

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

from ngx-moment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.