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

Store the original string instead of the parsed one in the Timestamp class

Dombi Attilad340dde88416
diff --git a/app/models/timestamp.rb b/app/models/timestamp.rb
index fece7777dae..65609730208 100644
--- a/app/models/timestamp.rb
+++ b/app/models/timestamp.rb
@@ -83,7 +83,8 @@ class Timestamp
def parse(timestamp_string)
return timestamp_string if timestamp_string.is_a?(Timestamp)
- timestamp_string = TimestampParser.new(timestamp_string.strip).parse!
+ timestamp_string = timestamp_string.strip
+ TimestampParser.new(timestamp_string).parse!
new(timestamp_string)
end
diff --git a/spec/models/timestamp_spec.rb b/spec/models/timestamp_spec.rb
index e79908a816d..827b8c06751 100644
--- a/spec/models/timestamp_spec.rb
+++ b/spec/models/timestamp_spec.rb
@@ -100,14 +100,14 @@ describe Timestamp do
{
'PT1H' => 'PT1H',
- 'PT0001H' => 'PT1H',
- 'PT0009H' => 'PT9H',
+ 'PT0001H' => 'PT0001H',
+ 'PT0009H' => 'PT0009H',
'PT-1H' => 'PT-1H',
- '+PT1H' => 'PT1H',
- '-PT1H' => 'PT-1H',
- '-PT-1H' => 'PT1H',
+ '+PT1H' => '+PT1H',
+ '-PT1H' => '-PT1H',
+ '-PT-1H' => '-PT-1H',
' PT1H ' => 'PT1H',
- '-P1M-1DT1H-02M' => 'P-1M1DT-1H2M'
+ '-P1M-1DT1H-02M' => '-P1M-1DT1H-02M'
}.each do |input, expected|
it "parses #{input.inspect} into #{expected.inspect}" do
expect(described_class.parse(input).to_s).to eq(expected)
@@ -121,7 +121,7 @@ describe Timestamp do
it "returns a described_class representing that absolute time" do
expect(subject).to be_a described_class
expect(subject).to be_valid
- expect(subject.to_s).to eq "2022-10-29T21:55:58+00:00"
+ expect(subject.to_s).to eq "2022-10-29T21:55:58Z"
expect(subject.to_time).to eq Time.iso8601("2022-10-29T21:55:58+00:00")
expect(subject).not_to be_relative
end
@@ -144,7 +144,7 @@ describe Timestamp do
it "returns a described_class representing that absolute time" do
expect(subject).to be_a described_class
expect(subject).to be_valid
- expect(subject.to_s).to eq "2022-10-29T21:55:00+00:00"
+ expect(subject.to_s).to eq "2022-10-29T21:55Z"
expect(subject.to_time).to eq Time.iso8601("2022-10-29T21:55:00Z")
expect(subject).not_to be_relative
end
@@ -193,7 +193,7 @@ describe Timestamp do
it "returns a Timestamp representing that absolute time" do
expect(subject).to be_a described_class
expect(subject).to be_valid
- expect(subject.to_s).to eq "2022-01-01T00:00:00+00:00"
+ expect(subject.to_s).to eq "2022-01-01"
expect(subject.to_time).to eq Time.zone.parse("2022-01-01T00:00:00Z")
expect(subject).not_to be_relative
end
diff --git a/spec/services/api/v3/parse_query_params_service_spec.rb b/spec/services/api/v3/parse_query_params_service_spec.rb
index fff2319e74c..73201b71e9b 100644
--- a/spec/services/api/v3/parse_query_params_service_spec.rb
+++ b/spec/services/api/v3/parse_query_params_service_spec.rb
@@ -338,12 +338,12 @@ describe API::V3::ParseQueryParamsService,
it_behaves_like 'transforms' do
let(:params) { { timestamps: "-1y, now" } }
- let(:expected) { { timestamps: [Timestamp.new("P-1Y"), Timestamp.parse("P-0Y")] } }
+ let(:expected) { { timestamps: [Timestamp.new("P-1Y"), Timestamp.new("PT0S")] } }
end
it_behaves_like 'transforms' do
let(:params) { { timestamps: "oneMonthAgo@11:00+00:00, now" } }
- let(:expected) { { timestamps: [Timestamp.parse("oneMonthAgo@11:00+00:00"), Timestamp.parse("P-0Y")] } }
+ let(:expected) { { timestamps: [Timestamp.parse("oneMonthAgo@11:00+00:00"), Timestamp.new("PT0S")] } }
end
it_behaves_like 'transforms' do