Module: CalendarDateSelect
- Defined in:
- lib/calendar_date_select.rb,
lib/calendar_date_select/calendar_date_select.rb
Defined Under Namespace
Modules: FormHelpers, IncludesHelper Classes: Railtie
Constant Summary
- Files =
[ '/public', '/public/javascripts/calendar_date_select', '/public/stylesheets/calendar_date_select', '/public/images/calendar_date_select', '/public/javascripts/calendar_date_select/locale' ]
- VERSION =
'1.16.2'- FORMATS =
{ :natural => { :date => "%B %d, %Y", :time => " %I:%M %p" }, :hyphen_ampm => { :date => "%Y-%m-%d", :time => " %I:%M %p", :javascript_include => "format_hyphen_ampm" }, :iso_date => { :date => "%Y-%m-%d", :time => " %H:%M", :javascript_include => "format_iso_date" }, :finnish => { :date => "%d.%m.%Y", :time => " %H:%M", :javascript_include => "format_finnish" }, :danish => { :date => "%d/%m/%Y", :time => " %H:%M", :javascript_include => "format_danish" }, :american => { :date => "%m/%d/%Y", :time => " %I:%M %p", :javascript_include => "format_american" }, :euro_24hr => { :date => "%d %B %Y", :time => " %H:%M", :javascript_include => "format_euro_24hr" }, :euro_24hr_ymd => { :date => "%Y.%m.%d", :time => " %H:%M", :javascript_include => "format_euro_24hr_ymd" }, :italian => { :date => "%d/%m/%Y", :time => " %H:%M", :javascript_include => "format_italian" }, :db => { :date => "%Y-%m-%d", :time => " %H:%M", :javascript_include => "format_db" } }
Class Method Summary (collapse)
- + (Object) date_format_string(time = false)
-
+ (Object) default_options
Returns the default_options hash.
-
+ (Object) format
Returns the options for the given format.
-
+ (Object) format=(format)
Set the format.
- + (Object) format_date(date)
- + (Object) format_time(value, options = {})
-
+ (Boolean) has_time?(value)
Detects the presence of time in a date, string.
-
+ (Object) image=(value)
Set the picker image.
Class Method Details
+ (Object) date_format_string(time = false)
92 93 94 |
# File 'lib/calendar_date_select/calendar_date_select.rb', line 92 def self.date_format_string(time = false) format[:date] + (time ? format[:time] : "") end |
+ (Object) default_options
Returns the default_options hash. These options are by default provided to every calendar_date_select control, unless otherwise overrided.
Example:
# At the bottom of config/environment.rb:
CalendarDateSelect..update(
:popup => "force",
:month_year => "label",
:image => "custom_calendar_picker.png"
)
65 66 67 |
# File 'lib/calendar_date_select/calendar_date_select.rb', line 65 def self. @calendar_date_select_default_options ||= { :image => "calendar_date_select/calendar.gif" } end |
+ (Object) format
Returns the options for the given format
Example:
CalendarDateSelect.format = :italian
puts CalendarDateSelect.format[:date]
=> "%d/%m/%Y"
80 81 82 |
# File 'lib/calendar_date_select/calendar_date_select.rb', line 80 def self.format @calendar_date_select_format ||= FORMATS[:natural] end |
+ (Object) format=(format)
Set the format. To see a list of available formats, CalendarDateSelect::FORMATS.keys, or open lib/calendar_date_select/calendar_date_select.rb
(e.g. CalendarDateSelect.format = :italian)
87 88 89 90 |
# File 'lib/calendar_date_select/calendar_date_select.rb', line 87 def self.format=(format) raise "CalendarDateSelect: Unrecognized format specification: #{format}" unless FORMATS.has_key?(format) @calendar_date_select_format = FORMATS[format] end |
+ (Object) format_date(date)
96 97 98 99 100 101 102 |
# File 'lib/calendar_date_select/calendar_date_select.rb', line 96 def self.format_date(date) if date.is_a?(Date) date.strftime(date_format_string(false)) else date.strftime(date_format_string(true)) end end |
+ (Object) format_time(value, options = {})
104 105 106 107 108 109 110 111 |
# File 'lib/calendar_date_select/calendar_date_select.rb', line 104 def self.format_time(value, = {}) return value unless value.respond_to?("strftime") if [:time] format_date(value) else format_date(value.to_date) end end |
+ (Boolean) has_time?(value)
Detects the presence of time in a date, string
114 115 116 117 118 119 120 121 |
# File 'lib/calendar_date_select/calendar_date_select.rb', line 114 def self.has_time?(value) case value when DateTime, Time then true when Date then false else /[0-9]:[0-9]{2}/.match(value.to_s) ? true : false end end |
+ (Object) image=(value)
Set the picker image. Provide the image url the same way you would provide it to image_tag
70 71 72 |
# File 'lib/calendar_date_select/calendar_date_select.rb', line 70 def self.image=(value) [:image] = value end |