module TimeDateHelpers::DateHelpers
Public Instance Methods
convert_to_date(string)
click to toggle source
convert a string to a date (using Chronic, of course)
# File lib/time_date_helpers/date_helpers.rb, line 22 def convert_to_date(string) return nil if (string.nil? || string.class != String) tmp = Chronic.parse(string) tmp ? tmp.to_date : nil end
convert_to_datetime(string)
click to toggle source
convert a string to a datetime (Chronic's default)
# File lib/time_date_helpers/date_helpers.rb, line 29 def convert_to_datetime(string) return nil if (string.nil? || string.class != String) Chronic.parse(string) end
humanize_date(date, opt={})
click to toggle source
convert a date to human format of mm/dd/yyyy
# File lib/time_date_helpers/date_helpers.rb, line 4 def humanize_date(date, opt={}) # Set the default options options = {:style => :calendar} # Merge whatever options the user has selected with the defaults options.merge!(opt) # Make sure what is passed is legit return nil if date.nil? return nil unless date.class == Date || date.class == Time || date.class == DateTime if options[:style] == :calendar date.strftime("%m/%d/%Y") elsif options[:style] == :full date.day < 10 ? date.strftime("%B%e, %Y") : date.strftime("%B %e, %Y") else nil end end