UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

47 lines (46 loc) 1.62 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.getUserCurrentTimezone = getUserCurrentTimezone; exports.getTimezoneRegion = getTimezoneRegion; exports.getTimezoneLabel = getTimezoneLabel; exports.getDateForTimezone = getDateForTimezone; function getUserCurrentTimezone(userTimezone) { if (!userTimezone) { return 'UTC'; } const { useAutomaticTimezone, automaticTimezone, manualTimezone, } = userTimezone; let useAutomatic = useAutomaticTimezone; if (typeof useAutomaticTimezone === 'string') { useAutomatic = useAutomaticTimezone === 'true'; } if (useAutomatic) { return automaticTimezone || 'UTC'; } return manualTimezone || 'UTC'; } function getTimezoneRegion(timezone) { if (timezone) { const split = timezone.split('/'); if (split.length > 1) { return split.pop().replace(/_/g, ' '); } } return timezone; } function getTimezoneLabel(timezones, timezone) { for (let i = 0; i < timezones.length; i++) { const zone = timezones[i]; for (let j = 0; j < zone.utc.length; j++) { const utcZone = zone.utc[j]; if (utcZone.toLowerCase() === timezone.toLowerCase()) { return zone.text; } } } return timezone; } function getDateForTimezone(date, tzString) { return new Date((typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', { timeZone: tzString })); }