[#1421] Move same_hour / same_minute to typed champ

This commit is contained in:
Frederic Merizen 2018-06-15 14:18:10 +02:00 committed by Pierre de La Morinerie
parent 41734092b2
commit 6af27a7190
2 changed files with 12 additions and 17 deletions

View file

@ -32,27 +32,10 @@ class Champ < ApplicationRecord
!private?
end
def same_hour?(num)
same_date? num, '%H'
end
def same_minute?(num)
same_date? num, '%M'
end
def mandatory_and_blank?
mandatory? && value.blank?
end
def same_date?(num, compare)
if type_champ == 'datetime' && value.present?
if value.to_datetime.strftime(compare) == num
return true
end
end
false
end
def self.regions
JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.pluck("nom")
end

View file

@ -1,8 +1,20 @@
class Champs::DatetimeChamp < Champ
before_save :format_before_save
def same_hour?(num)
same_date?(num, '%H')
end
def same_minute?(num)
same_date?(num, '%M')
end
private
def same_date?(num, compare)
return value.present? && value.to_datetime.strftime(compare) == num
end
def format_before_save
if (value =~ /=>/).present?
self.value =