Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#60713] Ends after 'a specific date' dates are not inclusive (#17674)

Mir Bhatia573b9d5a437a
diff --git a/modules/meeting/app/models/recurring_meeting.rb b/modules/meeting/app/models/recurring_meeting.rb
index 092ebdc56a6..d7b565495b9 100644
--- a/modules/meeting/app/models/recurring_meeting.rb
+++ b/modules/meeting/app/models/recurring_meeting.rb
@@ -1,3 +1,33 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
class RecurringMeeting < ApplicationRecord
# Magical maximum of iterations
MAX_ITERATIONS = 1000
@@ -83,7 +113,7 @@ class RecurringMeeting < ApplicationRecord
end
def schedule
- @schedule ||= IceCube::Schedule.new(start_time, end_time: end_date).tap do |s|
+ @schedule ||= IceCube::Schedule.new(start_time, end_time: modified_end_date).tap do |s|
s.add_recurrence_rule count_rule(frequency_rule)
exclude_non_working_days(s) if frequency_working_days?
end
@@ -139,7 +169,7 @@ class RecurringMeeting < ApplicationRecord
def remaining_occurrences
if end_date.present?
- schedule.occurrences_between(Time.current, end_date)
+ schedule.occurrences_between(Time.current, modified_end_date)
else
schedule.remaining_occurrences(Time.current)
end
@@ -162,6 +192,11 @@ class RecurringMeeting < ApplicationRecord
@schedule = nil
end
+ # Because IceCube is exclusive by default for end_time for a schedule
+ def modified_end_date
+ @modified_end_date ||= end_date + 1.day
+ end
+
def end_date_constraints
return if end_date.nil?
@@ -202,7 +237,7 @@ class RecurringMeeting < ApplicationRecord
if end_after_iterations?
rule.count(iterations)
else
- rule.until(end_date.to_time(:utc))
+ rule.until(modified_end_date.to_time(:utc))
end
end
diff --git a/modules/meeting/spec/models/recurring_meeting_spec.rb b/modules/meeting/spec/models/recurring_meeting_spec.rb
index 5497bace6a7..a17dd52006b 100644
--- a/modules/meeting/spec/models/recurring_meeting_spec.rb
+++ b/modules/meeting/spec/models/recurring_meeting_spec.rb
@@ -118,7 +118,7 @@ RSpec.describe RecurringMeeting,
it "schedules daily", :aggregate_failures do
expect(subject.first_occurrence).to eq Time.zone.tomorrow + 10.hours
- expect(subject.last_occurrence).to eq Time.zone.tomorrow + 6.days + 10.hours
+ expect(subject.last_occurrence).to eq Time.zone.tomorrow + 7.days + 10.hours
occurrence_in_two_days = Time.zone.today + 2.days + 10.hours
Timecop.freeze(Time.zone.tomorrow + 11.hours) do
@@ -186,7 +186,7 @@ RSpec.describe RecurringMeeting,
it "schedules weekly", :aggregate_failures do
expect(subject.first_occurrence).to eq Time.zone.tomorrow + 10.hours
- expect(subject.last_occurrence).to eq Time.zone.tomorrow + 3.weeks + 10.hours
+ expect(subject.last_occurrence).to eq Time.zone.tomorrow + 4.weeks + 10.hours
following_occurrence = Time.zone.tomorrow + 7.days + 10.hours
Timecop.freeze(Time.zone.tomorrow + 11.hours) do
@@ -198,7 +198,8 @@ RSpec.describe RecurringMeeting,
Time.zone.tomorrow + 10.hours,
Time.zone.tomorrow + 7.days + 10.hours,
Time.zone.tomorrow + 14.days + 10.hours,
- Time.zone.tomorrow + 21.days + 10.hours
+ Time.zone.tomorrow + 21.days + 10.hours,
+ Time.zone.tomorrow + 28.days + 10.hours
]
Timecop.freeze(Time.zone.tomorrow + 5.weeks) do