excid3 / combined_time_select

A Rails time_select like Google Calendar with combined hour and minute time_select

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

24-Hour Military Time

acutemedical opened this issue · comments

We should have the option in time_select to use military time 00:00-23:59 instead of the standard AM/PM format. I'm thinking about monkey patching this, but it would probably be best if I worked on a PR unless you've already a way to do this quickly.

Using :ampm => false should yield a 24-hour/military time scope, but it doesn't work.

I don't think I have a way of doing that at the moment.

I'd love to see that too. 👍

Ok, I'll fork it and work on a PR that solves this problem. I may even write a test or two. (Surprise!)

If you get into some trouble with it, we might just want to rewrite the gem from scratch. It's probably easier to generate a select tag for both and then write a method in the controller to transform it to a Time. Seems like that would be a better solution than how this is currently designed.

I've actually considered rewriting the gem from scratch. I think there's a simpler way to parse datetime into a combined object. I may need some help with some of the "features" but the core functionality of combining date/time together I have something up my sleeve.

I'm open to it. Want to prototype something in a branch and we can see how to move forward?

Yes, I'd like that. I have a few different ideas on how to simplify the gem's codebase.

:shipit:

Send me a link to your branch when you've got a draft. I'm excited to see what you come up with!

Will do. I plan to work on this sometime this weekend when I'm back.

I still need to figure this out. I am working on an app where I need military time. Any thoughts on where I can start in the code?

@excid3 I totally forgot about this. I forked this into a branch and am going to refactor it to accept 24:00 format. As soon as I have it working, I'll make a PR against master. What would be the best way to test this? I can write some rspec or minitest but I'm thinking of just bootstrapping a simple rails app and browser/controller testing. Thoughts?

@excid3 after forking this branch and testing it out against different rails versions I got the 24:00 military time to work. Looks like this wasn't working in the original version which I was locked at. So I upgraded, and here's the code that gets it to work in 24:00/Military.

<%= f.date_select :due_date, order: [:month, :day, :year] %>
  <%= f.time_select :due_date,
              :combined => true,
              :default => Time.zone.now,
              :minute_interval => 15,
              :time_separator => "",
              :start_hour => 00,
              :end_hour => 23,
              :labels => false,
              :ampm => false %>

Looks like the labels and ampm options have to be set to false. You can close this issue.