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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
simplify timestamp handling in url query
ulferts8339975088a9
diff --git a/app/models/timestamp.rb b/app/models/timestamp.rbindex b5c37fc9589..ce0298474dc 100644--- a/app/models/timestamp.rb+++ b/app/models/timestamp.rb@@ -40,6 +40,8 @@ class Timestampenddef self.parse(iso8601_string)+ return iso8601_string if iso8601_string.is_a?(Timestamp)+iso8601_string.strip!iso8601_string = substitute_special_shortcut_values(iso8601_string)if iso8601_string.start_with? "P" # ISO8601 "Period"diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex 0a301e7b9b5..04da611f220 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -548,11 +548,7 @@ module APIenddef self.timestamps_to_param_value(timestamps)- timestamps = Timestamp.parse_multiple(timestamps) if timestamps.is_a? String- timestamps = [timestamps] if timestamps.is_a? Timestamp- if timestamps.present? and timestamps.is_a? Array and timestamps != [Timestamp.now]- timestamps.collect { |timestamp| timestamp.absolute.iso8601 }.join(",")- end+ Array(timestamps).map { |timestamp| Timestamp.parse(timestamp).absolute.iso8601 }.join(",")enddef self.path_for(path, filters: nil, sort_by: nil, group_by: nil, page_size: nil, offset: nil,diff --git a/spec/lib/api/v3/utilities/path_helper_spec.rb b/spec/lib/api/v3/utilities/path_helper_spec.rbindex b2f87ca8859..a1fadf1f73d 100644--- a/spec/lib/api/v3/utilities/path_helper_spec.rb+++ b/spec/lib/api/v3/utilities/path_helper_spec.rb@@ -642,4 +642,50 @@ describe API::V3::Utilities::PathHelper doendendend++ describe '.timestamps_to_param_value' do+ subject { helper.timestamps_to_param_value(timestamps) }++ context 'for a single relative iso8601 string' do+ let(:timestamps) { 'PT0S' }++ it 'returns the value as an absolute value in ISO8601 format' do+ Timecop.freeze(Time.current) do+ expect(subject)+ .to eql Time.current.iso8601+ end+ end+ end++ context 'for a single absolute iso8601 string' do+ let(:timestamps) { '2023-01-31T21:34:11Z' }++ it 'returns the value unchanged' do+ expect(subject)+ .to eql timestamps+ end+ end++ context 'for a single timestamp (NOW)' do+ let(:timestamps) { Timestamp.now }++ it 'returns the value unchanged' do+ Timecop.freeze(Time.current) do+ expect(subject)+ .to eql Time.current.iso8601+ end+ end+ end++ context 'for an array in different formats' do+ let(:timestamps) { ['2023-01-31T21:34:11Z', Timestamp.new('2022-04-30T21:34:11Z'), 'PT0S'] }++ it 'returns the value unchanged' do+ Timecop.freeze(Time.current) do+ expect(subject)+ .to eql "2023-01-31T21:34:11Z,2022-04-30T21:34:11Z,#{Time.current.iso8601}"+ end+ end+ end+ endenddiff --git a/spec/models/timestamp_spec.rb b/spec/models/timestamp_spec.rbindex cae668fc5c1..4c21999634a 100644--- a/spec/models/timestamp_spec.rb+++ b/spec/models/timestamp_spec.rb@@ -171,6 +171,16 @@ describe Timestamp doendendend++ describe 'when providing a Timestamp' do+ subject { described_class.parse(provided) }++ let(:provided) { described_class.new }++ it "returns the provided timestamp" do+ expect(subject).to eql provided+ end+ endenddescribe ".parse_multiple" do