forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a86c14
commit e70f68f
Showing
4 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module ActionView | ||
module Helpers | ||
module Tags | ||
class DateSelect < Base #:nodoc: | ||
def initialize(object_name, method_name, template_object, options, html_options) | ||
@html_options = html_options | ||
|
||
super(object_name, method_name, template_object, options) | ||
end | ||
|
||
def render | ||
error_wrapping(datetime_selector(@options, @html_options).select_date.html_safe) | ||
end | ||
|
||
private | ||
|
||
def datetime_selector(options, html_options) | ||
datetime = value(object) || default_datetime(options) | ||
@auto_index ||= nil | ||
|
||
options = options.dup | ||
options[:field_name] = @method_name | ||
options[:include_position] = true | ||
options[:prefix] ||= @object_name | ||
options[:index] = @auto_index if @auto_index && !options.has_key?(:index) | ||
|
||
DateTimeSelector.new(datetime, options, html_options) | ||
end | ||
|
||
def default_datetime(options) | ||
return if options[:include_blank] || options[:prompt] | ||
|
||
case options[:default] | ||
when nil | ||
Time.current | ||
when Date, Time | ||
options[:default] | ||
else | ||
default = options[:default].dup | ||
|
||
# Rename :minute and :second to :min and :sec | ||
default[:min] ||= default[:minute] | ||
default[:sec] ||= default[:second] | ||
|
||
time = Time.current | ||
|
||
[:year, :month, :day, :hour, :min, :sec].each do |key| | ||
default[key] ||= time.send(key) | ||
end | ||
|
||
Time.utc_time( | ||
default[:year], default[:month], default[:day], | ||
default[:hour], default[:min], default[:sec] | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |