@qrvey/utils 1.10.0-timezone-2 → 1.10.0

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 (206) hide show
  1. package/README.md +1618 -952
  2. package/dist/cjs/columns/constants/COLUMN_PROPERTIES.d.ts +1 -1
  3. package/dist/cjs/columns/constants/COLUMN_PROPERTY_LABEL.d.ts +1 -0
  4. package/dist/cjs/columns/constants/COMPOUND_COLUMN_PROPERTY_LABEL.d.ts +1 -0
  5. package/dist/cjs/columns/constants/COMPOUND_COLUMN_PROPERTY_LABEL.js +1 -0
  6. package/dist/cjs/columns/helpers/isNumericalColumn.js +3 -1
  7. package/dist/cjs/dates/adapters/ISOToNumericOffset.js +6 -1
  8. package/dist/cjs/dates/adapters/dateToHms.js +5 -7
  9. package/dist/cjs/dates/adapters/dateToMdyDate.d.ts +2 -1
  10. package/dist/cjs/dates/adapters/dateToMdyDate.js +9 -3
  11. package/dist/cjs/dates/adapters/dateToMonthYear.d.ts +2 -1
  12. package/dist/cjs/dates/adapters/dateToMonthYear.js +6 -2
  13. package/dist/cjs/dates/adapters/dateToQuarterYear.d.ts +2 -1
  14. package/dist/cjs/dates/adapters/dateToQuarterYear.js +6 -2
  15. package/dist/cjs/dates/adapters/dateToWeekYear.d.ts +2 -1
  16. package/dist/cjs/dates/adapters/dateToWeekYear.js +6 -2
  17. package/dist/cjs/dates/adapters/dateToYear.d.ts +2 -1
  18. package/dist/cjs/dates/adapters/dateToYear.js +6 -2
  19. package/dist/cjs/dates/adapters/hmsToDate.d.ts +2 -1
  20. package/dist/cjs/dates/adapters/hmsToDate.js +6 -2
  21. package/dist/cjs/dates/adapters/mdyDateToDate.d.ts +2 -1
  22. package/dist/cjs/dates/adapters/mdyDateToDate.js +7 -2
  23. package/dist/cjs/dates/adapters/monthYearToDate.d.ts +2 -1
  24. package/dist/cjs/dates/adapters/monthYearToDate.js +6 -2
  25. package/dist/cjs/dates/adapters/numericOffsetToISO.d.ts +1 -1
  26. package/dist/cjs/dates/adapters/numericOffsetToISO.js +15 -8
  27. package/dist/cjs/dates/adapters/quarterYearToDate.d.ts +2 -1
  28. package/dist/cjs/dates/adapters/quarterYearToDate.js +6 -2
  29. package/dist/cjs/dates/adapters/weekYearToDate.d.ts +2 -1
  30. package/dist/cjs/dates/adapters/weekYearToDate.js +6 -2
  31. package/dist/cjs/dates/adapters/yearToDate.d.ts +2 -1
  32. package/dist/cjs/dates/adapters/yearToDate.js +6 -2
  33. package/dist/cjs/dates/constants/TIMEZONE_TYPE.d.ts +5 -0
  34. package/dist/cjs/dates/constants/TIMEZONE_TYPE.js +9 -0
  35. package/dist/cjs/dates/helpers/getDateByDateFormat.d.ts +2 -1
  36. package/dist/cjs/dates/helpers/getDateByDateFormat.js +6 -6
  37. package/dist/cjs/dates/helpers/getDateByTimezone.d.ts +3 -3
  38. package/dist/cjs/dates/helpers/getDateByTimezone.js +12 -27
  39. package/dist/cjs/dates/helpers/getDateByTimezoneOffset.d.ts +1 -1
  40. package/dist/cjs/dates/helpers/getDateByTimezoneOffset.js +14 -6
  41. package/dist/cjs/dates/helpers/getDefaultDateSettings.d.ts +7 -0
  42. package/dist/cjs/dates/helpers/getDefaultDateSettings.js +17 -0
  43. package/dist/cjs/dates/helpers/getFormattedDateByFormat.d.ts +2 -1
  44. package/dist/cjs/dates/helpers/getFormattedDateByFormat.js +7 -7
  45. package/dist/cjs/dates/helpers/getTimezoneObject.d.ts +8 -1
  46. package/dist/cjs/dates/helpers/getTimezoneObject.js +98 -14
  47. package/dist/cjs/dates/helpers/getTimezoneOffsetByType.d.ts +13 -0
  48. package/dist/cjs/dates/helpers/getTimezoneOffsetByType.js +27 -0
  49. package/dist/cjs/dates/helpers/getUTCFormatByOffset.d.ts +7 -0
  50. package/dist/cjs/dates/helpers/getUTCFormatByOffset.js +19 -0
  51. package/dist/cjs/dates/helpers/index.d.ts +4 -1
  52. package/dist/cjs/dates/helpers/index.js +4 -1
  53. package/dist/cjs/dates/helpers/isValidPotentialDate.d.ts +1 -0
  54. package/dist/cjs/dates/helpers/isValidPotentialDate.js +14 -5
  55. package/dist/cjs/dates/interfaces/IBTimezone.d.ts +7 -0
  56. package/dist/cjs/dates/interfaces/IBTimezoneType.d.ts +2 -0
  57. package/dist/cjs/dates/interfaces/IDFDateToHmsSettings.d.ts +2 -1
  58. package/dist/cjs/dates/interfaces/IDTimezone.d.ts +3 -0
  59. package/dist/cjs/dates/interfaces/IDTimezoneType.d.ts +2 -0
  60. package/dist/cjs/dates/interfaces/IDTimezoneType.js +2 -0
  61. package/dist/cjs/dates/interfaces/IDateSettings.d.ts +5 -0
  62. package/dist/cjs/dates/interfaces/IDateSettings.js +2 -0
  63. package/dist/cjs/dates/interfaces/index.d.ts +4 -1
  64. package/dist/cjs/dates/interfaces/index.js +4 -1
  65. package/dist/cjs/filters/services/Filters.api.js +1 -1
  66. package/dist/cjs/format/format.js +11 -0
  67. package/dist/cjs/format/localization.js +10 -1
  68. package/dist/cjs/general/array/getArrayByProperty.d.ts +1 -1
  69. package/dist/cjs/general/array/getUniqueArray.d.ts +1 -1
  70. package/dist/cjs/general/array/getUniqueArray.js +2 -0
  71. package/dist/cjs/general/mix/isEmpty.js +2 -0
  72. package/dist/cjs/general/mix/isNaNV2.d.ts +1 -0
  73. package/dist/cjs/general/mix/isNaNV2.js +7 -2
  74. package/dist/cjs/general/numeric/getSign.js +1 -1
  75. package/dist/cjs/general/object/applyTimezoneDeep.d.ts +1 -1
  76. package/dist/cjs/general/object/applyTimezoneDeep.js +10 -10
  77. package/dist/cjs/general/object/isObject.js +3 -1
  78. package/dist/cjs/general/object/mergeDeep.d.ts +6 -0
  79. package/dist/cjs/general/object/mergeDeep.js +12 -10
  80. package/dist/cjs/general/object/objectCopy.d.ts +1 -1
  81. package/dist/cjs/general/object/removeUndefinedDeep.js +6 -3
  82. package/dist/cjs/general/string/padLeadingZeros.d.ts +28 -1
  83. package/dist/cjs/general/string/padLeadingZeros.js +75 -7
  84. package/dist/cjs/globalization/interfaces/common/II18nColumnProperties.d.ts +1 -0
  85. package/dist/cjs/globalization/interfaces/dashboard/II18nDashboardToast.d.ts +1 -0
  86. package/dist/cjs/globalization/interfaces/dashboard/II18nDashboardTooltips.d.ts +1 -0
  87. package/dist/cjs/globalization/labels/common/I18N_COLUMN_PROPERTY_LABEL.js +1 -0
  88. package/dist/cjs/globalization/labels/dashboard/I18N_DASHBOARD.js +2 -0
  89. package/dist/cjs/globalization/labels/filters/I18N_RELATIVE_CONTAINER.js +1 -1
  90. package/dist/cjs/globalization/labels/formula_builder/I18N_FORMULA_BUILDER.js +5 -5
  91. package/dist/cjs/globalization/labels/panel/I18N_PANEL.js +1 -1
  92. package/dist/cjs/interfaces/format/IFormatConfig.Interface.d.ts +1 -1
  93. package/dist/cjs/qrvey/helpers/transformValue.js +35 -14
  94. package/dist/cjs/qrvey/interfaces/IBDataset.d.ts +1 -1
  95. package/dist/cjs/qrvey/interfaces/IBModel.d.ts +4 -1
  96. package/dist/cjs/qrvey/interfaces/index.d.ts +0 -1
  97. package/dist/cjs/qrvey/interfaces/index.js +0 -1
  98. package/dist/cjs/services/adapters/BTimezoneToUITimezone.d.ts +6 -1
  99. package/dist/cjs/services/adapters/BTimezoneToUITimezone.js +10 -1
  100. package/dist/columns/constants/COLUMN_PROPERTIES.d.ts +1 -1
  101. package/dist/columns/constants/COLUMN_PROPERTY_LABEL.d.ts +1 -0
  102. package/dist/columns/constants/COMPOUND_COLUMN_PROPERTY_LABEL.d.ts +1 -0
  103. package/dist/columns/constants/COMPOUND_COLUMN_PROPERTY_LABEL.js +1 -0
  104. package/dist/columns/helpers/isNumericalColumn.js +3 -1
  105. package/dist/dates/adapters/ISOToNumericOffset.js +6 -1
  106. package/dist/dates/adapters/dateToHms.js +5 -7
  107. package/dist/dates/adapters/dateToMdyDate.d.ts +2 -1
  108. package/dist/dates/adapters/dateToMdyDate.js +9 -3
  109. package/dist/dates/adapters/dateToMonthYear.d.ts +2 -1
  110. package/dist/dates/adapters/dateToMonthYear.js +6 -2
  111. package/dist/dates/adapters/dateToQuarterYear.d.ts +2 -1
  112. package/dist/dates/adapters/dateToQuarterYear.js +6 -2
  113. package/dist/dates/adapters/dateToWeekYear.d.ts +2 -1
  114. package/dist/dates/adapters/dateToWeekYear.js +6 -2
  115. package/dist/dates/adapters/dateToYear.d.ts +2 -1
  116. package/dist/dates/adapters/dateToYear.js +6 -2
  117. package/dist/dates/adapters/hmsToDate.d.ts +2 -1
  118. package/dist/dates/adapters/hmsToDate.js +6 -2
  119. package/dist/dates/adapters/mdyDateToDate.d.ts +2 -1
  120. package/dist/dates/adapters/mdyDateToDate.js +7 -2
  121. package/dist/dates/adapters/monthYearToDate.d.ts +2 -1
  122. package/dist/dates/adapters/monthYearToDate.js +6 -2
  123. package/dist/dates/adapters/numericOffsetToISO.d.ts +1 -1
  124. package/dist/dates/adapters/numericOffsetToISO.js +15 -8
  125. package/dist/dates/adapters/quarterYearToDate.d.ts +2 -1
  126. package/dist/dates/adapters/quarterYearToDate.js +6 -2
  127. package/dist/dates/adapters/weekYearToDate.d.ts +2 -1
  128. package/dist/dates/adapters/weekYearToDate.js +6 -2
  129. package/dist/dates/adapters/yearToDate.d.ts +2 -1
  130. package/dist/dates/adapters/yearToDate.js +6 -2
  131. package/dist/dates/constants/TIMEZONE_TYPE.d.ts +5 -0
  132. package/dist/dates/constants/TIMEZONE_TYPE.js +6 -0
  133. package/dist/dates/helpers/getDateByDateFormat.d.ts +2 -1
  134. package/dist/dates/helpers/getDateByDateFormat.js +6 -6
  135. package/dist/dates/helpers/getDateByTimezone.d.ts +3 -3
  136. package/dist/dates/helpers/getDateByTimezone.js +12 -27
  137. package/dist/dates/helpers/getDateByTimezoneOffset.d.ts +1 -1
  138. package/dist/dates/helpers/getDateByTimezoneOffset.js +11 -6
  139. package/dist/dates/helpers/getDefaultDateSettings.d.ts +7 -0
  140. package/dist/dates/helpers/getDefaultDateSettings.js +13 -0
  141. package/dist/dates/helpers/getFormattedDateByFormat.d.ts +2 -1
  142. package/dist/dates/helpers/getFormattedDateByFormat.js +7 -7
  143. package/dist/dates/helpers/getTimezoneObject.d.ts +8 -1
  144. package/dist/dates/helpers/getTimezoneObject.js +97 -13
  145. package/dist/dates/helpers/getTimezoneOffsetByType.d.ts +13 -0
  146. package/dist/dates/helpers/getTimezoneOffsetByType.js +23 -0
  147. package/dist/dates/helpers/getUTCFormatByOffset.d.ts +7 -0
  148. package/dist/dates/helpers/getUTCFormatByOffset.js +15 -0
  149. package/dist/dates/helpers/index.d.ts +4 -1
  150. package/dist/dates/helpers/index.js +4 -1
  151. package/dist/dates/helpers/isValidPotentialDate.d.ts +1 -0
  152. package/dist/dates/helpers/isValidPotentialDate.js +14 -5
  153. package/dist/dates/interfaces/IBTimezone.d.ts +7 -0
  154. package/dist/dates/interfaces/IBTimezoneType.d.ts +2 -0
  155. package/dist/dates/interfaces/IDFDateToHmsSettings.d.ts +2 -1
  156. package/dist/dates/interfaces/IDTimezone.d.ts +3 -0
  157. package/dist/dates/interfaces/IDTimezoneType.d.ts +2 -0
  158. package/dist/dates/interfaces/IDTimezoneType.js +1 -0
  159. package/dist/dates/interfaces/IDateSettings.d.ts +5 -0
  160. package/dist/dates/interfaces/IDateSettings.js +1 -0
  161. package/dist/dates/interfaces/index.d.ts +4 -1
  162. package/dist/dates/interfaces/index.js +4 -1
  163. package/dist/filters/services/Filters.api.js +1 -1
  164. package/dist/format/format.js +11 -0
  165. package/dist/format/localization.js +10 -1
  166. package/dist/general/array/getArrayByProperty.d.ts +1 -1
  167. package/dist/general/array/getUniqueArray.d.ts +1 -1
  168. package/dist/general/array/getUniqueArray.js +2 -0
  169. package/dist/general/mix/isEmpty.js +2 -0
  170. package/dist/general/mix/isNaNV2.d.ts +1 -0
  171. package/dist/general/mix/isNaNV2.js +7 -2
  172. package/dist/general/numeric/getSign.js +1 -1
  173. package/dist/general/object/applyTimezoneDeep.d.ts +1 -1
  174. package/dist/general/object/applyTimezoneDeep.js +10 -10
  175. package/dist/general/object/isObject.js +3 -1
  176. package/dist/general/object/mergeDeep.d.ts +6 -0
  177. package/dist/general/object/mergeDeep.js +12 -10
  178. package/dist/general/object/objectCopy.d.ts +1 -1
  179. package/dist/general/object/removeUndefinedDeep.js +6 -3
  180. package/dist/general/string/padLeadingZeros.d.ts +28 -1
  181. package/dist/general/string/padLeadingZeros.js +75 -7
  182. package/dist/globalization/interfaces/common/II18nColumnProperties.d.ts +1 -0
  183. package/dist/globalization/interfaces/dashboard/II18nDashboardToast.d.ts +1 -0
  184. package/dist/globalization/interfaces/dashboard/II18nDashboardTooltips.d.ts +1 -0
  185. package/dist/globalization/labels/common/I18N_COLUMN_PROPERTY_LABEL.js +1 -0
  186. package/dist/globalization/labels/dashboard/I18N_DASHBOARD.js +2 -0
  187. package/dist/globalization/labels/filters/I18N_RELATIVE_CONTAINER.js +1 -1
  188. package/dist/globalization/labels/formula_builder/I18N_FORMULA_BUILDER.js +5 -5
  189. package/dist/globalization/labels/panel/I18N_PANEL.js +1 -1
  190. package/dist/interfaces/format/IFormatConfig.Interface.d.ts +1 -1
  191. package/dist/qrvey/helpers/transformValue.js +35 -14
  192. package/dist/qrvey/interfaces/IBDataset.d.ts +1 -1
  193. package/dist/qrvey/interfaces/IBModel.d.ts +4 -1
  194. package/dist/qrvey/interfaces/index.d.ts +0 -1
  195. package/dist/qrvey/interfaces/index.js +0 -1
  196. package/dist/services/adapters/BTimezoneToUITimezone.d.ts +6 -1
  197. package/dist/services/adapters/BTimezoneToUITimezone.js +10 -1
  198. package/package.json +4 -3
  199. package/dist/cjs/dates/interfaces/IGetDateByTimezoneSettings.d.ts +0 -6
  200. package/dist/cjs/qrvey/interfaces/IBTimezone.d.ts +0 -4
  201. package/dist/dates/interfaces/IGetDateByTimezoneSettings.d.ts +0 -6
  202. package/dist/qrvey/interfaces/IBTimezone.d.ts +0 -4
  203. /package/dist/cjs/{qrvey → dates}/interfaces/IBTimezone.js +0 -0
  204. /package/dist/cjs/dates/interfaces/{IGetDateByTimezoneSettings.js → IBTimezoneType.js} +0 -0
  205. /package/dist/{qrvey → dates}/interfaces/IBTimezone.js +0 -0
  206. /package/dist/dates/interfaces/{IGetDateByTimezoneSettings.js → IBTimezoneType.js} +0 -0
@@ -23,5 +23,7 @@ export function isEmpty(variable, includeFalsy = false) {
23
23
  (!(variable instanceof Date) &&
24
24
  typeof variable !== "function" &&
25
25
  isObject(variable) &&
26
+ Object.entries(variable).length === 0) ||
27
+ (getTag(variable) === "[object NodeList]" &&
26
28
  Object.entries(variable).length === 0));
27
29
  }
@@ -8,6 +8,7 @@
8
8
  * Special case for isNaN
9
9
  * - The isNaN('') is considered as false statement. The empty string is converted to 0 which is not NaN.
10
10
  * - Boolean variables is considered as false statement.
11
+ * - Date objects is considered as true.
11
12
  *
12
13
  * @param variable the variable to validate
13
14
  * @return True: variable is a NaN; False: The variable is a number
@@ -1,4 +1,5 @@
1
- import { isEmpty } from ".";
1
+ import { isValidDateObject } from "../../dates/helpers/isValidDateObject";
2
+ import { isEmpty } from "./isEmpty";
2
3
  /**
3
4
  * Validates if the recieved number is NaN type.
4
5
  *
@@ -9,10 +10,14 @@ import { isEmpty } from ".";
9
10
  * Special case for isNaN
10
11
  * - The isNaN('') is considered as false statement. The empty string is converted to 0 which is not NaN.
11
12
  * - Boolean variables is considered as false statement.
13
+ * - Date objects is considered as true.
12
14
  *
13
15
  * @param variable the variable to validate
14
16
  * @return True: variable is a NaN; False: The variable is a number
15
17
  */
16
18
  export function isNaNV2(variable) {
17
- return isEmpty(variable) || typeof variable == "boolean" || isNaN(variable);
19
+ return (isEmpty(variable) ||
20
+ typeof variable == "boolean" ||
21
+ isNaN(variable) ||
22
+ isValidDateObject(variable));
18
23
  }
@@ -4,5 +4,5 @@
4
4
  * @returns {string} an string with the sign
5
5
  */
6
6
  export function getSign(num) {
7
- return Math.sign(num) > -1 ? "+" : "-";
7
+ return Math.sign(num) < 0 ? "-" : "+";
8
8
  }
@@ -5,4 +5,4 @@ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
5
5
  * @param {IDTimezone} timezone the timezone object
6
6
  * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
7
7
  */
8
- export declare function applyTimezoneDeep(obj: any, timezone: IDTimezone): any;
8
+ export declare function applyTimezoneDeep<T = any>(obj: T, timezone: IDTimezone): T;
@@ -1,6 +1,6 @@
1
1
  import { DATE_FORMAT } from "../../dates/constants/DATE_FORMAT";
2
- import { DATE_GROUPING_TIME_PROPERTY } from "../../dates/constants/DATE_GROUPING_TIME_PROPERTY";
3
2
  import { getDateByTimezone } from "../../dates/helpers/getDateByTimezone";
3
+ import { isValidDateObject } from "../../dates/helpers/isValidDateObject";
4
4
  import { validateDate } from "../../dates/helpers/validateDate";
5
5
  import { isEmpty } from "../mix/isEmpty";
6
6
  import { isObject } from "./isObject";
@@ -11,7 +11,7 @@ import { isObject } from "./isObject";
11
11
  * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
12
12
  */
13
13
  export function applyTimezoneDeep(obj, timezone) {
14
- if (isEmpty(obj))
14
+ if (!isValid(obj, timezone))
15
15
  return obj;
16
16
  let result;
17
17
  if (isObject(obj)) {
@@ -22,15 +22,12 @@ export function applyTimezoneDeep(obj, timezone) {
22
22
  }
23
23
  try {
24
24
  for (const i in obj) {
25
- if (isObject(obj[i]) || Array.isArray(obj[i])) {
26
- result[i] = applyTimezoneDeep(obj[i], timezone);
27
- }
28
- else if (obj[i] instanceof Date ||
25
+ if (isValidDateObject(obj[i]) ||
29
26
  validateDate(obj[i], DATE_FORMAT.HOUR)) {
30
- result[i] = getDateByTimezone(obj[i], {
31
- property: DATE_GROUPING_TIME_PROPERTY.HOUR,
32
- timezone,
33
- });
27
+ result[i] = getDateByTimezone(obj[i], timezone);
28
+ }
29
+ else if (isObject(obj[i]) || Array.isArray(obj[i])) {
30
+ result[i] = applyTimezoneDeep(obj[i], timezone);
34
31
  }
35
32
  else {
36
33
  result[i] = obj[i];
@@ -42,3 +39,6 @@ export function applyTimezoneDeep(obj, timezone) {
42
39
  return obj;
43
40
  }
44
41
  }
42
+ function isValid(obj, timezone) {
43
+ return (!isEmpty(obj) && (Array.isArray(obj) || isObject(obj)) && !isEmpty(timezone));
44
+ }
@@ -6,5 +6,7 @@ import { getTag } from "../mix/getTag";
6
6
  */
7
7
  export function isObject(obj) {
8
8
  return (!Array.isArray(obj) &&
9
- (obj === Object(obj) || getTag(obj) === "[object Object]"));
9
+ obj === Object(obj) &&
10
+ getTag(obj) !== "[object Function]" &&
11
+ (getTag(obj) === "[object Object]" || getTag(obj) === "[object Date]"));
10
12
  }
@@ -2,7 +2,13 @@
2
2
  * Settings structure of the Merge Deep helper
3
3
  */
4
4
  interface IMergeDeepSettings {
5
+ /**
6
+ * Merging properties that exists in object 2 but not in object 1
7
+ */
5
8
  mergeMissingProperties?: boolean;
9
+ /**
10
+ * Merging values on matched object properties. If false, the object 1 values remains as equal.
11
+ */
6
12
  mergeExistingValues?: boolean;
7
13
  }
8
14
  /**
@@ -12,22 +12,23 @@ export function mergeDeep(obj1, obj2, settings) {
12
12
  const defaultSettings = getParamsToMergeDeep(settings);
13
13
  if (!isValid(obj1, obj2))
14
14
  return objectCopy(obj1);
15
- const result = {};
15
+ const result = Array.isArray(obj1) ? [] : {};
16
16
  for (const i in obj1) {
17
- if (i != null && i in obj2 && isObject(obj1[i])) {
17
+ if (isObject(obj1[i]) || Array.isArray(obj1[i])) {
18
18
  result[i] = mergeDeep(obj1[i], obj2[i], defaultSettings);
19
19
  }
20
+ else if (i in obj2 && defaultSettings.mergeExistingValues) {
21
+ result[i] = obj2[i];
22
+ }
20
23
  else {
21
24
  result[i] = obj1[i];
22
25
  }
23
26
  }
24
- for (const i in obj2) {
25
- if (i != null &&
26
- ((!isObject(obj2[i]) &&
27
- i in result &&
28
- defaultSettings.mergeExistingValues) ||
29
- (!(i in result) && defaultSettings.mergeMissingProperties))) {
30
- result[i] = obj2[i];
27
+ if (defaultSettings.mergeMissingProperties) {
28
+ for (const i in obj2) {
29
+ if (!(i in result)) {
30
+ result[i] = obj2[i];
31
+ }
31
32
  }
32
33
  }
33
34
  return result;
@@ -39,7 +40,8 @@ export function mergeDeep(obj1, obj2, settings) {
39
40
  * @returns true: they are valid; false: they are not
40
41
  */
41
42
  function isValid(obj1, obj2) {
42
- return isObject(obj1) && isObject(obj2);
43
+ return ((isObject(obj1) && isObject(obj2)) ||
44
+ (Array.isArray(obj1) && Array.isArray(obj2)));
43
45
  }
44
46
  /**
45
47
  * Validates and gets the settings with all set parameters.
@@ -4,4 +4,4 @@
4
4
  * @param cache
5
5
  * @returns A new reference of the given argument
6
6
  */
7
- export declare function objectCopy(entity: any, cache?: WeakMap<object, any>): any;
7
+ export declare function objectCopy<T = any>(entity: T, cache?: WeakMap<object, any>): T;
@@ -1,14 +1,17 @@
1
- import { cloneDeep } from "./cloneDeep";
2
1
  import { isObject } from "./isObject";
2
+ import { objectCopy } from "./objectCopy";
3
3
  /**
4
4
  * Removes and returns the given object cleaning the undefined values
5
5
  * @param obj an object
6
6
  * @returns the new object with no undefined values
7
7
  */
8
8
  export function removeUndefinedDeep(obj) {
9
- if (obj == null || !isObject(obj) || !Array.isArray(obj))
9
+ const isArray = Array.isArray(obj);
10
+ if (obj == null || (!isObject(obj) && !isArray))
10
11
  return obj;
11
- const _obj = cloneDeep(obj);
12
+ let _obj = objectCopy(obj);
13
+ if (isArray)
14
+ _obj = _obj.filter(Boolean);
12
15
  Object.keys(_obj).forEach((key) => {
13
16
  if (isObject(_obj[key]) || Array.isArray(_obj[key])) {
14
17
  _obj[key] = removeUndefinedDeep(_obj[key]);
@@ -1 +1,28 @@
1
- export declare function padLeadingZeros(num: number | string, size?: number): string;
1
+ /**
2
+ * Sets an amount of zeros as prefix of the given number by its length
3
+ * @example
4
+ * num = 100
5
+ * size = 2
6
+ * padding = true
7
+ * => Returns "100"
8
+ * @example
9
+ * num = 100
10
+ * size = 5
11
+ * padding = true
12
+ * => Returns "00100"
13
+ * @example
14
+ * num = 100
15
+ * size = 2
16
+ * padding = false
17
+ * => Returns "00100"
18
+ * @example
19
+ * num = 100
20
+ * size = 5
21
+ * padding = false
22
+ * => Returns "00000100"
23
+ * @param {number | string} num the number
24
+ * @param {number} size the quantity of zeros to add
25
+ * @param {number} padding True: to pad with missing zeros; depending on the num length. False: to fill zeros by the amount.
26
+ * @returns the string of the number with the prefixed zeros
27
+ */
28
+ export declare function padLeadingZeros(num: number | string, amount?: number, padding?: boolean): string;
@@ -1,8 +1,76 @@
1
- export function padLeadingZeros(num, size = 0) {
2
- if (isNaN(Number(num)))
3
- return String(num);
4
- let s = `${num}`;
5
- while (s.length < size)
6
- s = `0${s}`;
7
- return s;
1
+ import { isEmpty } from "../mix";
2
+ import { isNaNV2 } from "../mix/isNaNV2";
3
+ import { getSign } from "../numeric/getSign";
4
+ /**
5
+ * Sets an amount of zeros as prefix of the given number by its length
6
+ * @example
7
+ * num = 100
8
+ * size = 2
9
+ * padding = true
10
+ * => Returns "100"
11
+ * @example
12
+ * num = 100
13
+ * size = 5
14
+ * padding = true
15
+ * => Returns "00100"
16
+ * @example
17
+ * num = 100
18
+ * size = 2
19
+ * padding = false
20
+ * => Returns "00100"
21
+ * @example
22
+ * num = 100
23
+ * size = 5
24
+ * padding = false
25
+ * => Returns "00000100"
26
+ * @param {number | string} num the number
27
+ * @param {number} size the quantity of zeros to add
28
+ * @param {number} padding True: to pad with missing zeros; depending on the num length. False: to fill zeros by the amount.
29
+ * @returns the string of the number with the prefixed zeros
30
+ */
31
+ export function padLeadingZeros(num, amount = 0, padding = true) {
32
+ if (isValidLeadingZerosParams(num, amount))
33
+ return num;
34
+ const newPadding = !isEmpty(padding, true);
35
+ const sign = getNumSign(num);
36
+ let absoluteStringNumber = getAbsoluteNum(num, sign);
37
+ if (newPadding) {
38
+ while (absoluteStringNumber.length < amount)
39
+ absoluteStringNumber = `0${absoluteStringNumber}`;
40
+ }
41
+ else {
42
+ let i = 0;
43
+ while (i < amount) {
44
+ absoluteStringNumber = `0${absoluteStringNumber}`;
45
+ i = i + 1;
46
+ }
47
+ }
48
+ return `${sign}${absoluteStringNumber}`;
49
+ }
50
+ function isValidLeadingZerosParams(num, amount) {
51
+ return isNaNV2(num) || isNaNV2(amount);
52
+ }
53
+ /**
54
+ * Gets the absolute number of the giving parameters
55
+ * @param {number | string} num the number
56
+ * @param {string} sign the sign of the number
57
+ * @returns {string} the absolute number
58
+ */
59
+ function getAbsoluteNum(num, sign = "") {
60
+ const stringNum = `${num}`;
61
+ return sign !== "" && `${stringNum}`.charAt(0) === sign
62
+ ? stringNum.substring(1)
63
+ : stringNum;
64
+ }
65
+ /**
66
+ * Gets the number sign
67
+ * @param {number | string} num the number
68
+ * @returns {string} the number sign
69
+ */
70
+ function getNumSign(num) {
71
+ const stringNum = `${num}`;
72
+ const sign = getSign(num);
73
+ if (stringNum.charAt(0) === sign)
74
+ return sign;
75
+ return "";
8
76
  }
@@ -42,6 +42,7 @@ export interface II18nColumnProperties {
42
42
  address_state_label: string;
43
43
  address_postal_code_label: string;
44
44
  address_country_label: string;
45
+ address_county_label: string;
45
46
  usaddress_address_line_1_label: string;
46
47
  usaddress_address_line_2_label: string;
47
48
  usaddress_city_label: string;
@@ -4,4 +4,5 @@ export interface II18nDashboardToast {
4
4
  add_record_message: string;
5
5
  data_views_updated_message: string;
6
6
  failed_download: string;
7
+ panels_loading: string;
7
8
  }
@@ -4,4 +4,5 @@ export interface II18nDashboardTooltips {
4
4
  buckets: string;
5
5
  download: string;
6
6
  embed_analyze: string;
7
+ histogram: string;
7
8
  }
@@ -43,6 +43,7 @@ export const I18N_COLUMN_PROPERTY_LABEL = {
43
43
  address_state_label: COLUMN_PROPERTY_LABEL.ADDRESS_STATE,
44
44
  address_postal_code_label: COLUMN_PROPERTY_LABEL.ADDRESS_POSTAL,
45
45
  address_country_label: COLUMN_PROPERTY_LABEL.ADDRESS_COUNTRY,
46
+ address_county_label: COLUMN_PROPERTY_LABEL.ADDRESS_COUNTY,
46
47
  usaddress_address_line_1_label: COLUMN_PROPERTY_LABEL.USADDRESS_LINE_1,
47
48
  usaddress_address_line_2_label: COLUMN_PROPERTY_LABEL.USADDRESS_LINE_2,
48
49
  usaddress_city_label: COLUMN_PROPERTY_LABEL.USADDRESS_CITY,
@@ -27,12 +27,14 @@ export const I18N_DASHBOARD = {
27
27
  delete_record_message: "Record Successfully Deleted.",
28
28
  refresh_table_message: "Record Successfully Edited.",
29
29
  failed_download: "The file(s) could not be exported at this time.",
30
+ panels_loading: "Visualizations are currently loading. Try exporting again once all visualizations have loaded properly.",
30
31
  },
31
32
  tooltips: {
32
33
  buckets: "Buckets",
33
34
  download: "Download",
34
35
  embed_analyze: "Embed Analyze View",
35
36
  formulas: "Formulas",
37
+ histogram: "Histogram",
36
38
  style_themes: "Style Themes",
37
39
  },
38
40
  views: {
@@ -10,5 +10,5 @@ export const I18N_RELATIVE_CONTAINER = {
10
10
  starting_date_tooltip: "The relative date will include the specific starting date and a period of time to show from that date onwards (Inclusive range). <br/> Unchecking this option will exclude the chosen starting date (exclusive range) from the date range.",
11
11
  starting_from: "Starting From",
12
12
  set_current_date: "Set to current date",
13
- utc_tooltip: "The times displayed are in UTC-0",
13
+ utc_tooltip: "The times displayed are in {{utc}}",
14
14
  };
@@ -338,7 +338,7 @@ export const I18N_FORMULA_BUILDER = {
338
338
  function_placeholder: "String.length()",
339
339
  },
340
340
  function_now: {
341
- description: "Return a date with the current time. Returned dates will have this format yyyy-MM-ddTHH:mm:ssZ.",
341
+ description: "Returns a date with the current time in the current timezone with the following format: yyyy-MM-ddTHH:mm:ss.",
342
342
  function_placeholder: "now()",
343
343
  },
344
344
  function_date_parse: {
@@ -359,7 +359,7 @@ export const I18N_FORMULA_BUILDER = {
359
359
  },
360
360
  function_date_add: {
361
361
  description: "Given a Date or a Column, add the specific value to the specific part.",
362
- function_placeholder: "dateAdd(date, date_part, interval_value)",
362
+ function_placeholder: "dateAdd(date, 'date_part', interval_value)",
363
363
  param_date_name: "date",
364
364
  param_date_description: "This is the Date or Column to which you want to add.",
365
365
  param_part_name: "date_part",
@@ -369,7 +369,7 @@ export const I18N_FORMULA_BUILDER = {
369
369
  },
370
370
  function_date_subtract: {
371
371
  description: "Given a Date or a Column, subtract the specific value to the specific part.",
372
- function_placeholder: "dateSubtract(date, date_part, interval_value)",
372
+ function_placeholder: "dateSubtract(date, 'date_part', interval_value)",
373
373
  param_date_name: "date",
374
374
  param_date_description: "This is the Date or Column to which you want to subtract.",
375
375
  param_part_name: "date_part",
@@ -379,7 +379,7 @@ export const I18N_FORMULA_BUILDER = {
379
379
  },
380
380
  function_date_diff: {
381
381
  description: "Calculates the difference between two dates based on the date part requested.",
382
- function_placeholder: "dateDiff(date_value1, date_value2, date_part)",
382
+ function_placeholder: "dateDiff(date_value1, date_value2, 'date_part')",
383
383
  param_date_value_one_name: "date_value1",
384
384
  param_date_value_one_description: "The first date value.",
385
385
  param_date_value_two_name: "date_value2",
@@ -393,7 +393,7 @@ export const I18N_FORMULA_BUILDER = {
393
393
  param_column_name: "column",
394
394
  param_column_description: "Date column to check.",
395
395
  param_replacement_name: "replacement",
396
- param_replacement_description: 'Date replacement value.<br>Common Replacement Value Formats:<br>○ Using another date column "dateIsNull(Column1, Column2)"<br>○ Using another date function "dateIsNull(Column, now())"<br>○ Using specified date "dateIsNull(Column, dateParse(\'dd/MM/yyyy\', \'dd/MM/yyyy\'))"',
396
+ param_replacement_description: 'Date replacement value.<br>Common Replacement Value Formats:<br>○ Using another date column "dateIsNull(Column1, Column2)"<br>○ Using another date function "dateIsNull(Column, now())"<br>○ Using specified date "dateIsNull(Column, dateParse(\'31/12/2021\', \'dd/MM/yyyy\'))"',
397
397
  },
398
398
  function_agg_sum: {
399
399
  description: "A single-value metrics aggregation that sums up numeric values that are extracted from the documents",
@@ -15,7 +15,7 @@ export const I18N_PANEL = {
15
15
  invalid_data_for_chart: "No valid data for this chart",
16
16
  longer_available_panel: "This panel is no longer available",
17
17
  long_text: "long-text",
18
- max_buckets_limit: "The combination of data used in this chart exceeds the maximum number of data points that the system can return.<br><br>We recommend you try:<br>• Refining your data with <i>Max Data Points</i> or <i>Filters</i><br>• Using a <i>Date Grouping</i> that returns less data<br>• Using another chart visualization",
18
+ max_buckets_limit: "The combination of data used in this chart exceeds the maximum number of aggregation buckets allowed in a single response.<br><br>To fix this issue, try the following:<br>• <i>Filter</i> your data<br>• Apply a <i>Date Grouping</i> that returns less data<br>• Use another chart visualization",
19
19
  missing_column: "Missing Column.",
20
20
  missing_bucket_column: "Missing bucket column.",
21
21
  missing_formula_column: "Missing formula column.",
@@ -1,6 +1,6 @@
1
1
  export interface IFormatConfig {
2
2
  lang?: string;
3
- offset?: number;
3
+ offset?: number | string;
4
4
  options?: object;
5
5
  isMultiplied?: boolean;
6
6
  }
@@ -20,10 +20,7 @@ export function transformValue(value, settings) {
20
20
  const defaultSettings = getDefaultSettings(settings);
21
21
  let timezonedValue = value;
22
22
  if (!defaultSettings.noTimezone) {
23
- timezonedValue = getDateByTimezone(value, {
24
- property: defaultSettings.property,
25
- timezone: defaultSettings.timezone,
26
- });
23
+ timezonedValue = getDateByTimezone(value, defaultSettings.timezone);
27
24
  }
28
25
  let valueWithI18n = timezonedValue;
29
26
  if (!defaultSettings.noTranslate) {
@@ -57,18 +54,14 @@ function getDefaultSettings(settings) {
57
54
  * @returns the outputformat settings
58
55
  */
59
56
  function getOutputFormat(settings) {
60
- var _a, _b;
61
- let type, format, decimals;
62
- const isDateTime = [
63
- DATE_GROUPING_TIME_PROPERTY.HOUR,
64
- DATE_GROUPING_TIME_PROPERTY.MINUTE,
65
- DATE_GROUPING_TIME_PROPERTY.SECOND,
66
- undefined,
67
- ].includes(settings.property);
57
+ var _a;
58
+ let type, format, decimals, originalFormat;
59
+ const isDateTime = isDateWithTime(settings.property);
68
60
  const isDate = [DATE_GROUPING_PROPERTY.DAY, undefined].includes(settings.property);
69
61
  if (isDateColumn(settings.column) && (isDate || isDateTime)) {
70
62
  type = "DATE";
71
63
  format = "Default";
64
+ originalFormat = getOutputFormatByPoperty(settings);
72
65
  }
73
66
  else if (settings.column.type === COLUMN.TIME) {
74
67
  type = "TIME";
@@ -77,13 +70,13 @@ function getOutputFormat(settings) {
77
70
  else if (isNumericalColumn(settings.column)) {
78
71
  type = "NUMERIC";
79
72
  format = "Default";
80
- decimals = (_b = (_a = settings === null || settings === void 0 ? void 0 : settings.column) === null || _a === void 0 ? void 0 : _a.outputFormat) === null || _b === void 0 ? void 0 : _b.decimals;
73
+ decimals = (_a = settings.column.outputFormat) === null || _a === void 0 ? void 0 : _a.decimals;
81
74
  }
82
75
  return {
83
76
  type,
84
77
  format,
85
78
  decimals,
86
- originalFormat: isDateTime ? settings.column.outputFormat : undefined,
79
+ originalFormat,
87
80
  };
88
81
  }
89
82
  /**
@@ -95,3 +88,31 @@ function getFormatConfig(settings) {
95
88
  var _a, _b;
96
89
  return ((_a = settings.i18n) === null || _a === void 0 ? void 0 : _a.locale) && { lang: (_b = settings.i18n) === null || _b === void 0 ? void 0 : _b.locale };
97
90
  }
91
+ /**
92
+ * If the property is a day, return the date format without the time, otherwise return the original
93
+ * format.
94
+ * @param {ITransformValueSettings} settings - ITransformValueSettings
95
+ * @returns The outputFormat of the column.
96
+ */
97
+ function getOutputFormatByPoperty(settings) {
98
+ var _a;
99
+ if (settings.property === DATE_GROUPING_PROPERTY.DAY) {
100
+ return Object.assign(Object.assign({}, settings.column.outputFormat), { format: (_a = settings.column.outputFormat) === null || _a === void 0 ? void 0 : _a.format.split(" ")[0] });
101
+ }
102
+ else if (isDateWithTime(settings.property))
103
+ return settings.column.outputFormat;
104
+ }
105
+ /**
106
+ * Get the format related to the columnn property.
107
+ * If the property is hour, minute, second, or undefined, return true.
108
+ * @param {IColumnPropertyType} property - The property of the date to group by.
109
+ * @returns {boolean} A boolean value.
110
+ */
111
+ function isDateWithTime(property) {
112
+ return [
113
+ DATE_GROUPING_TIME_PROPERTY.HOUR,
114
+ DATE_GROUPING_TIME_PROPERTY.MINUTE,
115
+ DATE_GROUPING_TIME_PROPERTY.SECOND,
116
+ undefined,
117
+ ].includes(property);
118
+ }
@@ -1,5 +1,5 @@
1
1
  import { IBColumn } from "../../columns/interfaces/IBColumn";
2
- import { IBTimezone } from "./IBTimezone";
2
+ import { IBTimezone } from "../../dates/interfaces/IBTimezone";
3
3
  /**
4
4
  * Structure for Dataset in the frontend side of Qrvey App
5
5
  */
@@ -2,12 +2,15 @@ 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
+ import { IBTimezone } from "../../dates/interfaces/IBTimezone";
6
6
  export interface IBModel {
7
7
  appType: IAppType;
8
8
  appid: string;
9
9
  branchesMap?: IBModelBranchesMap[];
10
10
  createDate: string;
11
+ /**
12
+ * @deprecated Data Link feature is not longer supported
13
+ */
11
14
  datalinkInfo?: any[];
12
15
  geoGroups?: any[];
13
16
  modifyDate: string;
@@ -4,7 +4,6 @@ export * from "./IBDataset";
4
4
  export * from "./IBModel";
5
5
  export * from "./IBModelBranchesMapBranch";
6
6
  export * from "./IBModelData";
7
- export * from "./IBTimezone";
8
7
  export * from "./ICalculation";
9
8
  export * from "./ICalculationInfo";
10
9
  export * from "./ICalculationType";
@@ -4,7 +4,6 @@ export * from "./IBDataset";
4
4
  export * from "./IBModel";
5
5
  export * from "./IBModelBranchesMapBranch";
6
6
  export * from "./IBModelData";
7
- export * from "./IBTimezone";
8
7
  export * from "./ICalculation";
9
8
  export * from "./ICalculationInfo";
10
9
  export * from "./ICalculationType";
@@ -1,3 +1,8 @@
1
1
  import { IDTimezone } from "../../dates/interfaces/IDTimezone";
2
- import { IBTimezone } from "../../qrvey/interfaces/IBTimezone";
2
+ import { IBTimezone } from "../../dates/interfaces/IBTimezone";
3
+ /**
4
+ * Transforms the backenc timezone structure to UI timezone structure
5
+ * @param {IBTimezone} timezone the backend timezone object
6
+ * @returns {IDTimezone} the UI timezone object
7
+ */
3
8
  export declare function BTimezoneToUITimezone(timezone: IBTimezone): IDTimezone;
@@ -1,5 +1,14 @@
1
+ import { TIMEZONE_TYPE } from "../../dates/constants/TIMEZONE_TYPE";
2
+ import { getTimezoneOffsetByType } from "../../dates/helpers/getTimezoneOffsetByType";
3
+ /**
4
+ * Transforms the backenc timezone structure to UI timezone structure
5
+ * @param {IBTimezone} timezone the backend timezone object
6
+ * @returns {IDTimezone} the UI timezone object
7
+ */
1
8
  export function BTimezoneToUITimezone(timezone) {
9
+ const type = (timezone === null || timezone === void 0 ? void 0 : timezone.type) || TIMEZONE_TYPE.DEFAULT;
2
10
  return {
3
- offset: timezone.offset || timezone.numericOffset,
11
+ type,
12
+ offset: getTimezoneOffsetByType(Object.assign(Object.assign({}, timezone), { type })),
4
13
  };
5
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.10.0-timezone-2",
3
+ "version": "1.10.0",
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",
@@ -15,8 +15,9 @@
15
15
  "publishing.beta.1": "node ./scripts/publishing --np-new-version=$npm_config_np_new_version --np-any-branch=$npm_config_np_any_branch --np-tag=$npm_config_np_tag",
16
16
  "publishing": "node ./scripts/clean-build && np $npm_config_np_new_version --any-branch --tag=$npm_config_np_tag",
17
17
  "publishing.win": "node ./scripts/clean-build && np %npm_config_np_new_version% --any-branch --tag=%npm_config_np_tag%",
18
- "test": "jest test",
19
- "test.watch": "jest --watch test",
18
+ "test": "jest test --verbose",
19
+ "test.coverage": "jest test --collect-coverage",
20
+ "test.watch": "jest test --watch ",
20
21
  "version": "auto-changelog -p && git add CHANGELOG.md"
21
22
  },
22
23
  "author": "Qrvey Inc",
@@ -1,6 +0,0 @@
1
- import { IColumnPropertyType } from "../../columns/interfaces/IColumnPropertyType";
2
- import { IDTimezone } from "./IDTimezone";
3
- export interface IGetDateByTimezoneSettings {
4
- property: IColumnPropertyType;
5
- timezone: IDTimezone;
6
- }
@@ -1,4 +0,0 @@
1
- export interface IBTimezone {
2
- numericOffset: number;
3
- offset: string;
4
- }
@@ -1,6 +0,0 @@
1
- import { IColumnPropertyType } from "../../columns/interfaces/IColumnPropertyType";
2
- import { IDTimezone } from "./IDTimezone";
3
- export interface IGetDateByTimezoneSettings {
4
- property: IColumnPropertyType;
5
- timezone: IDTimezone;
6
- }
@@ -1,4 +0,0 @@
1
- export interface IBTimezone {
2
- numericOffset: number;
3
- offset: string;
4
- }