@qrvey/utils 1.10.0-0 → 1.10.0-timezone-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/charts/adapters/endpointData.js +0 -3
  2. package/dist/cjs/charts/adapters/endpointData.js +0 -3
  3. package/dist/cjs/dates/adapters/ISOToNumericOffset.d.ts +6 -0
  4. package/dist/cjs/dates/adapters/ISOToNumericOffset.js +19 -0
  5. package/dist/cjs/dates/adapters/index.d.ts +2 -0
  6. package/dist/cjs/dates/adapters/index.js +2 -0
  7. package/dist/cjs/dates/adapters/numericOffsetToISO.d.ts +6 -0
  8. package/dist/cjs/dates/adapters/numericOffsetToISO.js +27 -0
  9. package/dist/cjs/dates/constants/ISO_8601_REGEX.d.ts +1 -0
  10. package/dist/cjs/dates/constants/ISO_8601_REGEX.js +4 -0
  11. package/dist/cjs/dates/constants/index.d.ts +1 -0
  12. package/dist/cjs/dates/constants/index.js +1 -0
  13. package/dist/cjs/dates/helpers/getDateByTimezone.d.ts +8 -0
  14. package/dist/cjs/dates/helpers/getDateByTimezone.js +39 -0
  15. package/dist/cjs/dates/helpers/getDateByTimezoneOffset.d.ts +7 -0
  16. package/dist/cjs/dates/helpers/getDateByTimezoneOffset.js +25 -0
  17. package/dist/cjs/dates/helpers/getTimezoneObject.d.ts +4 -0
  18. package/dist/cjs/dates/helpers/getTimezoneObject.js +24 -0
  19. package/dist/cjs/dates/helpers/index.d.ts +3 -1
  20. package/dist/cjs/dates/helpers/index.js +3 -1
  21. package/dist/cjs/dates/helpers/isValidISOOffset.d.ts +7 -0
  22. package/dist/cjs/dates/helpers/isValidISOOffset.js +17 -0
  23. package/dist/cjs/dates/interfaces/IDTimezone.d.ts +4 -0
  24. package/dist/cjs/dates/interfaces/IDTimezone.js +2 -0
  25. package/dist/cjs/dates/interfaces/IDTimezoneOffset.d.ts +1 -0
  26. package/dist/cjs/dates/interfaces/IDTimezoneOffset.js +2 -0
  27. package/dist/cjs/dates/interfaces/IGetDateByTimezoneSettings.d.ts +6 -0
  28. package/dist/cjs/dates/interfaces/IGetDateByTimezoneSettings.js +2 -0
  29. package/dist/cjs/dates/interfaces/index.d.ts +3 -0
  30. package/dist/cjs/dates/interfaces/index.js +3 -0
  31. package/dist/cjs/filters/helpers/builder/getFilterBuilderGeneralConfig.js +1 -1
  32. package/dist/cjs/filters/helpers/common/getFiltersByTimezone.d.ts +10 -0
  33. package/dist/cjs/filters/helpers/common/getFiltersByTimezone.js +26 -0
  34. package/dist/cjs/filters/helpers/common/index.d.ts +1 -0
  35. package/dist/cjs/filters/helpers/common/index.js +1 -0
  36. package/dist/cjs/filters/interfaces/ui/IFUTransformFilterValuesSettings.d.ts +6 -0
  37. package/dist/cjs/format/format.d.ts +1 -1
  38. package/dist/cjs/format/format.js +10 -4
  39. package/dist/cjs/general/index.d.ts +1 -0
  40. package/dist/cjs/general/index.js +1 -0
  41. package/dist/cjs/general/numeric/getSign.d.ts +6 -0
  42. package/dist/cjs/general/numeric/getSign.js +12 -0
  43. package/dist/cjs/general/numeric/index.d.ts +1 -0
  44. package/dist/cjs/general/numeric/index.js +17 -0
  45. package/dist/cjs/general/object/applyTimezoneDeep.d.ts +8 -0
  46. package/dist/cjs/general/object/applyTimezoneDeep.js +43 -0
  47. package/dist/cjs/general/object/index.d.ts +1 -0
  48. package/dist/cjs/general/object/index.js +1 -0
  49. package/dist/cjs/interfaces/format/IFormatConfig.Interface.d.ts +1 -0
  50. package/dist/cjs/interfaces/general/IWidgetConfig.d.ts +2 -1
  51. package/dist/cjs/qrvey/helpers/transformValue.js +34 -6
  52. package/dist/cjs/qrvey/interfaces/IBDataset.d.ts +2 -0
  53. package/dist/cjs/qrvey/interfaces/IBModel.d.ts +2 -0
  54. package/dist/cjs/qrvey/interfaces/IBTimezone.d.ts +4 -0
  55. package/dist/cjs/qrvey/interfaces/IBTimezone.js +2 -0
  56. package/dist/cjs/qrvey/interfaces/IDataset.d.ts +3 -1
  57. package/dist/cjs/qrvey/interfaces/IModel.d.ts +3 -1
  58. package/dist/cjs/qrvey/interfaces/ITransformValueSettings.d.ts +6 -0
  59. package/dist/cjs/qrvey/interfaces/index.d.ts +1 -0
  60. package/dist/cjs/qrvey/interfaces/index.js +1 -0
  61. package/dist/cjs/services/adapters/BDatasetsToUIDatasets.adapter.js +2 -0
  62. package/dist/cjs/services/adapters/BModelToUIModel.adapter.js +2 -0
  63. package/dist/cjs/services/adapters/BTimezoneToUITimezone.d.ts +3 -0
  64. package/dist/cjs/services/adapters/BTimezoneToUITimezone.js +9 -0
  65. package/dist/cjs/services/helpers/Request.d.ts +1 -1
  66. package/dist/cjs/services/helpers/Request.js +11 -5
  67. package/dist/dates/adapters/ISOToNumericOffset.d.ts +6 -0
  68. package/dist/dates/adapters/ISOToNumericOffset.js +15 -0
  69. package/dist/dates/adapters/index.d.ts +2 -0
  70. package/dist/dates/adapters/index.js +2 -0
  71. package/dist/dates/adapters/numericOffsetToISO.d.ts +6 -0
  72. package/dist/dates/adapters/numericOffsetToISO.js +23 -0
  73. package/dist/dates/constants/ISO_8601_REGEX.d.ts +1 -0
  74. package/dist/dates/constants/ISO_8601_REGEX.js +1 -0
  75. package/dist/dates/constants/index.d.ts +1 -0
  76. package/dist/dates/constants/index.js +1 -0
  77. package/dist/dates/helpers/getDateByTimezone.d.ts +8 -0
  78. package/dist/dates/helpers/getDateByTimezone.js +35 -0
  79. package/dist/dates/helpers/getDateByTimezoneOffset.d.ts +7 -0
  80. package/dist/dates/helpers/getDateByTimezoneOffset.js +21 -0
  81. package/dist/dates/helpers/getTimezoneObject.d.ts +4 -0
  82. package/dist/dates/helpers/getTimezoneObject.js +20 -0
  83. package/dist/dates/helpers/index.d.ts +3 -1
  84. package/dist/dates/helpers/index.js +3 -1
  85. package/dist/dates/helpers/isValidISOOffset.d.ts +7 -0
  86. package/dist/dates/helpers/isValidISOOffset.js +13 -0
  87. package/dist/dates/interfaces/IDTimezone.d.ts +4 -0
  88. package/dist/dates/interfaces/IDTimezone.js +1 -0
  89. package/dist/dates/interfaces/IDTimezoneOffset.d.ts +1 -0
  90. package/dist/dates/interfaces/IDTimezoneOffset.js +1 -0
  91. package/dist/dates/interfaces/IGetDateByTimezoneSettings.d.ts +6 -0
  92. package/dist/dates/interfaces/IGetDateByTimezoneSettings.js +1 -0
  93. package/dist/dates/interfaces/index.d.ts +3 -0
  94. package/dist/dates/interfaces/index.js +3 -0
  95. package/dist/filters/helpers/builder/getFilterBuilderGeneralConfig.js +1 -1
  96. package/dist/filters/helpers/common/getFiltersByTimezone.d.ts +10 -0
  97. package/dist/filters/helpers/common/getFiltersByTimezone.js +22 -0
  98. package/dist/filters/helpers/common/index.d.ts +1 -0
  99. package/dist/filters/helpers/common/index.js +1 -0
  100. package/dist/filters/interfaces/ui/IFUTransformFilterValuesSettings.d.ts +6 -0
  101. package/dist/format/format.d.ts +1 -1
  102. package/dist/format/format.js +10 -4
  103. package/dist/general/index.d.ts +1 -0
  104. package/dist/general/index.js +1 -0
  105. package/dist/general/numeric/getSign.d.ts +6 -0
  106. package/dist/general/numeric/getSign.js +8 -0
  107. package/dist/general/numeric/index.d.ts +1 -0
  108. package/dist/general/numeric/index.js +1 -0
  109. package/dist/general/object/applyTimezoneDeep.d.ts +8 -0
  110. package/dist/general/object/applyTimezoneDeep.js +39 -0
  111. package/dist/general/object/index.d.ts +1 -0
  112. package/dist/general/object/index.js +1 -0
  113. package/dist/interfaces/format/IFormatConfig.Interface.d.ts +1 -0
  114. package/dist/interfaces/general/IWidgetConfig.d.ts +2 -1
  115. package/dist/qrvey/helpers/transformValue.js +34 -6
  116. package/dist/qrvey/interfaces/IBDataset.d.ts +2 -0
  117. package/dist/qrvey/interfaces/IBModel.d.ts +2 -0
  118. package/dist/qrvey/interfaces/IBTimezone.d.ts +4 -0
  119. package/dist/qrvey/interfaces/IBTimezone.js +1 -0
  120. package/dist/qrvey/interfaces/IDataset.d.ts +3 -1
  121. package/dist/qrvey/interfaces/IModel.d.ts +3 -1
  122. package/dist/qrvey/interfaces/ITransformValueSettings.d.ts +6 -0
  123. package/dist/qrvey/interfaces/index.d.ts +1 -0
  124. package/dist/qrvey/interfaces/index.js +1 -0
  125. package/dist/services/adapters/BDatasetsToUIDatasets.adapter.js +2 -0
  126. package/dist/services/adapters/BModelToUIModel.adapter.js +2 -0
  127. package/dist/services/adapters/BTimezoneToUITimezone.d.ts +3 -0
  128. package/dist/services/adapters/BTimezoneToUITimezone.js +5 -0
  129. package/dist/services/helpers/Request.d.ts +1 -1
  130. package/dist/services/helpers/Request.js +11 -5
  131. package/package.json +5 -5
  132. package/dist/cjs/dates/helpers/adjustTimezone.d.ts +0 -6
  133. package/dist/cjs/dates/helpers/adjustTimezone.js +0 -19
  134. package/dist/dates/helpers/adjustTimezone.d.ts +0 -6
  135. package/dist/dates/helpers/adjustTimezone.js +0 -15
@@ -1,3 +1,6 @@
1
1
  export * from "./IDateFormat";
2
2
  export * from "./IDateGroupingProperty";
3
3
  export * from "./IDFDateToHmsSettings";
4
+ export * from "./IDTimezone";
5
+ export * from "./IDTimezoneOffset";
6
+ export * from "./IGetDateByTimezoneSettings";
@@ -1,3 +1,6 @@
1
1
  export * from "./IDateFormat";
2
2
  export * from "./IDateGroupingProperty";
3
3
  export * from "./IDFDateToHmsSettings";
4
+ export * from "./IDTimezone";
5
+ export * from "./IDTimezoneOffset";
6
+ export * from "./IGetDateByTimezoneSettings";
@@ -11,7 +11,7 @@ export function getFilterBuilderGeneralConfig(config = {}) {
11
11
  domain: config.domain,
12
12
  i18n: config.i18n,
13
13
  qv_token: config.qv_token,
14
- timezoneControl: getAttribute(config, "timezone_control") || config.timezoneControl,
14
+ timezone: config.timezone,
15
15
  userid: getAttribute(config, "user_id") || config.userid,
16
16
  };
17
17
  }
@@ -0,0 +1,10 @@
1
+ import { IDTimezone } from "../../../dates/interfaces/IDTimezone";
2
+ import { IFSData } from "../../interfaces/common/IFSData";
3
+ import { IFUData } from "../../interfaces/ui/IFUData";
4
+ /**
5
+ * Gets and transforms the Filter Data by the Timezone object
6
+ * @param {IFSData | IFUData} filterData the filter data
7
+ * @param {IDTimezone} timezone the timezone object
8
+ * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
9
+ */
10
+ export declare function getFiltersByTimezone(filterData: IFSData | IFUData, timezone: IDTimezone): IFUData | IFSData;
@@ -0,0 +1,22 @@
1
+ import { isEmpty } from "../../../general/mix/isEmpty";
2
+ import { transformFilterValues } from "../ui/transformFilterValues";
3
+ /**
4
+ * Gets and transforms the Filter Data by the Timezone object
5
+ * @param {IFSData | IFUData} filterData the filter data
6
+ * @param {IDTimezone} timezone the timezone object
7
+ * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
8
+ */
9
+ export function getFiltersByTimezone(filterData, timezone) {
10
+ if (isEmpty(filterData) ||
11
+ isEmpty(filterData.scopes) ||
12
+ !Array.isArray(filterData.scopes))
13
+ return filterData;
14
+ return Object.assign(Object.assign({}, filterData), { scopes: filterData.scopes.map((scope) => (Object.assign(Object.assign({}, scope), { datasets: scope.datasets.map((dataset) => (Object.assign(Object.assign({}, dataset), { filters: dataset.filters.map((filter) => (Object.assign(Object.assign({}, filter), { values: transformFilterValues(filter, {
15
+ timezone,
16
+ translate: undefined,
17
+ i18n: undefined,
18
+ noLocale: true,
19
+ noSuffix: true,
20
+ noTranslate: true,
21
+ }) }))) }))) }))) });
22
+ }
@@ -10,6 +10,7 @@ export * from "./getFiltersByDatasetsColumns";
10
10
  export * from "./getFiltersByParams";
11
11
  export * from "./getFiltersByScopes";
12
12
  export * from "./getFiltersByScopesIds";
13
+ export * from "./getFiltersByTimezone";
13
14
  export * from "./getFiltersByVisibility";
14
15
  export * from "./getMergeFiltersSettings";
15
16
  export * from "./getParamsToGetFilterSettings";
@@ -10,6 +10,7 @@ export * from "./getFiltersByDatasetsColumns";
10
10
  export * from "./getFiltersByParams";
11
11
  export * from "./getFiltersByScopes";
12
12
  export * from "./getFiltersByScopesIds";
13
+ export * from "./getFiltersByTimezone";
13
14
  export * from "./getFiltersByVisibility";
14
15
  export * from "./getMergeFiltersSettings";
15
16
  export * from "./getParamsToGetFilterSettings";
@@ -1,7 +1,13 @@
1
+ import { IDTimezone } from "../../../dates/interfaces/IDTimezone";
1
2
  import { II18nConfig } from "../../../globalization/interfaces/II18nConfig";
2
3
  import { II18nServiceTranslate } from "../../../globalization/interfaces/II18nServiceTranslate";
3
4
  export interface IFUTransformFilterValuesSettings {
5
+ timezone?: IDTimezone;
4
6
  translate: II18nServiceTranslate;
5
7
  i18n: II18nConfig;
6
8
  suffixTranslateLabel?: string;
9
+ noLocale?: boolean;
10
+ noTranslate?: boolean;
11
+ noSuffix?: boolean;
12
+ noTimezone?: boolean;
7
13
  }
@@ -1,5 +1,5 @@
1
1
  import { IFormatConfig } from "../interfaces/format/IFormatConfig.Interface";
2
- export declare function formatDate(dateString: any, format: any): any;
2
+ export declare function formatDate(dateString: any, format: any, offset: any): any;
3
3
  export declare function formatAbbreviated(num: any, decimals: any): any;
4
4
  /**
5
5
  * Set convert Bytes into MB
@@ -3,6 +3,7 @@ import dayjs from "dayjs";
3
3
  import { DATEGROUP_FORMATTING_UNSUPPORT, appliesFormatting, hasfileSizeProperty, isTextColumn, DEFAULT_DATE, } from "./definition";
4
4
  import isoWeek from "dayjs/plugin/isoWeek";
5
5
  import advancedFormat from "dayjs/plugin/advancedFormat";
6
+ import utc from "dayjs/plugin/utc";
6
7
  import { isEmpty } from "../general/mix/isEmpty";
7
8
  import { _get } from "../general/object/get";
8
9
  import { COLUMN } from "../columns/constants/COLUMN";
@@ -13,6 +14,7 @@ import { DURATION_PARTS_LIST } from "../column_format/constants/DURATION_PARTS_L
13
14
  import { cloneDeep } from "../general/object/cloneDeep";
14
15
  dayjs.extend(isoWeek); // Add support for iso week format https://github.com/iamkun/dayjs/issues/1328
15
16
  dayjs.extend(advancedFormat); // Add support to advanced formats https://day.js.org/docs/en/plugin/advanced-format
17
+ dayjs.extend(utc);
16
18
  /**
17
19
  * Apply to the given date format to a date value
18
20
  * @param bytes type number
@@ -21,7 +23,7 @@ function isValidDateString(dateString = "") {
21
23
  return (/^\d{2}\/\d{2}\/\d{4}/.test(dateString) || // MM/DD/YYY OR DD/MM/YYYY
22
24
  /^\d{4}-\d{2}-\d{2}/.test(dateString)); // YYYY-MM-DD
23
25
  }
24
- export function formatDate(dateString, format) {
26
+ export function formatDate(dateString, format, offset) {
25
27
  let _format = cloneDeep(format);
26
28
  if (isObject(format))
27
29
  _format = _format.format || "";
@@ -29,8 +31,12 @@ export function formatDate(dateString, format) {
29
31
  return dateString;
30
32
  if (!isValidDateString(dateString))
31
33
  return dateString;
32
- const dateValue = dateString === null || dateString === void 0 ? void 0 : dateString.replace(/Z$/i, "");
33
- return dayjs(dateValue.split(".")[0]).format(_format
34
+ const dateStringCleaned = dateString === null || dateString === void 0 ? void 0 : dateString.replace(/Z$/i, "");
35
+ const firstPartOfDateString = dayjs(dateStringCleaned.split(".")[0]);
36
+ const newDateValue = !isEmpty(offset)
37
+ ? firstPartOfDateString.utcOffset(offset)
38
+ : firstPartOfDateString;
39
+ return newDateValue.format(_format
34
40
  .replace("HH24:", "HH:")
35
41
  .replace("MI:SS", "mm:ss")
36
42
  .replace("MM:SS", "mm:ss"));
@@ -135,7 +141,7 @@ export const addFormat = (value, outputFormat = "None", config) => {
135
141
  : formatDate(value, (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Default" &&
136
142
  ((_c = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _c === void 0 ? void 0 : _c.format)
137
143
  ? (_d = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _d === void 0 ? void 0 : _d.format
138
- : outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format);
144
+ : outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format, config === null || config === void 0 ? void 0 : config.offset);
139
145
  case "NUMERIC": {
140
146
  const parse = parseFloat(value);
141
147
  const withLocale = (outputFormat !== "None" && (config === null || config === void 0 ? void 0 : config.lang)) ||
@@ -1,5 +1,6 @@
1
1
  export * from "./array/index";
2
2
  export * from "./function/index";
3
3
  export * from "./mix/index";
4
+ export * from "./numeric/index";
4
5
  export * from "./object/index";
5
6
  export * from "./string/index";
@@ -1,5 +1,6 @@
1
1
  export * from "./array/index";
2
2
  export * from "./function/index";
3
3
  export * from "./mix/index";
4
+ export * from "./numeric/index";
4
5
  export * from "./object/index";
5
6
  export * from "./string/index";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Gets the numeric sign of a given number
3
+ * @param {number} num the number
4
+ * @returns {string} an string with the sign
5
+ */
6
+ export declare function getSign(num: number): string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Gets the numeric sign of a given number
3
+ * @param {number} num the number
4
+ * @returns {string} an string with the sign
5
+ */
6
+ export function getSign(num) {
7
+ return Math.sign(num) > -1 ? "+" : "-";
8
+ }
@@ -0,0 +1 @@
1
+ export * from "./getSign";
@@ -0,0 +1 @@
1
+ export * from "./getSign";
@@ -0,0 +1,8 @@
1
+ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
2
+ /**
3
+ * Transforms the date+times propertiesof the given object by the Timezone object
4
+ * @param {any} obj the object
5
+ * @param {IDTimezone} timezone the timezone object
6
+ * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
7
+ */
8
+ export declare function applyTimezoneDeep(obj: any, timezone: IDTimezone): any;
@@ -0,0 +1,39 @@
1
+ import { DATE_FORMAT } from "../../dates/constants/DATE_FORMAT";
2
+ import { DATE_GROUPING_TIME_PROPERTY } from "../../dates/constants/DATE_GROUPING_TIME_PROPERTY";
3
+ import { getDateByTimezone } from "../../dates/helpers/getDateByTimezone";
4
+ import { validateDate } from "../../dates/helpers/validateDate";
5
+ import { isEmpty } from "../mix/isEmpty";
6
+ import { isObject } from "./isObject";
7
+ /**
8
+ * Transforms the date+times propertiesof the given object by the Timezone object
9
+ * @param {any} obj the object
10
+ * @param {IDTimezone} timezone the timezone object
11
+ * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
12
+ */
13
+ export function applyTimezoneDeep(obj, timezone) {
14
+ if (isEmpty(obj))
15
+ return obj;
16
+ const result = {};
17
+ try {
18
+ for (const i in obj) {
19
+ if (isObject(obj[i])) {
20
+ result[i] = applyTimezoneDeep(obj[i], timezone);
21
+ }
22
+ else if (obj[i] instanceof Date ||
23
+ !isNaN(obj[i]) ||
24
+ validateDate(obj[i], DATE_FORMAT.HOUR)) {
25
+ result[i] = getDateByTimezone(obj[i], {
26
+ property: DATE_GROUPING_TIME_PROPERTY.HOUR,
27
+ timezone,
28
+ });
29
+ }
30
+ else {
31
+ result[i] = obj[i];
32
+ }
33
+ }
34
+ return result;
35
+ }
36
+ catch (_a) {
37
+ return obj;
38
+ }
39
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./applyTimezoneDeep";
1
2
  export * from "./cloneDeep";
2
3
  export * from "./get";
3
4
  export * from "./getAttribute";
@@ -1,3 +1,4 @@
1
+ export * from "./applyTimezoneDeep";
1
2
  export * from "./cloneDeep";
2
3
  export * from "./get";
3
4
  export * from "./getAttribute";
@@ -1,5 +1,6 @@
1
1
  export interface IFormatConfig {
2
2
  lang?: string;
3
+ offset?: number;
3
4
  options?: object;
4
5
  isMultiplied?: boolean;
5
6
  }
@@ -1,3 +1,4 @@
1
+ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
1
2
  import { II18nConfig } from "../../globalization/interfaces/II18nConfig";
2
3
  export interface IWidgetConfig {
3
4
  appid?: string;
@@ -5,6 +6,6 @@ export interface IWidgetConfig {
5
6
  domain: string;
6
7
  i18n?: II18nConfig;
7
8
  qv_token?: string;
8
- timezoneControl?: string;
9
+ timezone?: IDTimezone;
9
10
  userid?: string;
10
11
  }
@@ -7,6 +7,7 @@ import { addFormat } from "../../format/format";
7
7
  import { isEmpty } from "../../general/mix/isEmpty";
8
8
  import { getI18nDateGroupLabel } from "../../globalization/helpers/getI18nDateGroupLabel";
9
9
  import { getValueWithSuffixes } from "./getValueWithSuffixes";
10
+ import { getDateByTimezone } from "../../dates/helpers/getDateByTimezone";
10
11
  /**
11
12
  * Transforms a value depending of localization/globalization and extras settings.
12
13
  * @param value A value to transform
@@ -16,12 +17,39 @@ import { getValueWithSuffixes } from "./getValueWithSuffixes";
16
17
  export function transformValue(value, settings) {
17
18
  if (isEmpty(value))
18
19
  return value;
19
- const valueWithI18n = getI18nDateGroupLabel(value, settings.property, settings.translate);
20
- const valueWithLocalization = addFormat(valueWithI18n, getOutputFormat(settings), getFormatConfig(settings));
21
- return getValueWithSuffixes(valueWithLocalization, {
22
- suffixTranslateLabel: settings.suffixTranslateLabel,
23
- translate: settings.translate,
24
- });
20
+ const defaultSettings = getDefaultSettings(settings);
21
+ let timezonedValue = value;
22
+ if (!defaultSettings.noTimezone) {
23
+ timezonedValue = getDateByTimezone(value, {
24
+ property: defaultSettings.property,
25
+ timezone: defaultSettings.timezone,
26
+ });
27
+ }
28
+ let valueWithI18n = timezonedValue;
29
+ if (!defaultSettings.noTranslate) {
30
+ valueWithI18n = getI18nDateGroupLabel(timezonedValue, defaultSettings.property, defaultSettings.translate);
31
+ }
32
+ let valueWithLocalization = valueWithI18n;
33
+ if (!defaultSettings.noLocale) {
34
+ valueWithLocalization = addFormat(valueWithI18n, getOutputFormat(settings), getFormatConfig(settings));
35
+ }
36
+ let valueWithSuffix = valueWithI18n;
37
+ if (!defaultSettings.noSuffix) {
38
+ valueWithSuffix = getValueWithSuffixes(valueWithLocalization, {
39
+ suffixTranslateLabel: defaultSettings.suffixTranslateLabel,
40
+ translate: defaultSettings.translate,
41
+ });
42
+ }
43
+ return valueWithSuffix;
44
+ }
45
+ /**
46
+ * Gets the default settings properties
47
+ * @param {ITransformValueSettings} settings the given settings
48
+ * @returns {ITransformValueSettings} the settings with default properties
49
+ */
50
+ function getDefaultSettings(settings) {
51
+ var _a, _b, _c, _d;
52
+ return Object.assign(Object.assign({}, settings), { noLocale: (_a = settings === null || settings === void 0 ? void 0 : settings.noLocale) !== null && _a !== void 0 ? _a : false, noSuffix: (_b = settings === null || settings === void 0 ? void 0 : settings.noSuffix) !== null && _b !== void 0 ? _b : false, noTimezone: (_c = settings === null || settings === void 0 ? void 0 : settings.noTimezone) !== null && _c !== void 0 ? _c : false, noTranslate: (_d = settings === null || settings === void 0 ? void 0 : settings.noTranslate) !== null && _d !== void 0 ? _d : false });
25
53
  }
26
54
  /**
27
55
  * Gets the outputformat settings
@@ -1,4 +1,5 @@
1
1
  import { IBColumn } from "../../columns/interfaces/IBColumn";
2
+ import { IBTimezone } from "./IBTimezone";
2
3
  /**
3
4
  * Structure for Dataset in the frontend side of Qrvey App
4
5
  */
@@ -7,4 +8,5 @@ export interface IBDataset {
7
8
  name?: string;
8
9
  options?: IBColumn[];
9
10
  qrveyid: string;
11
+ timezone?: IBTimezone;
10
12
  }
@@ -2,6 +2,7 @@ import { IAppStatus } from "./IAppStatus";
2
2
  import { IBModelBranchesMap } from "./IBModelBranchesMap";
3
3
  import { IBModelData } from "./IBModelData";
4
4
  import { IAppType } from "./IAppType";
5
+ import { IBTimezone } from "./IBTimezone";
5
6
  export interface IBModel {
6
7
  appType: IAppType;
7
8
  appid: string;
@@ -16,5 +17,6 @@ export interface IBModel {
16
17
  questionOrder: string[];
17
18
  questions: IBModelData;
18
19
  status: IAppStatus;
20
+ timezone: IBTimezone;
19
21
  userid: string;
20
22
  }
@@ -0,0 +1,4 @@
1
+ export interface IBTimezone {
2
+ numericOffset: number;
3
+ offset: string;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,9 +1,11 @@
1
1
  import { IColumn } from "../../columns/interfaces/IColumn";
2
+ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
2
3
  import { IBDataset } from "./IBDataset";
3
4
  /**
4
5
  * Structure for Dataset in the frontend side of Qrvey App
5
6
  */
6
- export interface IDataset extends Omit<IBDataset, "name" | "options"> {
7
+ export interface IDataset extends Omit<IBDataset, "name" | "options" | "timezone"> {
7
8
  label?: string;
8
9
  options?: IColumn[];
10
+ timezone?: IDTimezone;
9
11
  }
@@ -1,10 +1,12 @@
1
1
  import { IColumn } from "../../columns/interfaces/IColumn";
2
+ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
2
3
  import { IBModel } from "./IBModel";
3
4
  import { IModelBranchesMap } from "./IModelBranchesMap";
4
- export interface IModel extends Omit<IBModel, "questions" | "branchesMap" | "name" | "numResponses" | "questionOrder"> {
5
+ export interface IModel extends Omit<IBModel, "questions" | "branchesMap" | "name" | "numResponses" | "questionOrder" | "timezone"> {
5
6
  columns: IColumn[];
6
7
  columnOrder: string[];
7
8
  branchesMap: IModelBranchesMap[];
8
9
  label: string;
10
+ timezone: IDTimezone;
9
11
  totalRecords: number;
10
12
  }
@@ -1,11 +1,17 @@
1
1
  import { IColumn } from "../../columns/interfaces/IColumn";
2
2
  import { IColumnPropertyType } from "../../columns/interfaces/IColumnPropertyType";
3
+ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
3
4
  import { II18nConfig } from "../../globalization/interfaces/II18nConfig";
4
5
  import { II18nServiceTranslate } from "../../globalization/interfaces/II18nServiceTranslate";
5
6
  export interface ITransformValueSettings {
6
7
  column: IColumn;
7
8
  property: IColumnPropertyType;
9
+ timezone?: IDTimezone;
8
10
  translate: II18nServiceTranslate;
9
11
  i18n: II18nConfig;
10
12
  suffixTranslateLabel?: string;
13
+ noLocale?: boolean;
14
+ noTranslate?: boolean;
15
+ noSuffix?: boolean;
16
+ noTimezone?: boolean;
11
17
  }
@@ -4,6 +4,7 @@ export * from "./IBDataset";
4
4
  export * from "./IBModel";
5
5
  export * from "./IBModelBranchesMapBranch";
6
6
  export * from "./IBModelData";
7
+ export * from "./IBTimezone";
7
8
  export * from "./ICalculation";
8
9
  export * from "./ICalculationInfo";
9
10
  export * from "./ICalculationType";
@@ -4,6 +4,7 @@ export * from "./IBDataset";
4
4
  export * from "./IBModel";
5
5
  export * from "./IBModelBranchesMapBranch";
6
6
  export * from "./IBModelData";
7
+ export * from "./IBTimezone";
7
8
  export * from "./ICalculation";
8
9
  export * from "./ICalculationInfo";
9
10
  export * from "./ICalculationType";
@@ -1,9 +1,11 @@
1
1
  import { getAttribute } from "../../general/object/getAttribute";
2
2
  import { BColumnsToUIColumns } from "./BColumnsToUIColumns.adapter";
3
+ import { BTimezoneToUITimezone } from "./BTimezoneToUITimezone";
3
4
  export function BDatasetsToUIDatasets(datasets = []) {
4
5
  return datasets.map((dataset) => ({
5
6
  qrveyid: getAttribute(dataset, "qrvey_id"),
6
7
  label: dataset.name,
7
8
  options: BColumnsToUIColumns(dataset.options, dataset),
9
+ timezone: BTimezoneToUITimezone(dataset.timezone),
8
10
  }));
9
11
  }
@@ -1,6 +1,7 @@
1
1
  import { isEmpty } from "../../general/mix/isEmpty";
2
2
  import { BBranchesMapToUIBranchesMap } from "./BBranchesMapToUIBranchesMap.adapter";
3
3
  import { BColumnsToUIColumns } from "./BColumnsToUIColumns.adapter";
4
+ import { BTimezoneToUITimezone } from "./BTimezoneToUITimezone";
4
5
  export function BModelToUIModel(model) {
5
6
  if (isEmpty(model))
6
7
  return;
@@ -20,6 +21,7 @@ export function BModelToUIModel(model) {
20
21
  totalRecords: model.numResponses,
21
22
  qrveyid: model.qrveyid,
22
23
  status: model.status,
24
+ timezone: BTimezoneToUITimezone(model.timezone),
23
25
  userid: model.userid,
24
26
  };
25
27
  }
@@ -0,0 +1,3 @@
1
+ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
2
+ import { IBTimezone } from "../../qrvey/interfaces/IBTimezone";
3
+ export declare function BTimezoneToUITimezone(timezone: IBTimezone): IDTimezone;
@@ -0,0 +1,5 @@
1
+ export function BTimezoneToUITimezone(timezone) {
2
+ return {
3
+ offset: timezone.offset || timezone.numericOffset,
4
+ };
5
+ }
@@ -2,7 +2,7 @@ export default class Request {
2
2
  static checkStatus(response: any): Promise<any>;
3
3
  static hasQvToken(config: any): boolean;
4
4
  static getQvToken(config: any): any;
5
- static getTimezoneControl(config: any): any;
5
+ static getTimezoneOffset(config: any): string;
6
6
  static hasApiKey(config: any): boolean;
7
7
  static getApiKey(config: any): any;
8
8
  static makeUrl(config: any, url: any, params?: any): string;
@@ -7,6 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { numericOffsetToISO } from "../../dates/adapters/numericOffsetToISO";
11
+ import { isEmpty } from "../../general/mix/isEmpty";
10
12
  import { getAttribute } from "../../general/object/getAttribute";
11
13
  import { serialize } from "../../general/object/serialize";
12
14
  import { parseUrl } from "../../general/string/parseUrl";
@@ -24,8 +26,12 @@ export default class Request {
24
26
  static getQvToken(config) {
25
27
  return getAttribute(config, "qv_token");
26
28
  }
27
- static getTimezoneControl(config) {
28
- return getAttribute(config, "timezone_control");
29
+ static getTimezoneOffset(config) {
30
+ var _a;
31
+ const timezoneOffset = (_a = config.timezone) === null || _a === void 0 ? void 0 : _a.offset;
32
+ if (!isEmpty(timezoneOffset)) {
33
+ return numericOffsetToISO(timezoneOffset);
34
+ }
29
35
  }
30
36
  static hasApiKey(config) {
31
37
  return !!this.getApiKey(config);
@@ -68,9 +74,9 @@ export default class Request {
68
74
  cfg.credentials = "include";
69
75
  }
70
76
  }
71
- const timezoneControl = this.getTimezoneControl(reqData.config);
72
- if (timezoneControl) {
73
- cfg.headers["q-timezone-control"] = `offset=${timezoneControl};use-client-offset-only`;
77
+ const timezoneOffset = this.getTimezoneOffset(reqData.config);
78
+ if (timezoneOffset) {
79
+ cfg.headers["q-timezone-control"] = `offset=${timezoneOffset}`;
74
80
  }
75
81
  // AbortSignal (https://developers.google.com/web/updates/2017/09/abortable-fetch)
76
82
  if (reqData.config && reqData.config.signal) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.10.0-0",
3
+ "version": "1.10.0-timezone-1",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/index.js",
@@ -24,10 +24,10 @@
24
24
  "devDependencies": {
25
25
  "@types/jest": "29.4.0",
26
26
  "@types/responselike": "1.0.0",
27
- "@typescript-eslint/eslint-plugin": "5.49.0",
28
- "@typescript-eslint/parser": "5.49.0",
27
+ "@typescript-eslint/eslint-plugin": "5.50.0",
28
+ "@typescript-eslint/parser": "5.50.0",
29
29
  "auto-changelog": "2.4.0",
30
- "eslint": "8.32.0",
30
+ "eslint": "8.33.0",
31
31
  "eslint-config-prettier": "8.6.0",
32
32
  "eslint-plugin-prettier": "4.2.1",
33
33
  "husky": "8.0.3",
@@ -36,7 +36,7 @@
36
36
  "np": "7.6.3",
37
37
  "prettier": "2.8.3",
38
38
  "ts-jest": "29.0.5",
39
- "typescript": "4.9.4"
39
+ "typescript": "4.9.5"
40
40
  },
41
41
  "dependencies": {
42
42
  "d3-format": "2.0.0",
@@ -1,6 +0,0 @@
1
- /**
2
- * Adjusts a Date with the UTC-0 Timezone.
3
- * @param date String, object or millisencond number of the date
4
- * @returns updated Date object
5
- */
6
- export declare function adjustTimezone(date: string | Date | number): Date;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.adjustTimezone = void 0;
4
- const constants_1 = require("../constants");
5
- const isValidPotentialDate_1 = require("./isValidPotentialDate");
6
- const validateDate_1 = require("./validateDate");
7
- /**
8
- * Adjusts a Date with the UTC-0 Timezone.
9
- * @param date String, object or millisencond number of the date
10
- * @returns updated Date object
11
- */
12
- function adjustTimezone(date) {
13
- if (!(0, isValidPotentialDate_1.isValidPotentialDate)(date) ||
14
- (typeof date === "string" && !(0, validateDate_1.validateDate)(date, constants_1.DATE_FORMAT.DAY)))
15
- return date;
16
- const dt = new Date(date.valueOf());
17
- return new Date(+dt + dt.getTimezoneOffset() * 1000 * 60);
18
- }
19
- exports.adjustTimezone = adjustTimezone;
@@ -1,6 +0,0 @@
1
- /**
2
- * Adjusts a Date with the UTC-0 Timezone.
3
- * @param date String, object or millisencond number of the date
4
- * @returns updated Date object
5
- */
6
- export declare function adjustTimezone(date: string | Date | number): Date;
@@ -1,15 +0,0 @@
1
- import { DATE_FORMAT } from "../constants";
2
- import { isValidPotentialDate } from "./isValidPotentialDate";
3
- import { validateDate } from "./validateDate";
4
- /**
5
- * Adjusts a Date with the UTC-0 Timezone.
6
- * @param date String, object or millisencond number of the date
7
- * @returns updated Date object
8
- */
9
- export function adjustTimezone(date) {
10
- if (!isValidPotentialDate(date) ||
11
- (typeof date === "string" && !validateDate(date, DATE_FORMAT.DAY)))
12
- return date;
13
- const dt = new Date(date.valueOf());
14
- return new Date(+dt + dt.getTimezoneOffset() * 1000 * 60);
15
- }