0
내 앱은 병가/휴가를 계산하기위한 것입니다. 주석 처리 된 부분은 휴가 기간을 추적하는 데 사용했지만 주말은 제외하지 않았습니다. 나는이 대답 (Counting days excluding weekends)을 읽었고 실제로 그것을 내 모델에 적용하려고 시도했지만, 지금 내 지속 시간 방정식은 내가 넣은 데이터에 관계없이 "0"으로 돌아오고 있습니다.기간에서 주말 제외
class Furlough < ActiveRecord::Base
attr_accessible :duration, :note, :date_from, :date_to, :description, :employee_id
belongs_to :employee
validates_presence_of :date_from, :date_to, :employee_id, :description
# def duration
# (date_to - date_from).to_i
# end
def duration
only_weekdays(date_to..(date_from))
end
protected
def only_weekdays(range)
range.select { |d| (1..5).include?(d.wday) }.size
end
end
감사합니다.
당신을 축복. 다른 답변에는 "weekdays_in_date_range (self.due_date .. (Date.today))"구문이 있습니다. Date.today는 내 모델에있는 것과 같은 고정 변수가 아니기 때문에? – Alaric
번호 불필요한 괄호 쌍을 원하는만큼 추가하십시오. :-) –
하하, 잘 알고있다 : D – Alaric