public
Rubygem
Description: A popular and flexible JavaScript DatePicker for RubyOnRails (and others)
Homepage: http://code.google.com/p/calendardateselect/
Clone URL: git://github.com/timcharper/calendar_date_select.git
Added date parse function which respects :format

This way it's possible to assign the string values directly
to ActiveRecord objects which hold date values. The attributes
have to be marked as such with the new method calendar_date_attributes
inside the model definition.
jonas (author)
Thu Oct 02 11:21:15 -0700 2008
timcharper (committer)
Wed Oct 08 00:36:29 -0700 2008
commit  306738dbc2a2b51fe0f1cc1f921393dc340027b5
tree    2d8576d49632c132cedb0d70f9e662ad7e80ebfa
parent  f9a2b690bed35e8ca058dd498751aa568fdd76b3
...
1
 
2
3
4
5
6
7
 
8
9
10
...
 
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1,10 +1,11 @@
0
-%w[calendar_date_select includes_helper].each { |file|
0
+%w[calendar_date_select includes_helper active_record_extension].each { |file|
0
   require File.join( File.dirname(__FILE__), "lib",file)
0
 }
0
 
0
 ActionView::Helpers::FormHelper.send(:include, CalendarDateSelect::FormHelper)
0
 ActionView::Base.send(:include, CalendarDateSelect::FormHelper)
0
 ActionView::Base.send(:include, CalendarDateSelect::IncludesHelper)
0
+ActiveRecord::Base.send(:extend, CalendarDateSelect::ActiveRecordExtension)
0
 
0
 # install files
0
 unless File.exists?(RAILS_ROOT + '/public/javascripts/calendar_date_select/calendar_date_select.js')
...
66
67
68
 
69
70
71
...
73
74
75
 
 
 
 
 
 
 
 
 
 
 
 
 
76
77
78
...
66
67
68
69
70
71
72
...
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
0
@@ -66,6 +66,7 @@ class CalendarDateSelect
0
       @@format[:date] + ( time ? @@format[:time] : "" )
0
     end
0
     
0
+ # formates a date with the specified format
0
     def format_date(date)
0
       if Date===date
0
         date.strftime(date_format_string(false))
0
@@ -73,6 +74,19 @@ class CalendarDateSelect
0
         date.strftime(date_format_string(true))
0
       end
0
     end
0
+
0
+ # parses a date string using the specified format
0
+ def parse_date(date)
0
+ if has_time?(date)
0
+ hash = ::Date._strptime(date, date_format_string(true))
0
+ return nil if hash.nil?
0
+ ::DateTime.new(*hash.values_at(:year, :mon, :mday, :hour, :min))
0
+ else
0
+ hash = ::Date._strptime(date, date_format_string(false))
0
+ return nil if hash.nil?
0
+ ::Date.new(*hash.values_at(:year, :mon, :mday))
0
+ end
0
+ end
0
     
0
     def has_time?(value)
0
       /[0-9]:[0-9]{2}/.match(value.to_s)

Comments