Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add timezone selector in select_datetime form.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
Octocat-spinner-32 install.rb
README
TimezoneExtension
=================

Add timezone selector in select_datetime form.

Following options are added to select_datetime method to display timezone selector.

  :include_timezone
      if set to true, display timezone selector.
  :timezone_type
      Specify timezone display form. The default is 'short'.
        'short' : shortname(UTC, JST, etc.).
        'long'  : longname (Hawaii, Guam, Tokyo, etc.)
        'offset': available offsets.
  :timezone
      Set selected timezone instead of the default, which is dependent on
      time_zone configuration in "config/environment.rb".
  :timezone_sort_by_name
      Sort options by names insted of offsets.

Install
=======

./script/plugin install git://github.com/hs/timezone_extension.git

How to use
==========

== View

* get full datetime selector form:
  <% form_for(@timer) do |f| %>
      :
    <%= f.datetime_select :label, { :include_seconds => true, :include_timezone => true } %>
      :
  <% end %>
 or
  <%= datetime_select "datetime", "label", { :include_seconds => true, :include_timezone => true } %>

* timezone tag:
  <%= select_timezone %>

* to set id/name attributes in timezone tag:
  <%= select_timezone :prefix =>"datetime", :field_name => "label(7i)" %>

== Controller

This plugin also appends two methods in ActionController:

get_multiparameter_attributes(object_params, name):
    Get the array from multiparameter form.

get_multiparamete_time(object_parame, name):
    Get the Time object from datetime_select form.

For example, if you accept a request like:
   params => {
       datetime => {
           label(1i) => "2010", label(2i) => "1", label(3i) => "1",
           label(4i) => "0", label(5i) => "0", label(6i) => "0",
           label(7i) => "+0900" 
       }
   }

You can get the array of params[:datetime][:label*]:
   get_multiparameter_attributes(params[:datetime], "label")
   #=> [ 2010, 1, 1, 0, 0, 0, 900 ]

or Time object:
   get_multiparameter_time(params[:datetime], "label")
   #=> Fri, 01 Jan 2010 00:00:00 JST +09:00 (if Time.zone == 'Tokyo')

The get_multiparameter_attributes() recognize 'i' and 'f' suffix and convert them to integer and float.
Otherwize, a parameter remains in string. See tests for detail.

---
Copyright (c) 2010 Hideki SAKAMOTO, released under the MIT license
Something went wrong with that request. Please try again.