From 02e6569a48bb3986373373875b8adc59e1c755c0 Mon Sep 17 00:00:00 2001 From: Flavius Lacatusu Date: Tue, 27 Jun 2023 19:53:43 +0200 Subject: [PATCH] Return country as a string instead of array Signed-off-by: Flavius Lacatusu --- src/hooks/analytics/segment-adapter.ts | 11 ++++++++++- yarn.lock | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/hooks/analytics/segment-adapter.ts b/src/hooks/analytics/segment-adapter.ts index f71861840..322eb0316 100644 --- a/src/hooks/analytics/segment-adapter.ts +++ b/src/hooks/analytics/segment-adapter.ts @@ -138,7 +138,7 @@ export class SegmentAdapter { version: os.release(), }, location: { - country: getTimezone(Intl.DateTimeFormat().resolvedOptions().timeZone)?.countries || 'XX', + country: this.getCountry(Intl.DateTimeFormat().resolvedOptions().timeZone), }, timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, } @@ -155,4 +155,13 @@ export class SegmentAdapter { } return } + + private getCountry(timeZone: string): string { + const tz = getTimezone(timeZone) + if (tz && tz?.countries) { + return tz.countries[0] + } + // Probably UTC timezone + return 'ZZ' // Unknown country + } } diff --git a/yarn.lock b/yarn.lock index bed5556ca..518038c71 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2463,7 +2463,7 @@ detect-newline@^3.0.0: "devworkspace-operator@https://github.com/devfile/devworkspace-operator#main": version "0.0.0" - resolved "https://github.com/devfile/devworkspace-operator#d0c5346f9440e2d05867035646394c53fedafec3" + resolved "https://github.com/devfile/devworkspace-operator#8d54b6304319cc3382d1c0a52d7571b03584c844" diff-sequences@^29.4.2: version "29.4.2" @@ -2506,7 +2506,7 @@ ecc-jsbn@~0.1.1: "eclipse-che-operator@https://github.com/eclipse-che/che-operator#main": version "0.0.0" - resolved "https://github.com/eclipse-che/che-operator#109d3c2ce1f996997d6243b963dd27516aeab851" + resolved "https://github.com/eclipse-che/che-operator#411821f612b6aeb2796e52d16b201b06b83e096f" editorconfig@^0.15.0: version "0.15.3"