Skip to content

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

DEV: improve timezone API on the client (#16660)

Andrei Prigorshnev7412f665e799
diff --git a/app/assets/javascripts/discourse/app/components/bookmark.js b/app/assets/javascripts/discourse/app/components/bookmark.js
index df1409a793e..9d7a8eb01c6 100644
--- a/app/assets/javascripts/discourse/app/components/bookmark.js
+++ b/app/assets/javascripts/discourse/app/components/bookmark.js
@@ -55,7 +55,7 @@ export default Component.extend({
postDetectedLocalTime: null,
postDetectedLocalTimezone: null,
prefilledDatetime: null,
- userTimezone: this.currentUser.resolvedTimezone(this.currentUser),
+ userTimezone: this.currentUser.timezone,
showOptions: false,
_itsatrap: new ItsATrap(),
autoDeletePreference: this.model.autoDeletePreference || 0,
diff --git a/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js b/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js
index 4489a1353ba..f499f6e3f5d 100644
--- a/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js
+++ b/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js
@@ -84,7 +84,7 @@ export default Component.extend({
@discourseComputed()
timeOptions() {
- const timezone = this.currentUser.resolvedTimezone(this.currentUser);
+ const timezone = this.currentUser.timezone;
const shortcuts = timeShortcuts(timezone);
return [
diff --git a/app/assets/javascripts/discourse/app/components/future-date-input.js b/app/assets/javascripts/discourse/app/components/future-date-input.js
index 2278fb79cb1..3f54b8f5b2b 100644
--- a/app/assets/javascripts/discourse/app/components/future-date-input.js
+++ b/app/assets/javascripts/discourse/app/components/future-date-input.js
@@ -27,7 +27,7 @@ export default Component.extend({
init() {
this._super(...arguments);
- this.userTimezone = this.currentUser.resolvedTimezone(this.currentUser);
+ this.userTimezone = this.currentUser.timezone;
if (this.input) {
const dateTime = moment(this.input);
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 07627e149ee..ad8da0313f2 100644
--- a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js
+++ b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js
@@ -76,7 +76,7 @@ export default Component.extend({
_setupPicker() {
this.setProperties({
customTime: this.defaultCustomReminderTime,
- userTimezone: this.currentUser.resolvedTimezone(this.currentUser),
+ userTimezone: this.currentUser.timezone,
hiddenOptions: this.hiddenOptions || [],
customOptions: this.customOptions || [],
customLabels: this.customLabels || {},
diff --git a/app/assets/javascripts/discourse/app/components/user-card-contents.js b/app/assets/javascripts/discourse/app/components/user-card-contents.js
index db6621cc71d..d5e7d859399 100644
--- a/app/assets/javascripts/discourse/app/components/user-card-contents.js
+++ b/app/assets/javascripts/discourse/app/components/user-card-contents.js
@@ -79,7 +79,7 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, {
if (!this.showUserLocalTime) {
return;
}
- return user.resolvedTimezone(this.currentUser);
+ return user.timezone;
},
@discourseComputed("userTimezone")
diff --git a/app/assets/javascripts/discourse/app/controllers/create-invite.js b/app/assets/javascripts/discourse/app/controllers/create-invite.js
index b549e6826a1..20085801cd0 100644
--- a/app/assets/javascripts/discourse/app/controllers/create-invite.js
+++ b/app/assets/javascripts/discourse/app/controllers/create-invite.js
@@ -180,7 +180,7 @@ export default Controller.extend(
@discourseComputed
timeShortcuts() {
- const timezone = this.currentUser.resolvedTimezone(this.currentUser);
+ const timezone = this.currentUser.timezone;
const shortcuts = timeShortcuts(timezone);
return [
shortcuts.laterToday(),
diff --git a/app/assets/javascripts/discourse/app/controllers/edit-slow-mode.js b/app/assets/javascripts/discourse/app/controllers/edit-slow-mode.js
index fa95a69e8f2..f3c70f5b8be 100644
--- a/app/assets/javascripts/discourse/app/controllers/edit-slow-mode.js
+++ b/app/assets/javascripts/discourse/app/controllers/edit-slow-mode.js
@@ -110,7 +110,7 @@ export default Controller.extend(ModalFunctionality, {
@discourseComputed
timeShortcuts() {
- const timezone = this.currentUser.resolvedTimezone(this.currentUser);
+ const timezone = this.currentUser.timezone;
const shortcuts = timeShortcuts(timezone);
const nextWeek = shortcuts.monday();
diff --git a/app/assets/javascripts/discourse/app/controllers/ignore-duration-with-username.js b/app/assets/javascripts/discourse/app/controllers/ignore-duration-with-username.js
index 2b1e997a071..8ead0d77e36 100644
--- a/app/assets/javascripts/discourse/app/controllers/ignore-duration-with-username.js
+++ b/app/assets/javascripts/discourse/app/controllers/ignore-duration-with-username.js
@@ -13,7 +13,7 @@ export default Controller.extend(ModalFunctionality, {
@discourseComputed
timeShortcuts() {
- const timezone = this.currentUser.resolvedTimezone(this.currentUser);
+ const timezone = this.currentUser.timezone;
const shortcuts = timeShortcuts(timezone);
return [
shortcuts.laterToday(),
diff --git a/app/assets/javascripts/discourse/app/controllers/ignore-duration.js b/app/assets/javascripts/discourse/app/controllers/ignore-duration.js
index 0ee1ae3fcb5..75a7cb32453 100644
--- a/app/assets/javascripts/discourse/app/controllers/ignore-duration.js
+++ b/app/assets/javascripts/discourse/app/controllers/ignore-duration.js
@@ -11,7 +11,7 @@ export default Controller.extend(ModalFunctionality, {
@discourseComputed
timeShortcuts() {
- const timezone = this.currentUser.resolvedTimezone(this.currentUser);
+ const timezone = this.currentUser.timezone;
const shortcuts = timeShortcuts(timezone);
return [
shortcuts.laterToday(),
diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/profile.js b/app/assets/javascripts/discourse/app/controllers/preferences/profile.js
index 26cd76c27df..2470c060f6c 100644
--- a/app/assets/javascripts/discourse/app/controllers/preferences/profile.js
+++ b/app/assets/javascripts/discourse/app/controllers/preferences/profile.js
@@ -126,7 +126,7 @@ export default Controller.extend({
// update the timezone in memory so we can use the new
// one if we change routes without reloading the user
if (this.currentUser.id === this.model.id) {
- this.currentUser.changeTimezone(this.model.user_option.timezone);
+ this.currentUser.timezone = this.model.user_option.timezone;
}
cookAsync(model.get("bio_raw"))
diff --git a/app/assets/javascripts/discourse/app/models/bookmark.js b/app/assets/javascripts/discourse/app/models/bookmark.js
index 9285ff7ccb4..c38a5b69cc6 100644
--- a/app/assets/javascripts/discourse/app/models/bookmark.js
+++ b/app/assets/javascripts/discourse/app/models/bookmark.js
@@ -134,10 +134,7 @@ const Bookmark = RestModel.extend({
@discourseComputed("reminder_at", "currentUser")
formattedReminder(bookmarkReminderAt, currentUser) {
return capitalize(
- formattedReminderTime(
- bookmarkReminderAt,
- currentUser.resolvedTimezone(currentUser)
- )
+ formattedReminderTime(bookmarkReminderAt, currentUser.timezone)
);
},
diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js
index 39d215a0c7b..981b4619e73 100644
--- a/app/assets/javascripts/discourse/app/models/user.js
+++ b/app/assets/javascripts/discourse/app/models/user.js
@@ -670,11 +670,6 @@ const User = RestModel.extend({
json.user.card_badge = Badge.create(json.user.card_badge);
}
- if (!json.user._timezone) {
- json.user._timezone = json.user.timezone;
- delete json.user.timezone;
- }
-
user.setProperties(json.user);
return user;
});
@@ -961,34 +956,9 @@ const User = RestModel.extend({
);
},
- resolvedTimezone(currentUser) {
- if (this.hasSavedTimezone()) {
- return this._timezone;
- }
-
- // only change the timezone and save it if we are
- // looking at our own user
- if (currentUser.id === this.id) {
- this.changeTimezone(moment.tz.guess());
- ajax(userPath(this.username + ".json"), {
- type: "PUT",
- dataType: "json",
- data: { timezone: this._timezone },
- });
- }
-
- return this._timezone;
- },
-
- changeTimezone(tz) {
- this._timezone = tz;
- },
-
- hasSavedTimezone() {
- if (this._timezone) {
- return true;
- }
- return false;
+ // obsolete, just call "user.timezone" instead
+ resolvedTimezone() {
+ return this.timezone;
},
calculateMutedIds(notificationLevel, id, type) {
@@ -1040,17 +1010,6 @@ const User = RestModel.extend({
});
User.reopenClass(Singleton, {
- munge(json) {
- // timezone should not be directly accessed, use
- // resolvedTimezone() and changeTimezone(tz)
- if (!json._timezone) {
- json._timezone = json.timezone;
- delete json.timezone;
- }
-
- return json;
- },
-
// Find a `User` for a given username.
findByUsername(username, options) {
const user = User.create({ username });
@@ -1059,22 +1018,26 @@ User.reopenClass(Singleton, {
// TODO: Use app.register and junk Singleton
createCurrent() {
- let userJson = PreloadStore.get("currentUser");
+ const userJson = PreloadStore.get("currentUser");
+ if (userJson) {
+ if (userJson.primary_group_id) {
+ const primaryGroup = userJson.groups.find(
+ (group) => group.id === userJson.primary_group_id
+ );
+ if (primaryGroup) {
+ userJson.primary_group_name = primaryGroup.name;
+ }
+ }
- if (userJson && userJson.primary_group_id) {
- const primaryGroup = userJson.groups.find(
- (group) => group.id === userJson.primary_group_id
- );
- if (primaryGroup) {
- userJson.primary_group_name = primaryGroup.name;
+ if (!userJson.timezone) {
+ userJson.timezone = moment.tz.guess();
+ this._saveTimezone(userJson);
}
- }
- if (userJson) {
- userJson = User.munge(userJson);
const store = getOwner(this).lookup("service:store");
return store.createRecord("user", userJson);
}
+
return null;
},
@@ -1145,6 +1108,14 @@ User.reopenClass(Singleton, {
type: "POST",
});
},
+
+ _saveTimezone(user) {
+ ajax(userPath(user.username + ".json"), {
+ type: "PUT",
+ dataType: "json",
+ data: { timezone: user.timezone },
+ });
+ },
});
if (typeof Discourse !== "undefined") {
diff --git a/app/assets/javascripts/discourse/app/widgets/post-menu.js b/app/assets/javascripts/discourse/app/widgets/post-menu.js
index 8b9272783e9..1f542697ecb 100644
--- a/app/assets/javascripts/discourse/app/widgets/post-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/post-menu.js
@@ -340,7 +340,7 @@ registerButton(
if (attrs.bookmarkReminderAt) {
let formattedReminder = formattedReminderTime(
attrs.bookmarkReminderAt,
- currentUser.resolvedTimezone(currentUser)
+ currentUser.timezone
);
title = "bookmarks.created_with_reminder";
titleOptions.date = formattedReminder;
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-silence-user-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-silence-user-test.js
index 828b966d08b..4d0f06f7e9d 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-silence-user-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-silence-user-test.js
@@ -13,7 +13,7 @@ acceptance("Admin - Silence User", function (needs) {
needs.user();
needs.hooks.beforeEach(() => {
- const timezone = loggedInUser().resolvedTimezone(loggedInUser());
+ const timezone = loggedInUser().timezone;
clock = fakeTime("2100-05-03T08:00:00", timezone, true); // Monday morning
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
index 43d41a685c3..c60d3170cf4 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
@@ -112,7 +112,7 @@ acceptance("Admin - Suspend User - timeframe choosing", function (needs) {
needs.user();
needs.hooks.beforeEach(() => {
- const timezone = loggedInUser().resolvedTimezone(loggedInUser());
+ const timezone = loggedInUser().timezone;
clock = fakeTime("2100-05-03T08:00:00", timezone, true); // Monday morning
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/bookmarks-test.js b/app/assets/javascripts/discourse/tests/acceptance/bookmarks-test.js
index 177baae964c..0b09dc508cb 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/bookmarks-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/bookmarks-test.js
@@ -241,7 +241,7 @@ acceptance("Bookmarking", function (needs) {
test("Editing a bookmark", async function (assert) {
await visit("/t/internationalization-localization/280");
- let now = moment.tz(loggedInUser().resolvedTimezone(loggedInUser()));
+ let now = moment.tz(loggedInUser().timezone);
let tomorrow = now.add(1, "day").format("YYYY-MM-DD");
await openBookmarkModal();
await fillIn("input#bookmark-name", "Test name");
@@ -267,10 +267,7 @@ acceptance("Bookmarking", function (needs) {
test("Using a post date for the reminder date", async function (assert) {
await visit("/t/internationalization-localization/280");
- let postDate = moment.tz(
- "2036-01-15",
- loggedInUser().resolvedTimezone(loggedInUser())
- );
+ let postDate = moment.tz("2036-01-15", loggedInUser().timezone);
let postDateFormatted = postDate.format("YYYY-MM-DD");
await openBookmarkModal();
await fillIn("input#bookmark-name", "Test name");
diff --git a/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js b/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js
index 52194dac9ed..cf08b5a8ae2 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js
@@ -191,7 +191,7 @@ acceptance(
});
needs.hooks.beforeEach(() => {
- const timezone = loggedInUser().resolvedTimezone(loggedInUser());
+ const timezone = loggedInUser().timezone;
clock = fakeTime("2100-05-03T08:00:00", timezone, true); // Monday morning
});
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 983a3d522f6..f8b682510b1 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
@@ -30,7 +30,7 @@ acceptance("Topic - Edit timer", function (needs) {
});
needs.hooks.beforeEach(() => {
- const timezone = loggedInUser().resolvedTimezone(loggedInUser());
+ const timezone = loggedInUser().timezone;
const tuesday = "2100-06-15T08:00:00";
clock = fakeTime(tuesday, timezone, true);
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-set-slow-mode-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-set-slow-mode-test.js
index e9747a2c386..e35eb72071f 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/topic-set-slow-mode-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-set-slow-mode-test.js
@@ -29,7 +29,7 @@ acceptance("Topic - Set Slow Mode", function (needs) {
});
needs.hooks.beforeEach(() => {
- const timezone = loggedInUser().resolvedTimezone(loggedInUser());
+ const timezone = loggedInUser().timezone;
clock = fakeTime("2100-05-03T08:00:00", timezone, true); // Monday morning
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-card-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-card-test.js
index e58387e5a56..28bfe9a1532 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/user-card-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/user-card-test.js
@@ -19,7 +19,7 @@ acceptance("User Card - Show Local Time", function (needs) {
});
test("user card local time - does not update timezone for another user", async function (assert) {
- User.current().changeTimezone("Australia/Brisbane");
+ User.current().timezone = "Australia/Brisbane";
await visit("/t/internationalization-localization/280");
await click('a[data-user-card="charlie"]');
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-notifications-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-notifications-test.js
index 01da030999e..d107673ac20 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-notifications-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-notifications-test.js
@@ -116,7 +116,7 @@ acceptance("User Notifications - Users - Ignore User", function (needs) {
needs.user();
needs.hooks.beforeEach(() => {
- const timezone = loggedInUser().resolvedTimezone(loggedInUser());
+ const timezone = loggedInUser().timezone;
clock = fakeTime("2100-05-03T08:00:00", timezone, true); // Monday morning
});
diff --git a/app/assets/javascripts/discourse/tests/integration/components/future-date-input-test.js b/app/assets/javascripts/discourse/tests/integration/components/future-date-input-test.js
index d7e2cdc1e00..33c4df73795 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/future-date-input-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/future-date-input-test.js
@@ -56,7 +56,7 @@ discourseModule("Unit | Lib | select-kit/future-date-input", function (hooks) {
beforeEach() {
const monday = "2100-12-13T08:00:00";
- this.clock = fakeTime(monday, this.currentUser._timezone, true);
+ this.clock = fakeTime(monday, this.currentUser.timezone, true);
},
async test(assert) {
diff --git a/app/assets/javascripts/discourse/tests/integration/components/time-shortcut-picker-test.js b/app/assets/javascripts/discourse/tests/integration/components/time-shortcut-picker-test.js
index 7d5aeeeed9f..395742c782d 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/time-shortcut-picker-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/time-shortcut-picker-test.js
@@ -40,7 +40,7 @@ discourseModule(
beforeEach() {
this.siteSettings.suggest_weekends_in_date_pickers = true;
const tuesday = "2100-06-08T08:00:00";
- this.clock = fakeTime(tuesday, this.currentUser._timezone, true);
+ this.clock = fakeTime(tuesday, this.currentUser.timezone, true);
},
async test(assert) {
@@ -70,7 +70,7 @@ discourseModule(
beforeEach() {
const monday = "2100-06-07T08:00:00";
- this.clock = fakeTime(monday, this.currentUser._timezone, true);
+ this.clock = fakeTime(monday, this.currentUser.timezone, true);
},
test(assert) {
@@ -86,7 +86,7 @@ discourseModule(
beforeEach() {
const thursday = "2100-06-10T08:00:00";
- this.clock = fakeTime(thursday, this.currentUser._timezone, true);
+ this.clock = fakeTime(thursday, this.currentUser.timezone, true);
},
test(assert) {
@@ -103,7 +103,7 @@ discourseModule(
beforeEach() {
this.clock = fakeTime(
"2100-12-11T22:00:00", // + 3 hours is tomorrow
- this.currentUser._timezone,
+ this.currentUser.timezone,
true
);
},
@@ -122,7 +122,7 @@ discourseModule(
beforeEach() {
this.clock = fakeTime(
"2100-12-11T16:50:00",
- this.currentUser._timezone,
+ this.currentUser.timezone,
true
);
},
@@ -138,7 +138,7 @@ discourseModule(
beforeEach() {
this.clock = fakeTime(
"2100-12-11T17:00:00",
- this.currentUser._timezone,
+ this.currentUser.timezone,
true
);
},
@@ -165,7 +165,7 @@ discourseModule(
beforeEach() {
const sunday = "2100-01-24T08:00:00";
- this.clock = fakeTime(sunday, this.currentUser._timezone, true);
+ this.clock = fakeTime(sunday, this.currentUser.timezone, true);
},
async test(assert) {
@@ -188,7 +188,7 @@ discourseModule(
beforeEach() {
const monday = "2100-01-25T08:00:00";
- this.clock = fakeTime(monday, this.currentUser._timezone, true);
+ this.clock = fakeTime(monday, this.currentUser.timezone, true);
},
async test(assert) {
@@ -214,7 +214,7 @@ discourseModule(
beforeEach() {
this.clock = fakeTime(
"2100-01-01T08:00:00",
- this.currentUser._timezone,
+ this.currentUser.timezone,
true
);
},
diff --git a/app/assets/javascripts/discourse/tests/unit/models/user-test.js b/app/assets/javascripts/discourse/tests/unit/models/user-test.js
index 751ba857335..11af31127cc 100644
--- a/app/assets/javascripts/discourse/tests/unit/models/user-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/models/user-test.js
@@ -1,8 +1,8 @@
-import * as ajaxlib from "discourse/lib/ajax";
import { module, test } from "qunit";
-import sinon from "sinon";
import Group from "discourse/models/group";
import User from "discourse/models/user";
+import PreloadStore from "discourse/lib/preload-store";
+import sinon from "sinon";
module("Unit | Model | user", function () {
test("staff", function (assert) {
@@ -70,58 +70,36 @@ module("Unit | Model | user", function () {
);
});
- test("resolvedTimezone", function (assert) {
- const tz = "Australia/Brisbane";
- let user = User.create({ timezone: tz, username: "chuck", id: 111 });
+ test("muted ids", function (assert) {
+ let user = User.create({ username: "chuck", muted_category_ids: [] });
- sinon.stub(moment.tz, "guess").returns("America/Chicago");
- sinon.stub(ajaxlib.ajax);
- let spy = sinon.spy(ajaxlib, "ajax");
+ assert.deepEqual(user.calculateMutedIds(0, 1, "muted_category_ids"), [1]);
+ assert.deepEqual(user.calculateMutedIds(1, 1, "muted_category_ids"), []);
+ });
- assert.strictEqual(
- user.resolvedTimezone(user),
- tz,
- "if the user already has a timezone return it"
- );
- assert.ok(
- spy.notCalled,
- "if the user already has a timezone do not call AJAX update"
- );
- user = User.create({ username: "chuck", id: 111 });
- assert.strictEqual(
- user.resolvedTimezone(user),
- "America/Chicago",
- "if the user has no timezone guess it with moment"
- );
- assert.ok(
- spy.calledWith("/u/chuck.json", {
- type: "PUT",
- dataType: "json",
- data: { timezone: "America/Chicago" },
- }),
- "if the user has no timezone save it with an AJAX update"
- );
+ test("createCurrent() guesses timezone if user doesn't have it set", function (assert) {
+ PreloadStore.store("currentUser", {
+ username: "eviltrout",
+ timezone: null,
+ });
+ const expectedTimezone = "Africa/Casablanca";
+ sinon.stub(moment.tz, "guess").returns(expectedTimezone);
- let otherUser = User.create({ username: "howardhamlin", id: 999 });
- assert.strictEqual(
- otherUser.resolvedTimezone(user),
- undefined,
- "if the user has no timezone and the user is not the current user, do NOT guess with moment"
- );
- assert.notOk(
- spy.calledWith("/u/howardhamlin.json", {
- type: "PUT",
- dataType: "json",
- data: { timezone: "America/Chicago" },
- }),
- "if the user has no timezone, and the user is not the current user, do NOT save it with an AJAX update"
- );
+ const currentUser = User.createCurrent();
+
+ assert.deepEqual(currentUser.timezone, expectedTimezone);
});
- test("muted ids", function (assert) {
- let user = User.create({ username: "chuck", muted_category_ids: [] });
+ test("createCurrent() doesn't guess timezone if user has it already set", function (assert) {
+ const timezone = "Africa/Casablanca";
+ PreloadStore.store("currentUser", {
+ username: "eviltrout",
+ timezone,
+ });
+ const spyMomentGuess = sinon.spy(moment.tz, "guess");
- assert.deepEqual(user.calculateMutedIds(0, 1, "muted_category_ids"), [1]);
- assert.deepEqual(user.calculateMutedIds(1, 1, "muted_category_ids"), []);
+ User.createCurrent();
+
+ assert.ok(spyMomentGuess.notCalled);
});
});
diff --git a/app/assets/javascripts/select-kit/addon/components/future-date-input-selector.js b/app/assets/javascripts/select-kit/addon/components/future-date-input-selector.js
index 18031e21f7f..e294171f655 100644
--- a/app/assets/javascripts/select-kit/addon/components/future-date-input-selector.js
+++ b/app/assets/javascripts/select-kit/addon/components/future-date-input-selector.js
@@ -18,7 +18,7 @@ export default ComboBoxComponent.extend({
init() {
this._super(...arguments);
- this.userTimezone = this.currentUser.resolvedTimezone(this.currentUser);
+ this.userTimezone = this.currentUser.timezone;
},
modifyComponentForRow() {