README.md in datetime_picker_input-4.0.0 vs README.md in datetime_picker_input-4.17.37

- old
+ new

@@ -45,10 +45,46 @@ ```slim = simple_form_for Event.new do |f| f.input :when, as: :date_time_picker ``` +By default (without config), when you select a value from the DateTime picker, the format of the value +defaults to `YYYY-MM-DD HH:mm:ss Z`, i.e. `2015-10-25 14:33:02 +0800`. + +This ensures that, out of the box, this value (with Time Zone) would be passed on to the Rails backend +and be saved as a DateTime value with the *correct Time Zone*. + +Beneath the hood, Moment.js is used to parse and format value on the DateTime picker. +For other valid formats, please refer to [their Docs](http://momentjs.com/docs/#/displaying/). + +#### Warning! + +However, if you do change the format (like in the Customized Options example), +then you will need to implement your attribute setter and getter in Rails backend +to save and display the value correctly in your desired Time Zone. + +One way to do this is to implement an `around_filter` on your controllers like so: + +```ruby +class AppointmentsController < ApplicationController + around_action :use_current_timezone + + # .. your controller code + + def use_current_timezone(&block) + Time.use_zone(current_user.timezone, &block) + end +end +``` + +This uses your `user`'s Time Zone, so that the DateTime gets stored and will be displayed as expected (from the user's perspective). + +We are also assuming that, in this example, the `current_user` has set a custom Time Zone, +otherwise, you should just use the gem's default. + +Times are hard.. + ### Customized Options ```slim = f.input :when, as: :date_time_picker, input_html: { data: @@ -68,10 +104,21 @@ For example: - `dayViewHeaderFormat` to `date_day_view_header_format` - `minDate` to `date_min_date` +### Date Picker Only + +```slim += f.input :when, as: :date_time_picker, input_html: \ + { data: \ + { \ + date_format: "YYYY-MM-DD", \ + } \ + } +``` + ## Customization To [customize the input field](https://github.com/plataformatec/simple_form/wiki/Adding-custom-input-components), you can copy `datetime_picker_input.rb` from the gem to your app by using the generator included in `datetime_picker_input`. Simple do: @@ -95,20 +142,21 @@ Any bug fix release of this gem will have a 4th decimal added, e.g. 4.0.0.1, 4.0.0.2. ## Contributing -1. Fork it ( https://github.com/jollygoodcode/datetime_picker_input/fork ) -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Add some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create a new Pull Request +Please see the [CONTRIBUTING.md](/CONTRIBUTING.md) file. ## Credits -A huge THANK YOU to all our [contributors] (https://github.com/jollygoodcode/datetime_picker_input/graphs/contributors)! :heart: +A huge THANK YOU to all our [contributors](https://github.com/jollygoodcode/datetime_picker_input/graphs/contributors)! :heart: -This project is maintained by [Jolly Good Code](http://www.jollygoodcode.com). - ## License -MIT License. See [LICENSE](LICENSE) for details. +Please see the [LICENSE.md](/LICENSE.md) file. + +## Maintained by Jolly Good Code + +[![Jolly Good Code](https://cloud.githubusercontent.com/assets/1000669/9362336/72f9c406-46d2-11e5-94de-5060e83fcf83.jpg)](http://www.jollygoodcode.com) + +We specialise in Agile practices and Ruby, and we love contributing to open source. +[Speak to us](http://www.jollygoodcode.com/#get-in-touch) about your next big idea, or [check out our projects](http://www.jollygoodcode.com/open-source).