Module: VesperDateTime

Defined in:
lib/vesper/framework/plugins/core-extensions.vpi/application/date_time.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/vesper/framework/plugins/core-extensions.vpi/application/date_time.rb', line 3

def self.included base
  base.extend ClassMethods
end

Instance Method Details

#display(format = :date) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vesper/framework/plugins/core-extensions.vpi/application/date_time.rb', line 13

def display format = :date
  case format
  when :date
    string = "%A %b %d, %Y"
  when :day
    string = "%b %d, %Y"
  when :day_with_time
    string = "%b %d, %Y at %I:%M%P"
  when :american_day
    string = "%m/%d/%y"
  else
    string = "%A %b %d, %Y"
  end
  self.strftime string
end

#to_fields(field) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vesper/framework/plugins/core-extensions.vpi/application/date_time.rb', line 29

def to_fields field
  date_field = ""
  
  date_field << "<select name='#{field}_month' id='#{field}_month'>"
  (1..12).each do |m|
    date_field << "<option value='#{m}' #{'selected' if m == self.strftime('%m').to_i}>#{m}</option>"
  end
  date_field << "</select>"
  
  date_field << "<select name='#{field}_day' id='#{field}_day'>"
  (1..31).each do |d|
    date_field << "<option value='#{d}' #{'selected' if d == self.strftime('%d').to_i}>#{d}</option>"
  end
  date_field << "</select>"
  
  date_field << "<select name='#{field}_year' id='#{field}_year'>"
  (2007..Chronic.parse('3 years from now').strftime('%Y').to_i).each do |y|
    date_field << "<option value='#{y}' #{'selected' if y == self.strftime('%Y').to_i}>#{y}</option>"
  end
  date_field << "</select>"
  
  date_field
end