Class: ActionView::Helpers::DateTimeSelector
- Inherits:
-
Object
- Object
- ActionView::Helpers::DateTimeSelector
- Extended by:
- ActiveSupport::Memoizable
- Includes:
- TagHelper
- Defined in:
- lib/action_view/helpers/date_helper.rb
Overview
:nodoc:
Constant Summary collapse
- DEFAULT_PREFIX =
'date'.freeze
- POSITION =
{ :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }.freeze
- AMPM_TRANSLATION =
Hash[ [[0, "12 AM"], [1, "01 AM"], [2, "02 AM"], [3, "03 AM"], [4, "04 AM"], [5, "05 AM"], [6, "06 AM"], [7, "07 AM"], [8, "08 AM"], [9, "09 AM"], [10, "10 AM"], [11, "11 AM"], [12, "12 PM"], [13, "01 PM"], [14, "02 PM"], [15, "03 PM"], [16, "04 PM"], [17, "05 PM"], [18, "06 PM"], [19, "07 PM"], [20, "08 PM"], [21, "09 PM"], [22, "10 PM"], [23, "11 PM"]] ].freeze
Constants included from TagHelper
Instance Method Summary collapse
-
#initialize(datetime, options = {}, html_options = {}) ⇒ DateTimeSelector
constructor
A new instance of DateTimeSelector.
- #select_date ⇒ Object
- #select_datetime ⇒ Object
- #select_day ⇒ Object
- #select_hour ⇒ Object
- #select_minute ⇒ Object
- #select_month ⇒ Object
- #select_second ⇒ Object
- #select_time ⇒ Object
- #select_year ⇒ Object
Methods included from TagHelper
#cdata_section, #content_tag, #escape_once, #tag
Methods included from CaptureHelper
#capture, #content_for, #content_for?, #flush_output_buffer, #provide, #with_output_buffer
Constructor Details
#initialize(datetime, options = {}, html_options = {}) ⇒ DateTimeSelector
Returns a new instance of DateTimeSelector.
641 642 643 644 645 646 647 |
# File 'lib/action_view/helpers/date_helper.rb', line 641 def initialize(datetime, = {}, = {}) @options = .dup @html_options = .dup @datetime = datetime @options[:datetime_separator] ||= ' — ' @options[:time_separator] ||= ' : ' end |
Instance Method Details
#select_date ⇒ Object
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'lib/action_view/helpers/date_helper.rb', line 674 def select_date order = date_order.dup @options[:discard_hour] = true @options[:discard_minute] = true @options[:discard_second] = true @options[:discard_year] ||= true unless order.include?(:year) @options[:discard_month] ||= true unless order.include?(:month) @options[:discard_day] ||= true if @options[:discard_month] || !order.include?(:day) # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are # valid (otherwise it could be 31 and February wouldn't be a valid date) if @datetime && @options[:discard_day] && !@options[:discard_month] @datetime = @datetime.change(:day => 1) end [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) } build_selects_from_types(order) end |
#select_datetime ⇒ Object
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
# File 'lib/action_view/helpers/date_helper.rb', line 649 def select_datetime order = date_order.dup order -= [:hour, :minute, :second] @options[:discard_year] ||= true unless order.include?(:year) @options[:discard_month] ||= true unless order.include?(:month) @options[:discard_day] ||= true if @options[:discard_month] || !order.include?(:day) @options[:discard_minute] ||= true if @options[:discard_hour] @options[:discard_second] ||= true unless @options[:include_seconds] && !@options[:discard_minute] # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are # valid (otherwise it could be 31 and February wouldn't be a valid date) if @datetime && @options[:discard_day] && !@options[:discard_month] @datetime = @datetime.change(:day => 1) end if @options[:tag] && @options[:ignore_date] select_time else [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) } order += [:hour, :minute, :second] unless @options[:discard_hour] build_selects_from_types(order) end end |
#select_day ⇒ Object
736 737 738 739 740 741 742 |
# File 'lib/action_view/helpers/date_helper.rb', line 736 def select_day if @options[:use_hidden] || @options[:discard_day] build_hidden(:day, day) else (:day, day, :start => 1, :end => 31, :leading_zeros => false) end end |
#select_hour ⇒ Object
728 729 730 731 732 733 734 |
# File 'lib/action_view/helpers/date_helper.rb', line 728 def select_hour if @options[:use_hidden] || @options[:discard_hour] build_hidden(:hour, hour) else (:hour, hour, :end => 23, :ampm => @options[:ampm]) end end |
#select_minute ⇒ Object
720 721 722 723 724 725 726 |
# File 'lib/action_view/helpers/date_helper.rb', line 720 def select_minute if @options[:use_hidden] || @options[:discard_minute] build_hidden(:minute, min) else (:minute, min, :step => @options[:minute_step]) end end |
#select_month ⇒ Object
744 745 746 747 748 749 750 751 752 753 754 755 756 |
# File 'lib/action_view/helpers/date_helper.rb', line 744 def select_month if @options[:use_hidden] || @options[:discard_month] build_hidden(:month, month) else = [] 1.upto(12) do |month_number| = { :value => month_number } [:selected] = "selected" if month == month_number << content_tag(:option, month_name(month_number), ) + "\n" end build_select(:month, .join) end end |
#select_second ⇒ Object
712 713 714 715 716 717 718 |
# File 'lib/action_view/helpers/date_helper.rb', line 712 def select_second if @options[:use_hidden] || @options[:discard_second] build_hidden(:second, sec) if @options[:include_seconds] else (:second, sec) end end |
#select_time ⇒ Object
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
# File 'lib/action_view/helpers/date_helper.rb', line 696 def select_time order = [] @options[:discard_month] = true @options[:discard_year] = true @options[:discard_day] = true @options[:discard_second] ||= true unless @options[:include_seconds] order += [:year, :month, :day] unless @options[:ignore_date] order += [:hour, :minute] order << :second if @options[:include_seconds] build_selects_from_types(order) end |
#select_year ⇒ Object
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
# File 'lib/action_view/helpers/date_helper.rb', line 758 def select_year if !@datetime || @datetime == 0 val = '' middle_year = Date.today.year else val = middle_year = year end if @options[:use_hidden] || @options[:discard_year] build_hidden(:year, val) else = {} [:start] = @options[:start_year] || middle_year - 5 [:end] = @options[:end_year] || middle_year + 5 [:step] = [:start] < [:end] ? 1 : -1 [:leading_zeros] = false (:year, val, ) end end |