mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-27 02:05:26 +08:00
This feature adds all day functionality to discourse-calendar post event events, and fixes the display across different timezones. There are many smaller changes in here to get the date to display correctly across timezones, including on the event topic itself, the upcoming events block in right-sidebar-blocks, the upcoming events page (calendar), and the badge on topics in list view. #### A bit more detailed: - Adds new column `all_day` to `discourse_post_event_events` and wires that up through the model, serializer, and controller - Modifies existing methods for formatting time to account for `all_day` flag - Modifies the frontend components to check for the `all_day` flag and, if present, display the dates without times and ignoring timezones - The post event builder form will now snap the times to 00:00 and 23:59 if all day is checked, and then hide the time entry input boxes - Adds the all day flag to the webhook payload and parses start/end times based on that flag - Tests for all of the new functionality #### Demo video https://github.com/user-attachments/assets/b4067764-d2e6-48df-b95e-5b8c717f8716
112 lines
3.6 KiB
Text
Vendored
112 lines
3.6 KiB
Text
Vendored
import { render } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import { fakeTime } from "discourse/tests/helpers/qunit-helpers";
|
|
import EventDate from "../../discourse/components/event-date";
|
|
|
|
module("Integration | Component | EventDate", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.siteSettings.discourse_post_event_enabled = true;
|
|
this.siteSettings.use_local_event_date = true;
|
|
this.originalGuess = moment.tz.guess;
|
|
});
|
|
|
|
hooks.afterEach(function () {
|
|
moment.tz.guess = this.originalGuess;
|
|
this.clock?.restore();
|
|
});
|
|
|
|
test("uses event timezone when show_local_time is true", async function (assert) {
|
|
moment.tz.guess = () => "Africa/Harare";
|
|
this.clock = fakeTime("2026-02-02T12:00:00Z", "Africa/Harare", true);
|
|
|
|
// 15:00 UTC on Feb 2 is:
|
|
// - Feb 3, 02:00 in Sydney (UTC+11)
|
|
// - Feb 2, 17:00 in Harare (UTC+2)
|
|
// So the date should show Feb 3 (Sydney) not Feb 2 (Harare)
|
|
const topic = {
|
|
event_starts_at: "2026-02-02T15:00:00.000Z",
|
|
event_timezone: "Australia/Sydney",
|
|
event_show_local_time: true,
|
|
};
|
|
|
|
await render(<template><EventDate @topic={{topic}} /></template>);
|
|
|
|
assert
|
|
.dom(".event-date")
|
|
.hasAttribute(
|
|
"title",
|
|
/February 3, 2026/,
|
|
"displays Feb 3 (Sydney timezone) not Feb 2 (browser Harare timezone)"
|
|
);
|
|
});
|
|
|
|
test("uses browser timezone when show_local_time is false", async function (assert) {
|
|
moment.tz.guess = () => "Africa/Harare";
|
|
this.clock = fakeTime("2026-02-02T12:00:00Z", "Africa/Harare", true);
|
|
|
|
// 15:00 UTC on Feb 2 is:
|
|
// - Feb 3, 02:00 in Sydney (UTC+11)
|
|
// - Feb 2, 17:00 in Harare (UTC+2)
|
|
// When show_local_time is false, should use browser timezone (Harare)
|
|
const topic = {
|
|
event_starts_at: "2026-02-02T15:00:00.000Z",
|
|
event_timezone: "Australia/Sydney",
|
|
event_show_local_time: false,
|
|
};
|
|
|
|
await render(<template><EventDate @topic={{topic}} /></template>);
|
|
|
|
assert
|
|
.dom(".event-date")
|
|
.hasAttribute(
|
|
"title",
|
|
/February 2, 2026.*5:00 PM/,
|
|
"displays Feb 2 (browser Harare timezone) not Feb 3 (event Sydney timezone)"
|
|
);
|
|
});
|
|
|
|
test("falls back to browser timezone when event has no timezone", async function (assert) {
|
|
moment.tz.guess = () => "Africa/Harare";
|
|
this.clock = fakeTime("2026-02-02T12:00:00Z", "Africa/Harare", true);
|
|
|
|
// 15:00 UTC on Feb 2 is Feb 2, 17:00 in Harare (UTC+2)
|
|
const topic = {
|
|
event_starts_at: "2026-02-02T15:00:00.000Z",
|
|
};
|
|
|
|
await render(<template><EventDate @topic={{topic}} /></template>);
|
|
|
|
assert
|
|
.dom(".event-date")
|
|
.hasAttribute(
|
|
"title",
|
|
/February 2, 2026.*5:00 PM/,
|
|
"displays date in browser timezone (Harare) when no event timezone"
|
|
);
|
|
});
|
|
|
|
test("all-day event does not shift date across timezones", async function (assert) {
|
|
// Use a western timezone where UTC midnight would shift to the previous day
|
|
moment.tz.guess = () => "America/Chicago";
|
|
this.clock = fakeTime("2026-03-11T12:00:00Z", "America/Chicago", true);
|
|
|
|
const topic = {
|
|
event_starts_at: "2026-03-12",
|
|
event_ends_at: "2026-03-14",
|
|
event_all_day: true,
|
|
};
|
|
|
|
await render(<template><EventDate @topic={{topic}} /></template>);
|
|
|
|
assert
|
|
.dom(".event-date")
|
|
.hasAttribute(
|
|
"title",
|
|
/March 12, 2026/,
|
|
"displays March 12 (correct date) not March 11 (timezone-shifted)"
|
|
);
|
|
});
|
|
});
|