mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
35 lines (30 loc) • 922 B
text/typescript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {UserTimezone} from 'types/users';
export function getUserCurrentTimezone(userTimezone?: UserTimezone): string | undefined | null {
if (!userTimezone) {
return null;
}
const {
useAutomaticTimezone,
automaticTimezone,
manualTimezone,
} = userTimezone;
let useAutomatic = useAutomaticTimezone;
if (typeof useAutomaticTimezone === 'string') {
useAutomatic = useAutomaticTimezone === 'true';
}
if (useAutomatic) {
return automaticTimezone;
}
return manualTimezone;
}
export function getTimezoneRegion(timezone: string): string {
if (timezone) {
const split = timezone.split('/');
if (split.length > 1) {
return split.pop()!.replace(/_/g, ' ');
}
}
return timezone;
}