mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 20:02:15 +00:00
people: Fix misleading comments and tests for utcToZonedTime.
The reason utcToZonedTime would return an invalid Date (i.e. ‘new Date(NaN)’) is because we passed in an invalid timezone. Fix the comments and tests to reflect this; remove unnecessary mocking and the misleading ‘instanceof Date’ check. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
40d61be293
commit
fda73976bd
@@ -287,14 +287,8 @@ export function get_user_time(user_id) {
|
||||
const user_pref = get_user_time_preferences(user_id);
|
||||
if (user_pref) {
|
||||
const current_date = utcToZonedTime(new Date(), user_pref.timezone);
|
||||
// In theory, utcToZonedTime should always return a Date
|
||||
// object. However, we have reports from users in the wild
|
||||
// seeing this returning `undefined`. To avoid throwing an
|
||||
// exception, we check whether we got a Date object back,
|
||||
// including a NaN check, which covers the case where we
|
||||
// called `Date("foo")`.
|
||||
// eslint-disable-next-line unicorn/prefer-number-properties
|
||||
if (!(current_date instanceof Date) || isNaN(current_date)) {
|
||||
// This could happen if the timezone is invalid.
|
||||
if (Number.isNaN(current_date.getTime())) {
|
||||
blueslip.error(`Got invalid date for timezone: ${user_pref.timezone}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user