How to process time (hours and minutes)

I’ll have to process open/closes hours (like 8:30, 20:00, etc) and wonder what are existing and the best practices in Ember community. I found some add-ons:

But some have compatibility issues, some require some work to change the style, format, etc. I’ll have to exchange data with a Rails API, so in the backend there 2 existing solutions to format the input as we need:

Any other ideas ? Thank you.

Another resource is http://momentjs.com/, which works fine in ember apps. You can install ember-moment and it will take care of adding it to your build automatically.

Thank you for response. I already use ember-moment add-on but just for display formatted date/time values. I wonder what way to go in case when you need:

  • let User enter time values in a specified format (mask), like 8:00 or 18:30, for example.
  • display the entered previously time values for editing

It seems, if I’m not wrong, ember-moment main use is just to display time/date values in specified format. That’s why I was looking for add-ons to let Users enter time values.

You could also just roll your own component that relies on the native time input. Using an addon for time input feels a bit overkill (depending on your requirements).

The browser can take care of a lot of things for you natively (like validation). You could then use moment to transform the value into something your model needs.

1 Like

@mattmcmanus Thanks a lot, didn’t know this one :(, it seems like Safari still does not support it. I’ll take a try. Sure it is the most convenient solution and the most native I think.

Just tried {{input type="time" class="form-control" value=myTime}}, - woks like a charm :). I can get the entered value as hh:mm and will be able to transform it to whatever I want with one of the above gems (I think, to milliseconds, to store it as integer in a DB). Thank you very much, @mattmcmanus!

2 Likes