module MultiparameterDateTime

Constants

DEFAULT_DATE_FORMAT
DEFAULT_TIME_FORMAT
VALID_DATE_FORMAT
VALID_MILITARY_TIME_FORMAT
VALID_STANDARD_TIME_FORMAT
VERSION

Public Class Methods

date_format() click to toggle source
# File lib/multiparameter_date_time.rb, line 19
def self.date_format
  @@date_format ||= DEFAULT_DATE_FORMAT
end
time_format() click to toggle source
# File lib/multiparameter_date_time.rb, line 23
def self.time_format
  @@time_format ||= DEFAULT_TIME_FORMAT
end

Private Instance Methods

set_combined_datetime(name, date_string, time_string) click to toggle source
# File lib/multiparameter_date_time.rb, line 112
def set_combined_datetime(name, date_string, time_string)
  if date_string =~ MultiparameterDateTime::VALID_DATE_FORMAT && (time_string =~ MultiparameterDateTime::VALID_STANDARD_TIME_FORMAT || time_string =~ VALID_MILITARY_TIME_FORMAT)
    begin
      formatted_date_string = date_string
      if MultiparameterDateTime.date_string_formatter.present?
        formatted_date_string = MultiparameterDateTime.date_string_formatter.format(date_string)
      end

      Date.parse(formatted_date_string)
      write_attribute_for_multiparameter_date_time(
        name, Time.zone.parse("#{formatted_date_string} #{time_string}")
      )
    rescue ArgumentError
      write_attribute_for_multiparameter_date_time(name, :incomplete)
    end

  elsif date_string.blank? && time_string.blank?
    write_attribute_for_multiparameter_date_time(name, nil)
  else
    write_attribute_for_multiparameter_date_time(name, :incomplete)
  end
end
write_attribute_for_multiparameter_date_time(attribute_name, value) click to toggle source
# File lib/multiparameter_date_time.rb, line 135
def write_attribute_for_multiparameter_date_time(attribute_name, value)
  write_attribute(attribute_name, value)
rescue NoMethodError
  instance_variable_set("@#{attribute_name}", value)
end