{"id":15642911,"url":"https://github.com/excid3/combined_time_select","last_synced_at":"2025-04-09T15:09:08.271Z","repository":{"id":2097833,"uuid":"3038648","full_name":"excid3/combined_time_select","owner":"excid3","description":"A Rails time_select like Google Calendar with combined hour and minute time_select","archived":false,"fork":false,"pushed_at":"2020-06-26T15:24:22.000Z","size":14,"stargazers_count":64,"open_issues_count":7,"forks_count":22,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T15:09:03.899Z","etag":null,"topics":["hour","minutes","parse","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/excid3.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-12-23T05:49:18.000Z","updated_at":"2025-03-21T13:31:56.000Z","dependencies_parsed_at":"2022-09-07T16:40:20.003Z","dependency_job_id":null,"html_url":"https://github.com/excid3/combined_time_select","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excid3%2Fcombined_time_select","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excid3%2Fcombined_time_select/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excid3%2Fcombined_time_select/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excid3%2Fcombined_time_select/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/excid3","download_url":"https://codeload.github.com/excid3/combined_time_select/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055282,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hour","minutes","parse","rails","ruby"],"created_at":"2024-10-03T11:58:05.249Z","updated_at":"2025-04-09T15:09:08.236Z","avatar_url":"https://github.com/excid3.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Combined Time Select\n====================\n\nCompatible with Rails 5+\n\nWritten by [Chris Oliver](http://excid3.com) [@excid3](https://twitter.com/excid3).\n\nThis is a small gem for creating Google Calendar style 12 hour AM/PM\ntime_select fields for Rails. It's based off of [simple_time_select](https://github.com/tamoyal/simple_time_select) by tamoyal.\n\n![combined_time_select](http://f.cl.ly/items/1945331M3W1h0f1K3I2v/Screen%20Shot%202011-12-23%20at%2012.08.37%20AM.png)\n\n![combined_time_select](http://f.cl.ly/items/0H1x3a0S3m3E1U020s2m/Screen%20Shot%202011-12-23%20at%2012.09.00%20AM.png)\n\nInstallation\n------------\n\nJust add this into your Gemfile followed by a bundle install:\n\n    gem \"combined_time_select\", \"~\u003e 2.0.0\"\n\nUsage\n-----\n\nHere we have a model called Event with the start_time attribute that we\nwill be using with combined_time_select.\n\nBecause Rails time_select fields submit separate values, there is some\noverhead on the controller side when we combine the fields into one. We\ncan't rely on Rails to parse the input into a valid time anymore.\n\nIn the view you can do the following:\n\n    \u003c%= f.time_select :start_time,\n      :combined =\u003e true,\n      :default =\u003e Time.now.change(:hour =\u003e 11, :min =\u003e 30),\n      :minute_interval =\u003e 15,\n      :time_separator =\u003e \"\",\n      :start_hour =\u003e 10,\n      :start_minute =\u003e 30,\n      :end_hour =\u003e 14,\n      :end_minute =\u003e 30\n    %\u003e\n\nThis will create a combined time select starting at 10:30 AM and going till\n2:30 PM with 15 minute intervals with a default of 11:30 AM. This will set the\nvalue for the start_time attribute on the object this form was created\nfor.\n\nBecause `combined_time_select` overrides the time_select method to provide you the combined time fields, there is no need to designate a method when using libraries such as Formtastic.  You will, however, need to disable the built in hour and minute labels by indicating `:labels =\u003e false` (though you can still give your individual field a label with `:label =\u003e \"Label Name\"`) and to add in the am/pm designation for a 12 hour clock by indicating `:ampm =\u003e true`.\n\nYou can also pass in HTML options as a second hash argument to add attributes like data directly to the html.\n\n```erb\n\u003c%= form.time_select :time_start, # :time_start here is the datetime object\n  {\n    combined: true, \n    minute_interval: 30, \n    ampm: true, \n    time_separator: \"\", \n    end_hour: 23, \n    include_blank: true\n  }, # options\n  {  \n    data: { input: \"true\" }\n  } # html_options\n%\u003e\n```\n\nOn the controller side, we need to parse this attribute before we create\na new object. combined_time_select provides a nice method for this\ncalled parse_time_select!. You can use this in your create action just\nbefore you initialize the new model:\n\n    def create\n      params[:event].parse_time_select! :start_time\n      @event = Event.new params[:event]\n    end\n\n    def update\n      params[:event].parse_time_select! :start_time\n      @event = Event.find(params[:event])\n      if @event.update_attributes params[:event]\n        ...\n      end\n    end\n\nAnd voila! You're all set.\n\nIf you would like to include a date with your time_select, you can use `date_select` with the same paramter name and the fields will be combined with the time.\n\n    \u003c%= form.date_select :event_start %\u003e\n    \u003c%= form.time_select :event_start, combined: true %\u003e\n\nBehind The Scenes\n-----------------\n\nWhen the form gets submitted we will recieve a params hash like so:\n\n    {\"utf8\"=\u003e\"✓\", \"event\"=\u003e{\"start_time(5i)\"=\u003e\"10:00:00\"}, \"commit\"=\u003e\"Save changes\"}\n\nA normal time_select wil use start_time(4i) for the hours and\nstart_time(5i) for the minutes. The parse_time_select! will take all the\nstart_time(Xi) fields, parse them into a Time object and set the\nparams[:start_time] attribute to this object. The result after a\nparse_time_select!(attribute) looks like this:\n\n    {\"utf8\"=\u003e\"✓\", \"event\"=\u003e{\"start_time\"=\u003eFri, 23 Dec 2011 10:00:00 UTC +00:00}, \"commit\"=\u003e\"Save changes\"}\n\nThis allows you to also seamlessly use a date_select field in\ncombination with combined_time_select.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexcid3%2Fcombined_time_select","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexcid3%2Fcombined_time_select","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexcid3%2Fcombined_time_select/lists"}