Class: CalendarDateSelect

Inherits:
Object
  • Object
show all
Defined in:
lib/includes_helper.rb,
lib/calendar_date_select.rb

Defined Under Namespace

Modules: FormHelper, IncludesHelper

Constant Summary collapse

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"
  },
  :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"
  }
}
@@image =
"calendar_date_select/calendar.gif"
@@format =
FORMATS[:natural]

Class Method Summary collapse

Class Method Details

.date_format_string(time = false) ⇒ Object



65
66
67
# File 'lib/calendar_date_select.rb', line 65

def date_format_string(time=false)
  @@format[:date] + ( time ? @@format[:time] : "" )
end

.format=(format) ⇒ Object



56
57
58
59
# File 'lib/calendar_date_select.rb', line 56

def format=(format)
  raise "CalendarDateSelect: Unrecognized format specification: #{format}" unless FORMATS.has_key?(format)
  @@format = FORMATS[format]
end

.format_date(date) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/calendar_date_select.rb', line 69

def format_date(date)
  if Date===date
    date.strftime(date_format_string(false))
  else
    date.strftime(date_format_string(true))
  end
end

.has_time?(value) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/calendar_date_select.rb', line 77

def has_time?(value)
  /[0-9]:[0-9]{2}/.match(value.to_s)
end

.javascript_format_includeObject



61
62
63
# File 'lib/calendar_date_select.rb', line 61

def javascript_format_include
  @@format[:javascript_include] && "calendar_date_select/#{@@format[:javascript_include]}"
end