diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index b784c4f2d..c0fade776 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -180,7 +180,9 @@ class TimeEntry < ApplicationRecord
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
if spent_on && spent_on_changed? && user
+ max_days_for_past = [Setting.timelog_max_days_for_past.to_i, 0].max
errors.add :base, I18n.t(:error_spent_on_future_date) if !Setting.timelog_accept_future_dates? && (spent_on > user.today)
+ errors.add :base, I18n.t(:error_spent_on_past_date, :max_days => max_days_for_past) if max_days_for_past < (user.today - spent_on)
end
end
diff --git a/app/views/settings/_timelog.html.erb b/app/views/settings/_timelog.html.erb
index c6efd966d..831ab9ac1 100644
--- a/app/views/settings/_timelog.html.erb
+++ b/app/views/settings/_timelog.html.erb
@@ -9,6 +9,8 @@
<%= setting_check_box :timelog_accept_0_hours %>
<%= setting_check_box :timelog_accept_future_dates %>
+
+<%= setting_text_field :timelog_max_days_for_past, :size => 6 %>