mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: date-range tag for local dates (#15474)
New range tag for local dates with syntax like: ``` [date-range from=2022-01-06T13:00 to=2022-01-08 timezone=Australia/Sydney] ``` Previously, 2 dates in one line were considered as range. It was hard to decide if 2 dates are range when they were in separate lines or have some content between them. New explicit tag should clearly distinguish between single date and range. Common code from `addLocalDate` is extracted to `addSingleLocalDate`. Both `addLocalDate` and new `addLocalRange` are using `addSingleLocalDate`. Also, `defaultDateConfig` was extracted to have one place for all possible parameters.
This commit is contained in:

committed by
GitHub

parent
fff8b98485
commit
17ec3bc5b9
@ -86,4 +86,34 @@ RSpec.describe "Local Dates" do
|
||||
|
||||
expect(cooked).to include("data-countdown=")
|
||||
end
|
||||
|
||||
context 'ranges' do
|
||||
it 'generates ranges without time' do
|
||||
raw = "[date-range from=2022-01-06 to=2022-01-08]"
|
||||
cooked = Fabricate(:post, raw: raw).cooked
|
||||
|
||||
expect(cooked).to include('data-date="2022-01-06')
|
||||
expect(cooked).to include('data-range="true"')
|
||||
expect(cooked).not_to include('data-time=')
|
||||
end
|
||||
|
||||
it 'supports time and timezone' do
|
||||
raw = "[date-range from=2022-01-06T13:00 to=2022-01-08 timezone=Australia/Sydney]"
|
||||
cooked = Fabricate(:post, raw: raw).cooked
|
||||
|
||||
expect(cooked).to include('data-date="2022-01-06')
|
||||
expect(cooked).to include('data-range="true"')
|
||||
expect(cooked).to include('data-time="13:00"')
|
||||
expect(cooked).to include('data-timezone="Australia/Sydney"')
|
||||
end
|
||||
|
||||
it 'generates single date when range without end date' do
|
||||
raw = "[date-range from=2022-01-06T13:00]"
|
||||
cooked = Fabricate(:post, raw: raw).cooked
|
||||
|
||||
expect(cooked).to include('data-date="2022-01-06')
|
||||
expect(cooked).to include('data-time="13:00"')
|
||||
expect(cooked).not_to include('data-range=')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user