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

Update the documentation regarding the relative date keywords, and rename them to reflect their purpose better

Dombi Attila8f13c1bc2d96
diff --git a/app/models/day.rb b/app/models/day.rb
index 89e7d0609e2..a154f31199d 100644
--- a/app/models/day.rb
+++ b/app/models/day.rb
@@ -80,7 +80,7 @@ class Day < ApplicationRecord
end
def self.last_working
- # Look up only from 8 days ago, because the Setting.working_days must have at least 1 working day.
+ # Look up only from 8 days ago, because the Setting.working_days must have at least 1 working weekday.
from_range(from: 8.days.ago, to: Time.zone.yesterday).where(working: true).last
end
diff --git a/app/models/timestamp.rb b/app/models/timestamp.rb
index 2b29f7cc868..0a7ad308bf9 100644
--- a/app/models/timestamp.rb
+++ b/app/models/timestamp.rb
@@ -33,7 +33,7 @@ class Timestamp
class TimestampParser
DATE_KEYWORD_REGEX =
- /^(?:yesterday|lastWorkingDay|lastWeek|lastMonth)@(?:([0-1]?[0-9]|2[0-3]):[0-5]?[0-9])$/
+ /^(?:oneDayAgo|lastWorkingDay|oneWeekAgo|oneMonthAgo)@(?:([0-1]?[0-9]|2[0-3]):[0-5]?[0-9])$/
def initialize(string)
@original_string = string
@@ -161,10 +161,10 @@ class Timestamp
relative_date_keyword, time_part = @timestamp_string.split('@')
date = case relative_date_keyword
- when 'yesterday' then 1.day.ago
+ when 'oneDayAgo' then 1.day.ago
when 'lastWorkingDay' then Day.last_working.date || 1.day.ago
- when 'lastWeek' then 1.week.ago
- when 'lastMonth' then 1.month.ago
+ when 'oneWeekAgo' then 1.week.ago
+ when 'oneMonthAgo' then 1.month.ago
end
Time.zone.parse(time_part, date)
diff --git a/docs/api/apiv3/paths/project_queries_default.yml b/docs/api/apiv3/paths/project_queries_default.yml
index a5bed27f8a9..c3f31ef2b5d 100644
--- a/docs/api/apiv3/paths/project_queries_default.yml
+++ b/docs/api/apiv3/paths/project_queries_default.yml
@@ -75,9 +75,12 @@ get:
default: false
type: boolean
- name: timestamps
- description: Indicates the timestamps to filter by when showing changed attributes
- on work packages. Values can be either ISO8601 durations or dates.
- example: '2023-01-01,P-1Y,PT0S'
+ description: >
+ Indicates the timestamps to filter by when showing changed attributes
+ on work packages. Values can be either ISO8601 dates, ISO8601 durations and the
+ following relative date keywords: "oneDayAgo@HH:MM", "lastWorkingDay@HH:MM", "oneWeekAgo@HH:MM",
+ "oneMonthAgo@HH:MM". The "HH:MM" part represents the zero paded hours and minutes.
+ example: '2023-01-01,P-1Y,PT0S,lastWorkingDay@12:00'
in: query
required: false
schema:
diff --git a/docs/api/apiv3/paths/queries_default.yml b/docs/api/apiv3/paths/queries_default.yml
index d904ede3add..89810f2403a 100644
--- a/docs/api/apiv3/paths/queries_default.yml
+++ b/docs/api/apiv3/paths/queries_default.yml
@@ -67,9 +67,12 @@ get:
default: false
type: boolean
- name: timestamps
- description: Indicates the timestamps to filter by when showing changed attributes
- on work packages. Values can be either ISO8601 durations or dates.
- example: '2023-01-01,P-1Y,PT0S'
+ description: >
+ Indicates the timestamps to filter by when showing changed attributes
+ on work packages. Values can be either ISO8601 dates, ISO8601 durations and the
+ following relative date keywords: "oneDayAgo@HH:MM", "lastWorkingDay@HH:MM", "oneWeekAgo@HH:MM",
+ "oneMonthAgo@HH:MM". The "HH:MM" part represents the zero paded hours and minutes.
+ example: '2023-01-01,P-1Y,PT0S,lastWorkingDay@12:00'
in: query
required: false
schema:
diff --git a/docs/api/apiv3/paths/query.yml b/docs/api/apiv3/paths/query.yml
index d70cf02000b..8be667eddd8 100644
--- a/docs/api/apiv3/paths/query.yml
+++ b/docs/api/apiv3/paths/query.yml
@@ -135,9 +135,12 @@ get:
default: false
type: boolean
- name: timestamps
- description: Indicates the timestamps to filter by when showing changed attributes
- on work packages. Values can be either ISO8601 durations or dates.
- example: '2023-01-01,P-1Y,PT0S'
+ description: >
+ Indicates the timestamps to filter by when showing changed attributes
+ on work packages. Values can be either ISO8601 dates, ISO8601 durations and the
+ following relative date keywords: "oneDayAgo@HH:MM", "lastWorkingDay@HH:MM", "oneWeekAgo@HH:MM",
+ "oneMonthAgo@HH:MM". The "HH:MM" part represents the zero paded hours and minutes.
+ example: '2023-01-01,P-1Y,PT0S,lastWorkingDay@12:00'
in: query
required: false
schema:
diff --git a/docs/api/apiv3/paths/work_package.yml b/docs/api/apiv3/paths/work_package.yml
index dc0bc9150fe..74bf42926ab 100644
--- a/docs/api/apiv3/paths/work_package.yml
+++ b/docs/api/apiv3/paths/work_package.yml
@@ -73,7 +73,9 @@ get:
example: 1
- description: |-
In order to perform a [baseline comparison](/docs/api/baseline-comparisons) of the work-package attributes, you may
- provide one or several timestamps in ISO-8601 format as comma-separated list. The timestamps may be absolute or relative.
+ provide one or several timestamps in ISO-8601 format as comma-separated list. The timestamps may be absolute or relative,
+ such as ISO8601 dates, ISO8601 durations and the following relative date keywords: "oneDayAgo@HH:MM", "lastWorkingDay@HH:MM",
+ "oneWeekAgo@HH:MM", "oneMonthAgo@HH:MM". The "HH:MM" part represents the zero paded hours and minutes.
Usually, the first timestamp is the baseline date, the last timestamp is the current date.
in: query
name: timestamps
diff --git a/docs/api/apiv3/paths/work_packages.yml b/docs/api/apiv3/paths/work_packages.yml
index 0db720b2e02..25f95cb2000 100644
--- a/docs/api/apiv3/paths/work_packages.yml
+++ b/docs/api/apiv3/paths/work_packages.yml
@@ -126,8 +126,10 @@ get:
type: string
- description: |-
In order to perform a [baseline comparison](/docs/api/baseline-comparisons), you may provide one or several timestamps
- in ISO-8601 format as comma-separated list. The timestamps may be absolute or relative. Usually, the first timestamp
- is the baseline date, the last timestamp is the current date.
+ in ISO-8601 format as comma-separated list. The timestamps may be absolute or relative,
+ such as ISO8601 dates, ISO8601 durations and the following relative date keywords: "oneDayAgo@HH:MM", "lastWorkingDay@HH:MM",
+ "oneWeekAgo@HH:MM", "oneMonthAgo@HH:MM". The "HH:MM" part represents the zero paded hours and minutes.
+ Usually, the first timestamp is the baseline date, the last timestamp is the current date.
example: '2022-01-01T00:00:00Z,PT0S'
in: query
name: timestamps
diff --git a/docs/api/apiv3/tags/baseline_comparisons.yml b/docs/api/apiv3/tags/baseline_comparisons.yml
index fd018e333aa..701e1a86229 100644
--- a/docs/api/apiv3/tags/baseline_comparisons.yml
+++ b/docs/api/apiv3/tags/baseline_comparisons.yml
@@ -22,6 +22,7 @@ description: |-
```
Each timestamp should be given as an [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) string, either an absolute date and time with timezone, e.g. `"2022-01-01T00:00:00Z"`, or a relative timestamp utilizing the [ISO-8601-Duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) format, e.g. `"P-1Y"`, which is composed of an initial `"P"` for "Period", and a duration. `"P-1Y"` is interpreted as the relative timestamp "1 year ago".
+ Furthermore, a set of predefined relative date keywords can also be passed for the timestamps: `"oneDayAgo@HH:MM", "lastWorkingDay@HH:MM", "oneWeekAgo@HH:MM", "oneMonthAgo@HH:MM"`. The `"HH:MM"` part represents the zero paded hours and minutes, e.g. `"oneMonthAgo@21:20"`.
Several timestamps should be passed as comma-separated list of these ISO-8601 strings to the `timestamps` parameter, e.g. `"2022-01-01T00:00:00Z,PT0S"`.
diff --git a/docs/api/apiv3/tags/basic_objects.yml b/docs/api/apiv3/tags/basic_objects.yml
index 70d729ca0ff..5a523ab51db 100644
--- a/docs/api/apiv3/tags/basic_objects.yml
+++ b/docs/api/apiv3/tags/basic_objects.yml
@@ -237,6 +237,8 @@ description: |-
* `Timestamp` - refers to an ISO 8601 combined date and time, e.g. "2014-05-21T13:37:00Z" or to an ISO 8601 duration, e.g. "P1DT18H".
The following shorthand values are also being parsed as duration: "1d", "1w", "1m", "1y", "1y-2m", "-2y".
+ It can also refer the following relative date keywords: "oneDayAgo@HH:MM", "lastWorkingDay@HH:MM", "oneWeekAgo@HH:MM", "oneMonthAgo@HH:MM".
+ The "HH:MM" part represents the zero paded hours and minutes of the relative date e.g. "oneDayAgo@00:00", "lastWorkingDay@21:00".
## Colors
diff --git a/spec/models/timestamp_spec.rb b/spec/models/timestamp_spec.rb
index 32a82539263..223ac5137d2 100644
--- a/spec/models/timestamp_spec.rb
+++ b/spec/models/timestamp_spec.rb
@@ -177,8 +177,8 @@ describe Timestamp do
end
describe "when providing relative date keywords" do
- describe "yesterday@12:00" do
- subject { described_class.parse("yesterday@12:00") }
+ describe "oneDayAgo@12:00" do
+ subject { described_class.parse("oneDayAgo@12:00") }
it "returns a Timestamp representing the yesterday at 12:00 pm" do
expect(subject).to be_a described_class
@@ -206,8 +206,8 @@ describe Timestamp do
end
end
- describe "lastWeek@12:00" do
- subject { described_class.parse("lastWeek@12:00") }
+ describe "oneWeekAgo@12:00" do
+ subject { described_class.parse("oneWeekAgo@12:00") }
it "returns a Timestamp representing the last week at 12:00 pm" do
expect(subject).to be_a described_class
@@ -218,8 +218,8 @@ describe Timestamp do
end
end
- describe "lastMonth@12:00" do
- subject { described_class.parse("lastMonth@12:00") }
+ describe "oneMonthAgo@12:00" do
+ subject { described_class.parse("oneMonthAgo@12:00") }
it "returns a Timestamp representing the last month at 12:00 pm" do
expect(subject).to be_a described_class
@@ -248,7 +248,7 @@ describe Timestamp do
end
describe "when providing something invalid with relative date keywords" do
- subject { described_class.parse("yesterday@") }
+ subject { described_class.parse("oneDayAgo@") }
it "raises an error" do
expect { subject }.to raise_error ArgumentError
@@ -256,7 +256,7 @@ describe Timestamp do
end
describe "when providing something invalid with relative date keywords#2" do
- subject { described_class.parse("yesterday@11:22:asd") }
+ subject { described_class.parse("oneDayAgo@11:22:asd") }
it "raises an error" do
expect { subject }.to raise_error ArgumentError
@@ -345,7 +345,7 @@ describe Timestamp do
end
describe "for a timestamp as a date keyword representing a point in time relative to now" do
- let(:timestamp) { described_class.new("lastWeek@12:00") }
+ let(:timestamp) { described_class.new("oneWeekAgo@12:00") }
it "returns true" do
expect(subject).to be true
@@ -374,10 +374,10 @@ describe Timestamp do
end
describe "for a timestamp as a date keyword representing a point in time relative to now" do
- let(:timestamp) { described_class.new('yesterday@12:00') }
+ let(:timestamp) { described_class.new('oneDayAgo@12:00') }
it "returns an relative date keyword" do
- expect(subject).to eq 'yesterday@12:00'
+ expect(subject).to eq 'oneDayAgo@12:00'
end
end
end
diff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rb
index f12c237c08a..b0b16a1a361 100644
--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb
@@ -774,7 +774,7 @@ describe 'API v3 Work package resource',
end
context 'when the timestamps are relative date keywords' do
- let(:timestamps) { [Timestamp.parse('lastWeek@11:00'), Timestamp.parse('lastWorkingDay@12:00')] }
+ let(:timestamps) { [Timestamp.parse('oneWeekAgo@11:00'), Timestamp.parse('lastWorkingDay@12:00')] }
it 'has an embedded link to the baseline work package' do
expect(subject.body)
@@ -801,7 +801,7 @@ describe 'API v3 Work package resource',
it 'has the relative timestamps within the _meta timestamps' do
expect(subject.body)
- .to be_json_eql('lastWeek@11:00'.to_json)
+ .to be_json_eql('oneWeekAgo@11:00'.to_json)
.at_path('_embedded/elements/0/_embedded/attributesByTimestamp/0/_meta/timestamp')
expect(subject.body)
.to be_json_eql('lastWorkingDay@12:00'.to_json)
@@ -820,7 +820,7 @@ describe 'API v3 Work package resource',
describe "timestamp" do
it 'has the baseline timestamp, which is the first timestmap' do
expect(subject.body)
- .to be_json_eql('lastWeek@11:00'.to_json)
+ .to be_json_eql('oneWeekAgo@11:00'.to_json)
.at_path('_embedded/elements/0/_embedded/attributesByTimestamp/0/_meta/timestamp')
end
end
@@ -930,7 +930,7 @@ describe 'API v3 Work package resource',
end
context "with relative date keyword timestamps" do
- let(:timestamps) { [Timestamp.parse('lastWeek@12:00'), Timestamp.now] }
+ let(:timestamps) { [Timestamp.parse('oneWeekAgo@12:00'), Timestamp.now] }
let(:created_at) { '2015-01-01' }
describe "when the filter becomes outdated" do
@@ -954,10 +954,10 @@ describe 'API v3 Work package resource',
let(:search_term) { 'original' }
it 'has the relative timestamps within the _meta timestamps' do
- expect(timestamps.first.to_s).to eq('lastWeek@12:00')
+ expect(timestamps.first.to_s).to eq('oneWeekAgo@12:00')
expect(timestamps.first).to be_relative
expect(subject.body)
- .to be_json_eql('lastWeek@12:00'.to_json)
+ .to be_json_eql('oneWeekAgo@12:00'.to_json)
.at_path('_embedded/elements/0/_embedded/attributesByTimestamp/0/_meta/timestamp')
expect(subject.body)
.to be_json_eql('PT0S'.to_json)
diff --git a/spec/requests/api/v3/work_packages/show_resource_spec.rb b/spec/requests/api/v3/work_packages/show_resource_spec.rb
index fb42cff78f9..8d1adc5aaac 100644
--- a/spec/requests/api/v3/work_packages/show_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb
@@ -420,7 +420,7 @@ describe 'API v3 Work package resource',
end
context 'when the timestamps are relative date keywords' do
- let(:timestamps) { [Timestamp.new('lastWeek@12:00'), Timestamp.now] }
+ let(:timestamps) { [Timestamp.new('oneWeekAgo@12:00'), Timestamp.now] }
it 'has an embedded link to the baseline work package' do
expect(subject)
@@ -441,7 +441,7 @@ describe 'API v3 Work package resource',
describe 'timestamp' do
it 'has the relative timestamps' do
expect(subject)
- .to be_json_eql('lastWeek@12:00'.to_json)
+ .to be_json_eql('oneWeekAgo@12:00'.to_json)
.at_path('_embedded/attributesByTimestamp/0/_meta/timestamp')
expect(subject)
.to be_json_eql('PT0S'.to_json)
@@ -455,7 +455,7 @@ describe 'API v3 Work package resource',
before { login_as current_user }
context "with relative timestamps" do
- let(:timestamps) { [Timestamp.parse("yesterday@00:00"), Timestamp.now] }
+ let(:timestamps) { [Timestamp.parse("oneDayAgo@00:00"), Timestamp.now] }
let(:created_at) { '2015-01-01' }
describe "attributesByTimestamp" do
@@ -490,7 +490,7 @@ describe 'API v3 Work package resource',
describe "_meta" do
describe "exists" do
- let(:timestamps) { [Timestamp.parse("yesterday@00:00")] }
+ let(:timestamps) { [Timestamp.parse("oneDayAgo@00:00")] }
let(:created_at) { 25.hours.ago }
it "is not cached" do
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 8070ec75e0a..22eb0b71588 100644
--- a/spec/services/api/v3/parse_query_params_service_spec.rb
+++ b/spec/services/api/v3/parse_query_params_service_spec.rb
@@ -342,13 +342,13 @@ describe API::V3::ParseQueryParamsService,
end
it_behaves_like 'transforms' do
- let(:params) { { timestamps: "lastMonth@11:00, now" } }
- let(:expected) { { timestamps: [Timestamp.parse("lastMonth@11:00"), Timestamp.parse("P-0Y")] } }
+ let(:params) { { timestamps: "oneMonthAgo@11:00, now" } }
+ let(:expected) { { timestamps: [Timestamp.parse("oneMonthAgo@11:00"), Timestamp.parse("P-0Y")] } }
end
it_behaves_like 'transforms' do
- let(:params) { { timestamps: "lastMonth@11:00, lastWeek@12:00" } }
- let(:expected) { { timestamps: [Timestamp.parse("lastMonth@11:00"), Timestamp.parse("lastWeek@12:00")] } }
+ let(:params) { { timestamps: "oneMonthAgo@11:00, oneWeekAgo@12:00" } }
+ let(:expected) { { timestamps: [Timestamp.parse("oneMonthAgo@11:00"), Timestamp.parse("oneWeekAgo@12:00")] } }
end
describe "for invalid parameters" do
diff --git a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb
index 8abd227a648..26e5cbe647f 100644
--- a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb
+++ b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb
@@ -236,7 +236,7 @@ describe API::V3::WorkPackageCollectionFromQueryService,
end
context 'when timestamps are given' do
- let(:timestamps) { [Timestamp.parse("P-1Y"), Timestamp.parse("lastWeek@12:00"), Timestamp.now] }
+ let(:timestamps) { [Timestamp.parse("P-1Y"), Timestamp.parse("oneWeekAgo@12:00"), Timestamp.now] }
let(:query) { build_stubbed(:query, timestamps:) }
it 'has the query timestamps' do
diff --git a/spec/services/update_query_from_params_service_spec.rb b/spec/services/update_query_from_params_service_spec.rb
index 03a77cbc558..d3f99c86ae6 100644
--- a/spec/services/update_query_from_params_service_spec.rb
+++ b/spec/services/update_query_from_params_service_spec.rb
@@ -195,7 +195,7 @@ describe UpdateQueryFromParamsService,
let(:timestamps) do
[
Timestamp.parse("2022-10-29T23:01:23Z"),
- Timestamp.parse("lastWeek@12:00"),
+ Timestamp.parse("oneWeekAgo@12:00"),
Timestamp.parse("PT0S")
]
end