Patch #6450 ยป scvmc_redmine_668p1_custom_field_dates.diff
| app/models/custom_value.rb (working copy) | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class CustomValue < ActiveRecord::Base
|
||
|
include Redmine::I18n
|
||
|
|
||
|
belongs_to :custom_field
|
||
|
belongs_to :customized, :polymorphic => true
|
||
|
before_save :transform
|
||
|
def after_initialize
|
||
|
if new_record? && custom_field && (customized_type.blank? || (customized && customized.new_record?))
|
||
|
self.value ||= custom_field.default_value
|
||
| ... | ... | |
|
def to_s
|
||
|
value.to_s
|
||
|
end
|
||
|
|
||
|
|
||
|
protected
|
||
|
def validate
|
||
|
if value.blank?
|
||
| ... | ... | |
|
when 'float'
|
||
|
begin; Kernel.Float(value); rescue; errors.add(:value, :invalid) end
|
||
|
when 'date'
|
||
|
errors.add(:value, :not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/
|
||
|
errors.add(:value, :not_a_date) unless parse_user_date(value)
|
||
|
when 'list'
|
||
|
errors.add(:value, :inclusion) unless custom_field.possible_values.include?(value)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
private
|
||
|
def transform
|
||
|
self.value = parse_user_date(value) if custom_field.field_format == 'date'
|
||
|
end
|
||
|
end
|
||
| lib/redmine/i18n.rb (working copy) | ||
|---|---|---|
|
return nil unless date
|
||
|
Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format)
|
||
|
end
|
||
|
def parse_user_date(datestring)
|
||
|
return nil unless datestring
|
||
|
begin
|
||
|
if datestring =~ /^\d{4}-\d{2}-\d{2}$/
|
||
|
r = Date.strptime(datestring, '%F')
|
||
|
elsif
|
||
|
r = Setting.date_format.blank? ? Date.parse(datestring) : Date.strptime(datestring, Setting.date_format)
|
||
|
end
|
||
|
rescue
|
||
|
r = nil
|
||
|
end
|
||
|
return r
|
||
|
end
|
||
|
|
||
|
def format_time(time, include_date = true)
|
||
|
return nil unless time
|
||