From 978ab53d21bdf7be939bf82066dc3fd4bd7c5aba Mon Sep 17 00:00:00 2001 From: WizardOfOgz Date: Wed, 21 Oct 2015 11:59:54 -0500 Subject: [PATCH] Work around a Chronic bug --- lib/has_safe_dates/core_ext.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/has_safe_dates/core_ext.rb b/lib/has_safe_dates/core_ext.rb index 8be967c..d4e92f2 100644 --- a/lib/has_safe_dates/core_ext.rb +++ b/lib/has_safe_dates/core_ext.rb @@ -69,7 +69,9 @@ def read_date # Otherwise the original #read_date method is invoked. def read_time if ActiveRecord::Base.has_safe_fields_config[object.class.base_class] && ActiveRecord::Base.has_safe_fields_config[object.class.base_class][:fields].include?(name) - "#{ values.values_at(1,2,3).join("-")} #{ values.values_at(4,5).join(":") }" # Convert multiparameter parts into a Time string, e.g. "2011-4-23 12:34", return it, and allow CoreExt methods handle the result. + date = values.values_at(1,2,3).join("-") + time = values.values_at(4,5).map{ |digit| "%02i" % digit }.join(":") # Zero-pad the hour and minute values to work around a Chronic bug, see https://github.com/mojombo/chronic/issues/314 + "#{ date } #{ time }" # Convert multiparameter parts into a Time string, e.g. "2011-4-23 12:34", return it, and allow CoreExt methods handle the result. else super # has_safe_dates is not enabled for the current field, so invoke the super method (original #read_time method). end