Skip to content

A platform for community discussion. Free, open, simple.

FIX: Invalid Date on "last" shortcut for timer + bookmarks (#12783)

Martin Brennan206d8db433d1
diff --git a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js
index e35e3a33a37..69d4a436d5b 100644
--- a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js
+++ b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js
@@ -88,7 +88,6 @@ export default Component.extend({
}
this._bindKeyboardShortcuts();
- this._loadLastUsedCustomDatetime();
},
@observes("prefilledDatetime")
@@ -134,7 +133,7 @@ export default Component.extend({
if (lastTime && lastDate) {
let parsed = parseCustomDatetime(lastDate, lastTime, this.userTimezone);
- if (parsed < now(this.userTimezone)) {
+ if (!parsed.isValid() || parsed < now(this.userTimezone)) {
return;
}
@@ -175,6 +174,8 @@ export default Component.extend({
"userTimezone"
)
options(additionalOptionsToShow, hiddenOptions, customOptions, userTimezone) {
+ this._loadLastUsedCustomDatetime();
+
let options = defaultShortcutOptions(userTimezone);
if (additionalOptionsToShow.length > 0) {
@@ -255,7 +256,7 @@ export default Component.extend({
this.userTimezone
);
- if (customDatetime.isValid()) {
+ if (customDatetime.isValid() && this.customDate) {
dateTime = customDatetime;
localStorage.lastCustomTime = this.customTime;
diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-edit-timer-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-edit-timer-test.js
index 82a72b87c1e..070ee1aaced 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/topic-edit-timer-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-edit-timer-test.js
@@ -133,6 +133,41 @@ acceptance("Topic - Edit timer", function (needs) {
assert.ok(regex.test(text));
});
+ test("schedule - last custom date and time", async function (assert) {
+ updateCurrentUser({ moderator: true });
+
+ await visit("/t/internationalization-localization");
+ await click(".toggle-admin-menu");
+ await click(".admin-topic-timer-update button");
+
+ await click("#tap_tile_custom");
+ await click(".modal-close");
+
+ await click(".toggle-admin-menu");
+ await click(".admin-topic-timer-update button");
+
+ assert.notOk(
+ exists("#tap_tile_last_custom"),
+ "it does not show last custom if the custom date and time was not filled and valid"
+ );
+
+ await click("#tap_tile_custom");
+ await fillIn(".tap-tile-date-input .date-picker", "2099-11-24");
+ await fillIn("#custom-time", "10:30");
+ await click(".edit-topic-timer-buttons button.btn-primary");
+
+ await click(".toggle-admin-menu");
+ await click(".admin-topic-timer-update button");
+
+ assert.ok(
+ exists("#tap_tile_last_custom"),
+ "it show last custom because the custom date and time was valid"
+ );
+ let text = queryAll("#tap_tile_last_custom").text().trim();
+ const regex = /Nov 24, 10:30 am/g;
+ assert.ok(regex.test(text));
+ });
+
test("TL4 can't auto-delete", async function (assert) {
updateCurrentUser({ moderator: false, admin: false, trust_level: 4 });
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index efaadae43cd..b91131b93c7 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -324,18 +324,6 @@ en:
search_placeholder: "Search bookmarks by name, topic title, or post content"
search: "Search"
reminders:
- later_today: "Later today"
- next_business_day: "Next business day"
- tomorrow: "Tomorrow"
- next_week: "Next week"
- post_local_date: "Date in post"
- later_this_week: "Later this week"
- start_of_next_business_week: "Monday"
- start_of_next_business_week_alt: "Next Monday"
- next_month: "Next month"
- custom: "Custom date and time"
- last_custom: "Last"
- none: "No reminder needed"
today_with_time: "today at %{time}"
tomorrow_with_time: "tomorrow at %{time}"
at_time: "at %{date_time}"
@@ -614,7 +602,7 @@ en:
custom: "Custom date and time"
relative: "Relative time"
none: "None needed"
- last_custom: "Last"
+ last_custom: "Last custom datetime"
user_action:
user_posted_topic: "<a href='%{userUrl}'>%{user}</a> posted <a href='%{topicUrl}'>the topic</a>"