From 70f9fd5162ae9d7ede6d0372b5523a8886dcc491 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 14 Jun 2022 10:02:24 -0300 Subject: [PATCH] tz moment --- .../livechat/server/business-hour/AbstractBusinessHour.ts | 7 ++++--- apps/meteor/app/livechat/server/business-hour/Default.ts | 4 ++-- apps/meteor/app/livechat/server/lib/Analytics.js | 2 +- .../app/smarsh-connector/server/functions/generateEml.js | 3 +-- apps/meteor/app/smarsh-connector/server/settings.js | 3 +-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/meteor/app/livechat/server/business-hour/AbstractBusinessHour.ts b/apps/meteor/app/livechat/server/business-hour/AbstractBusinessHour.ts index 66024e005ae23..089d83d564029 100644 --- a/apps/meteor/app/livechat/server/business-hour/AbstractBusinessHour.ts +++ b/apps/meteor/app/livechat/server/business-hour/AbstractBusinessHour.ts @@ -1,4 +1,5 @@ import moment from 'moment'; +import { tz } from 'moment-timezone'; import type { ILivechatBusinessHour, ILivechatDepartment } from '@rocket.chat/core-typings'; import { IWorkHoursCronJobsWrapper, LivechatBusinessHoursRaw } from '../../../models/server/raw/LivechatBusinessHours'; @@ -71,8 +72,8 @@ export abstract class AbstractBusinessHourType { private convertWorkHours(businessHourData: ILivechatBusinessHour): ILivechatBusinessHour { businessHourData.workHours.forEach((hour: any) => { - const startUtc = moment.tz(`${hour.day}:${hour.start}`, 'dddd:HH:mm', businessHourData.timezone.name).utc(); - const finishUtc = moment.tz(`${hour.day}:${hour.finish}`, 'dddd:HH:mm', businessHourData.timezone.name).utc(); + const startUtc = tz(`${hour.day}:${hour.start}`, 'dddd:HH:mm', businessHourData.timezone.name).utc(); + const finishUtc = tz(`${hour.day}:${hour.finish}`, 'dddd:HH:mm', businessHourData.timezone.name).utc(); hour.start = { time: hour.start, utc: { @@ -103,7 +104,7 @@ export abstract class AbstractBusinessHourType { if (!timezone) { return String(moment().utcOffset() / 60); } - return moment.tz(timezone).format('Z'); + return tz(timezone).format('Z'); } private formatDayOfTheWeekFromServerTimezoneAndUtcHour(utc: any, format: string): string { diff --git a/apps/meteor/app/livechat/server/business-hour/Default.ts b/apps/meteor/app/livechat/server/business-hour/Default.ts index 0109508009462..19184ff2c3075 100644 --- a/apps/meteor/app/livechat/server/business-hour/Default.ts +++ b/apps/meteor/app/livechat/server/business-hour/Default.ts @@ -1,4 +1,4 @@ -import moment from 'moment'; +import { tz } from 'moment-timezone'; import { ILivechatBusinessHour, LivechatBusinessHourTypes } from '@rocket.chat/core-typings'; import { AbstractBusinessHourType, IBusinessHourType } from './AbstractBusinessHour'; @@ -21,7 +21,7 @@ export class DefaultBusinessHour extends AbstractBusinessHourType implements IBu return businessHourData; } businessHourData.timezone = { - name: timezoneName || moment.tz.guess(), + name: timezoneName || tz.guess(), utc: this.getUTCFromTimezone(timezoneName), }; await this.baseSaveBusinessHour(businessHourData); diff --git a/apps/meteor/app/livechat/server/lib/Analytics.js b/apps/meteor/app/livechat/server/lib/Analytics.js index 1974a5be1985c..43bb483f2cf2f 100644 --- a/apps/meteor/app/livechat/server/lib/Analytics.js +++ b/apps/meteor/app/livechat/server/lib/Analytics.js @@ -1,5 +1,5 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; -import moment from 'moment'; +import moment from 'moment-timezone'; import { LivechatRooms } from '../../../models'; import { LivechatRooms as LivechatRoomsRaw } from '../../../models/server/raw'; diff --git a/apps/meteor/app/smarsh-connector/server/functions/generateEml.js b/apps/meteor/app/smarsh-connector/server/functions/generateEml.js index a4244e3f95017..aff1769eaf0df 100644 --- a/apps/meteor/app/smarsh-connector/server/functions/generateEml.js +++ b/apps/meteor/app/smarsh-connector/server/functions/generateEml.js @@ -1,14 +1,13 @@ import { Meteor } from 'meteor/meteor'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import _ from 'underscore'; -import moment from 'moment'; +import moment from 'moment-timezone'; import { settings } from '../../../settings'; import { Rooms, Messages, Users } from '../../../models/server'; import { SmarshHistory } from '../../../models/server/raw'; import { MessageTypes } from '../../../ui-utils'; import { smarsh } from '../lib/rocketchat'; -import 'moment-timezone'; const start = ''; diff --git a/apps/meteor/app/smarsh-connector/server/settings.js b/apps/meteor/app/smarsh-connector/server/settings.js index 77c8f4e3b3de8..f5fe44cca1b5c 100644 --- a/apps/meteor/app/smarsh-connector/server/settings.js +++ b/apps/meteor/app/smarsh-connector/server/settings.js @@ -1,7 +1,6 @@ -import moment from 'moment'; +import moment from 'moment-timezone'; import { settingsRegistry } from '../../settings/server'; -import 'moment-timezone'; settingsRegistry.addGroup('Smarsh', function addSettings() { this.add('Smarsh_Enabled', false, {