From eef207029d4a7ca2a1738cab804a67725fbedfc7 Mon Sep 17 00:00:00 2001 From: aishik-biswas Date: Fri, 17 Dec 2021 12:48:32 +0530 Subject: [PATCH 1/5] timezone-update --- packages/utilities/package.json | 3 +-- .../src/is-outside-business-hours.ts | 19 ++++------------- yarn.lock | 21 +++++++------------ 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/packages/utilities/package.json b/packages/utilities/package.json index 4f1762b9..a75a4709 100644 --- a/packages/utilities/package.json +++ b/packages/utilities/package.json @@ -36,7 +36,6 @@ "typescript": "^4.3.2" }, "dependencies": { - "dayjs": "^1.10.5", - "timezone-support": "^2.0.2" + "moment-timezone": "^0.5.33" } } diff --git a/packages/utilities/src/is-outside-business-hours.ts b/packages/utilities/src/is-outside-business-hours.ts index fa373b93..72d04254 100644 --- a/packages/utilities/src/is-outside-business-hours.ts +++ b/packages/utilities/src/is-outside-business-hours.ts @@ -1,13 +1,4 @@ -import dayjs from 'dayjs'; -import advancedFormat from 'dayjs/plugin/advancedFormat'; -import relativeTime from 'dayjs/plugin/relativeTime'; -import localizedFormat from 'dayjs/plugin/localizedFormat'; -import { findTimeZone, getZonedTime } from 'timezone-support'; -import { formatZonedTime } from 'timezone-support/dist/parse-format'; - -dayjs.extend(advancedFormat); -dayjs.extend(relativeTime); -dayjs.extend(localizedFormat); +import moment from 'moment-timezone'; type DateInput = Date | number; @@ -53,11 +44,8 @@ const getWorkingHours = (data: string): string[][] => { const toTimeZone = (timeStamp: DateInput, preferredTimeZone: string): string => { if (timeStamp && preferredTimeZone) { try { - const timeZoneData = findTimeZone(preferredTimeZone); - const convertedTime = getZonedTime(timeStamp, timeZoneData); const format = 'YYYY-MM-DD HH:mm:ss'; - - return formatZonedTime(convertedTime, format); + return moment(timeStamp).tz(preferredTimeZone).format(format); } catch (err) { return ''; } @@ -77,7 +65,7 @@ const isOutsideBusinessHours = (businessHour: BusinessHour, currentTimeInMillis: if (!operatingHours.enabled) { isAway = false; } else { - agentTime = dayjs(toTimeZone(currentTimeInMillis, operatingHours.timezone.replace(' - ', '/'))); + agentTime = moment(toTimeZone(currentTimeInMillis, operatingHours.timezone.replace(' - ', '/'))); agentDayOfWeek = (agentTime.day() + 6) % 7; if (operatingHours.working[agentDayOfWeek] !== 'true') { isAway = true; @@ -89,6 +77,7 @@ const isOutsideBusinessHours = (businessHour: BusinessHour, currentTimeInMillis: toTimeSeconds = parseInt(fromToArr[1], 10), agentTimeFrom = agentTime.clone().startOf('day').add(fromTimeSeconds, 's'), agentTimeTo = agentTime.clone().startOf('day').add(toTimeSeconds, 's'); + if (agentTime.isAfter(agentTimeFrom) && agentTime.isBefore(agentTimeTo)) { isAway = false; break; diff --git a/yarn.lock b/yarn.lock index 3e14a864..772b6266 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2519,11 +2519,6 @@ combined-stream@^1.0.6, combined-stream@~1.0.6: dependencies: delayed-stream "~1.0.0" -commander@2.20.0: - version "2.20.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422" - integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ== - commander@^2.19.0: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" @@ -5722,7 +5717,14 @@ modify-values@^1.0.0: resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw== -moment@^2.18.1: +moment-timezone@^0.5.33: + version "0.5.34" + resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.34.tgz#a75938f7476b88f155d3504a9343f7519d9a405c" + integrity sha512-3zAEHh2hKUs3EXLESx/wsgw6IQdusOT8Bxm3D9UrHPQR7zlMmzwybC8zHEM1tQ4LJwP7fcxrWr8tuBg05fFCbg== + dependencies: + moment ">= 2.9.0" + +"moment@>= 2.9.0", moment@^2.18.1: version "2.29.1" resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3" integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ== @@ -7833,13 +7835,6 @@ time-stamp@^1.0.1: resolved "https://registry.yarnpkg.com/time-stamp/-/time-stamp-1.1.0.tgz#764a5a11af50561921b133f3b44e618687e0f5c3" integrity sha1-dkpaEa9QVhkhsTPztE5hhofg9cM= -timezone-support@^2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/timezone-support/-/timezone-support-2.0.2.tgz#801d6924478b1b60f09b90699ce1127a6044cbe7" - integrity sha512-J/1PyHCX76vOPuJzCyHMQMH2wTjXCJ30R5EXaS/QTi+xYsL0thS0pubDrHCWnfG4zU1jpPJtctnBBRCOpcJZeQ== - dependencies: - commander "2.20.0" - tmp@^0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" From a03230adc33ac8e44e7d6576c4c727539810a30d Mon Sep 17 00:00:00 2001 From: aishik-biswas Date: Fri, 17 Dec 2021 13:00:20 +0530 Subject: [PATCH 2/5] Publish - @freshworks-jaya/freshchat-api@0.7.28-alpha.0 - @freshworks-jaya/rule-engine@0.17.4-alpha.0 - @freshworks-jaya/utilities@0.2.9-alpha.0 --- packages/freshchat-api/package.json | 4 ++-- packages/rule-engine/package.json | 6 +++--- packages/utilities/package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/freshchat-api/package.json b/packages/freshchat-api/package.json index f617c165..ed42329d 100644 --- a/packages/freshchat-api/package.json +++ b/packages/freshchat-api/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/freshchat-api", - "version": "0.7.27", + "version": "0.7.28-alpha.0", "description": "Provides simple interface for accessing Freshchat's public APIs", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", @@ -43,7 +43,7 @@ "typescript": "^4.3.2" }, "dependencies": { - "@freshworks-jaya/utilities": "^0.2.8", + "@freshworks-jaya/utilities": "^0.2.9-alpha.0", "axios": "^0.21.4", "dayjs": "^1.10.5", "handlebars": "^4.7.7", diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index 9be69056..d09d47f0 100644 --- a/packages/rule-engine/package.json +++ b/packages/rule-engine/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/rule-engine", - "version": "0.17.3", + "version": "0.17.4-alpha.0", "description": "Provides methods to process rules in product events in marketplace app", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", @@ -44,10 +44,10 @@ "typescript": "^4.3.2" }, "dependencies": { - "@freshworks-jaya/freshchat-api": "^0.7.27", + "@freshworks-jaya/freshchat-api": "^0.7.28-alpha.0", "@freshworks-jaya/kairos-api": "^0.1.5", "@freshworks-jaya/marketplace-models": "^0.1.14", - "@freshworks-jaya/utilities": "^0.2.8", + "@freshworks-jaya/utilities": "^0.2.9-alpha.0", "@google-cloud/logging": "^9.3.1", "axios": "^0.21.4", "bluebird": "^3.7.2", diff --git a/packages/utilities/package.json b/packages/utilities/package.json index a75a4709..09517d1b 100644 --- a/packages/utilities/package.json +++ b/packages/utilities/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/utilities", - "version": "0.2.8", + "version": "0.2.9-alpha.0", "description": "Provides a function that can replace placeholders in a string with a given map.", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", From ccd7030dbb53fc88cb35cb3bcb5f3d599e6c1f9a Mon Sep 17 00:00:00 2001 From: aishik-biswas Date: Fri, 17 Dec 2021 13:02:40 +0530 Subject: [PATCH 3/5] Update is-outside-business-hours.test.ts --- packages/utilities/test/is-outside-business-hours.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utilities/test/is-outside-business-hours.test.ts b/packages/utilities/test/is-outside-business-hours.test.ts index f1727c3c..958af288 100644 --- a/packages/utilities/test/is-outside-business-hours.test.ts +++ b/packages/utilities/test/is-outside-business-hours.test.ts @@ -7,7 +7,7 @@ describe('Utils test', () => { appId: 123, created: '2020-04-08T12:51:20.654Z', days: { - //8-12am, 2-4pm and 4-6pm UTC working hours + //8-12pm, 2-4pm and 4-6pm UTC working hours '0': '28800;43200;50400;57600;57600;64800;', '1': '28800;43200;50400;57600;57600;64800;', '2': '28800;43200;50400;57600;57600;64800;', From 800116703073e8220dd1452c313b0ee3dd8592d3 Mon Sep 17 00:00:00 2001 From: aishik-biswas Date: Fri, 17 Dec 2021 13:03:28 +0530 Subject: [PATCH 4/5] Publish - @freshworks-jaya/freshchat-api@0.7.28-alpha.1 - @freshworks-jaya/rule-engine@0.17.4-alpha.1 - @freshworks-jaya/utilities@0.2.9-alpha.1 --- packages/freshchat-api/package.json | 4 ++-- packages/rule-engine/package.json | 6 +++--- packages/utilities/package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/freshchat-api/package.json b/packages/freshchat-api/package.json index ed42329d..b7b18b90 100644 --- a/packages/freshchat-api/package.json +++ b/packages/freshchat-api/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/freshchat-api", - "version": "0.7.28-alpha.0", + "version": "0.7.28-alpha.1", "description": "Provides simple interface for accessing Freshchat's public APIs", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", @@ -43,7 +43,7 @@ "typescript": "^4.3.2" }, "dependencies": { - "@freshworks-jaya/utilities": "^0.2.9-alpha.0", + "@freshworks-jaya/utilities": "^0.2.9-alpha.1", "axios": "^0.21.4", "dayjs": "^1.10.5", "handlebars": "^4.7.7", diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index d09d47f0..2013a579 100644 --- a/packages/rule-engine/package.json +++ b/packages/rule-engine/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/rule-engine", - "version": "0.17.4-alpha.0", + "version": "0.17.4-alpha.1", "description": "Provides methods to process rules in product events in marketplace app", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", @@ -44,10 +44,10 @@ "typescript": "^4.3.2" }, "dependencies": { - "@freshworks-jaya/freshchat-api": "^0.7.28-alpha.0", + "@freshworks-jaya/freshchat-api": "^0.7.28-alpha.1", "@freshworks-jaya/kairos-api": "^0.1.5", "@freshworks-jaya/marketplace-models": "^0.1.14", - "@freshworks-jaya/utilities": "^0.2.9-alpha.0", + "@freshworks-jaya/utilities": "^0.2.9-alpha.1", "@google-cloud/logging": "^9.3.1", "axios": "^0.21.4", "bluebird": "^3.7.2", diff --git a/packages/utilities/package.json b/packages/utilities/package.json index 09517d1b..95f90cc5 100644 --- a/packages/utilities/package.json +++ b/packages/utilities/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/utilities", - "version": "0.2.9-alpha.0", + "version": "0.2.9-alpha.1", "description": "Provides a function that can replace placeholders in a string with a given map.", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", From 72b4922bc288b53c153f0c2bea82f9e59f9b6ab1 Mon Sep 17 00:00:00 2001 From: aishik-biswas Date: Fri, 17 Dec 2021 14:47:15 +0530 Subject: [PATCH 5/5] updates --- packages/utilities/src/is-outside-business-hours.ts | 9 +++------ .../utilities/test/is-outside-business-hours.test.ts | 4 ++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/utilities/src/is-outside-business-hours.ts b/packages/utilities/src/is-outside-business-hours.ts index 72d04254..5bfcdab2 100644 --- a/packages/utilities/src/is-outside-business-hours.ts +++ b/packages/utilities/src/is-outside-business-hours.ts @@ -43,12 +43,9 @@ const getWorkingHours = (data: string): string[][] => { */ const toTimeZone = (timeStamp: DateInput, preferredTimeZone: string): string => { if (timeStamp && preferredTimeZone) { - try { - const format = 'YYYY-MM-DD HH:mm:ss'; - return moment(timeStamp).tz(preferredTimeZone).format(format); - } catch (err) { - return ''; - } + const format = 'YYYY-MM-DD HH:mm:ss'; + const convertedTime = moment(timeStamp).tz(preferredTimeZone); + return convertedTime.isValid() ? convertedTime.format(format) : ''; } return ''; }; diff --git a/packages/utilities/test/is-outside-business-hours.test.ts b/packages/utilities/test/is-outside-business-hours.test.ts index 958af288..add25172 100644 --- a/packages/utilities/test/is-outside-business-hours.test.ts +++ b/packages/utilities/test/is-outside-business-hours.test.ts @@ -83,5 +83,9 @@ describe('Utils test', () => { const agentTime = 1586437800201; assert.equal(true, isOutsideBusinessHours(businessHour, agentTime)); }); + it('should go to the error block when wrong timestamp is provided', () => { + businessHour.enabled = true; + assert.equal(true, isOutsideBusinessHours(businessHour, 'agentTime' as unknown as number)); + }); }); });