Permalink
Browse files

Added automatic conversion of given dates from default local time for…

…mat to the format expected by the API, if I18n is defined and the date is not already in the required format
  • Loading branch information...
1 parent 90a1e2d commit d4b18ff682f9fb48a0a47ca5054322320f346b39 @RSpace RSpace committed Nov 29, 2011
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/podio/active_podio/base.rb
@@ -292,7 +292,13 @@ def define_date_accessor(name)
self[name.to_sym] = if value.is_a?(Date)
value.try(:to_s, :db)
else
- value.try(:to_s)
+ value = value.try(:to_s)
+ if defined?(I18n) && value.present? && !(value =~ /^\d{4}-\d{2}-\d{2}$/) # If we have I18n available, assume that we are in Rails and try to convert the string to a date to convert it to ISO 8601
+ value_as_date = Date.strptime(value, I18n.t('date.formats.default')) rescue nil
+ value_as_date.nil? ? value.try(:to_s) : value_as_date.try(:to_s, :db)
+ else
+ value
+ end
end
end
end

0 comments on commit d4b18ff

Please sign in to comment.