@qrvey/utils 1.10.0-4 → 1.10.0-5

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.
@@ -3,6 +3,7 @@ import { IModel } from "../../qrvey/interfaces/IModel";
3
3
  import { IDTimezone } from "../interfaces/IDTimezone";
4
4
  /**
5
5
  * Gets the timezone object by the given argument or the model object
6
+ * - In any case, the offset is prioritized to override other properties.
6
7
  * @param {IDTimezone} timezone the timezone object
7
8
  * @param {IModel | IDataset} model the info of the dataset (model)
8
9
  * @returns a new timezone object
@@ -8,6 +8,7 @@ const getUTCFormatByOffset_1 = require("./getUTCFormatByOffset");
8
8
  const isValidISOOffset_1 = require("./isValidISOOffset");
9
9
  /**
10
10
  * Gets the timezone object by the given argument or the model object
11
+ * - In any case, the offset is prioritized to override other properties.
11
12
  * @param {IDTimezone} timezone the timezone object
12
13
  * @param {IModel | IDataset} model the info of the dataset (model)
13
14
  * @returns a new timezone object
@@ -24,6 +25,15 @@ function getTimezoneObject(timezone, model) {
24
25
  };
25
26
  }
26
27
  exports.getTimezoneObject = getTimezoneObject;
28
+ /**
29
+ * Gets the offset of the timezone by the given objects
30
+ * - Searchs the first argument
31
+ * - If the timezone is empty, in the model timezone is searched
32
+ * - If it does not exist in any, a default one is set.
33
+ * @param {IDTimezone} timezone The timezone object
34
+ * @param {IModel | IDataset} model The model info
35
+ * @returns {IDTimezoneOffset} the offset of the objects
36
+ */
27
37
  function getOffset(timezone, model) {
28
38
  var _a;
29
39
  let offset;
@@ -38,12 +48,26 @@ function getOffset(timezone, model) {
38
48
  }
39
49
  return offset;
40
50
  }
51
+ /**
52
+ * Gets the type of the timezone
53
+ * - Searchs the first argument
54
+ * - If it does not exist, asking for the timezone offset in order to prioritized the offset above all.
55
+ * - If the timezone is empty, in the model timezone is searched.
56
+ * - If it does not exist in any, a default one is set.
57
+ * @param {IDTimezone} timezone The timezone object
58
+ * @param {IModel | IDataset} model The model info
59
+ * @param {IDTimezoneOffset} offset a default offset if the validation are not satisfied
60
+ * @returns {IDTimezoneType} the rigth type of the timezone
61
+ */
41
62
  function getType(timezone, model, offset) {
42
63
  var _a;
43
64
  let type;
44
65
  if (!(0, isEmpty_1.isEmpty)(timezone === null || timezone === void 0 ? void 0 : timezone.type)) {
45
66
  type = timezone.type;
46
67
  }
68
+ else if (!(0, isEmpty_1.isEmpty)(timezone === null || timezone === void 0 ? void 0 : timezone.offset)) {
69
+ type = getTypeByOffset(timezone === null || timezone === void 0 ? void 0 : timezone.offset);
70
+ }
47
71
  else if (!(0, isEmpty_1.isEmpty)((_a = model === null || model === void 0 ? void 0 : model.timezone) === null || _a === void 0 ? void 0 : _a.type)) {
48
72
  type = model.timezone.type;
49
73
  }
@@ -52,6 +76,15 @@ function getType(timezone, model, offset) {
52
76
  }
53
77
  return type;
54
78
  }
79
+ /**
80
+ * Gets the type by a offset
81
+ * - For a offset=0 the type is default
82
+ * - For a offset="browser" the type is browser
83
+ * - For a valid offset different to previous ones, the type is fixed;
84
+ * - Anything else, it is considered default.
85
+ * @param {IDTimezoneOffset} offset a given offset
86
+ * @returns {IDTimezoneType} the right timezone type for the offset
87
+ */
55
88
  function getTypeByOffset(offset) {
56
89
  if (offset === "+00:00") {
57
90
  return TIMEZONE_TYPE_1.TIMEZONE_TYPE.DEFAULT;
@@ -64,6 +97,11 @@ function getTypeByOffset(offset) {
64
97
  }
65
98
  return TIMEZONE_TYPE_1.TIMEZONE_TYPE.DEFAULT;
66
99
  }
100
+ /**
101
+ * Gets the UTC string by the timezone object
102
+ * @param {IDTimezone} timezone the timezone object
103
+ * @returns {string} the label of the UTC value
104
+ */
67
105
  function getUTC(timezone) {
68
106
  return (0, getUTCFormatByOffset_1.getUTCFormatByOffset)(timezone);
69
107
  }
@@ -3,6 +3,7 @@ import { IModel } from "../../qrvey/interfaces/IModel";
3
3
  import { IDTimezone } from "../interfaces/IDTimezone";
4
4
  /**
5
5
  * Gets the timezone object by the given argument or the model object
6
+ * - In any case, the offset is prioritized to override other properties.
6
7
  * @param {IDTimezone} timezone the timezone object
7
8
  * @param {IModel | IDataset} model the info of the dataset (model)
8
9
  * @returns a new timezone object
@@ -5,6 +5,7 @@ import { getUTCFormatByOffset } from "./getUTCFormatByOffset";
5
5
  import { isValidISOOffset } from "./isValidISOOffset";
6
6
  /**
7
7
  * Gets the timezone object by the given argument or the model object
8
+ * - In any case, the offset is prioritized to override other properties.
8
9
  * @param {IDTimezone} timezone the timezone object
9
10
  * @param {IModel | IDataset} model the info of the dataset (model)
10
11
  * @returns a new timezone object
@@ -20,6 +21,15 @@ export function getTimezoneObject(timezone, model) {
20
21
  utc,
21
22
  };
22
23
  }
24
+ /**
25
+ * Gets the offset of the timezone by the given objects
26
+ * - Searchs the first argument
27
+ * - If the timezone is empty, in the model timezone is searched
28
+ * - If it does not exist in any, a default one is set.
29
+ * @param {IDTimezone} timezone The timezone object
30
+ * @param {IModel | IDataset} model The model info
31
+ * @returns {IDTimezoneOffset} the offset of the objects
32
+ */
23
33
  function getOffset(timezone, model) {
24
34
  var _a;
25
35
  let offset;
@@ -34,12 +44,26 @@ function getOffset(timezone, model) {
34
44
  }
35
45
  return offset;
36
46
  }
47
+ /**
48
+ * Gets the type of the timezone
49
+ * - Searchs the first argument
50
+ * - If it does not exist, asking for the timezone offset in order to prioritized the offset above all.
51
+ * - If the timezone is empty, in the model timezone is searched.
52
+ * - If it does not exist in any, a default one is set.
53
+ * @param {IDTimezone} timezone The timezone object
54
+ * @param {IModel | IDataset} model The model info
55
+ * @param {IDTimezoneOffset} offset a default offset if the validation are not satisfied
56
+ * @returns {IDTimezoneType} the rigth type of the timezone
57
+ */
37
58
  function getType(timezone, model, offset) {
38
59
  var _a;
39
60
  let type;
40
61
  if (!isEmpty(timezone === null || timezone === void 0 ? void 0 : timezone.type)) {
41
62
  type = timezone.type;
42
63
  }
64
+ else if (!isEmpty(timezone === null || timezone === void 0 ? void 0 : timezone.offset)) {
65
+ type = getTypeByOffset(timezone === null || timezone === void 0 ? void 0 : timezone.offset);
66
+ }
43
67
  else if (!isEmpty((_a = model === null || model === void 0 ? void 0 : model.timezone) === null || _a === void 0 ? void 0 : _a.type)) {
44
68
  type = model.timezone.type;
45
69
  }
@@ -48,6 +72,15 @@ function getType(timezone, model, offset) {
48
72
  }
49
73
  return type;
50
74
  }
75
+ /**
76
+ * Gets the type by a offset
77
+ * - For a offset=0 the type is default
78
+ * - For a offset="browser" the type is browser
79
+ * - For a valid offset different to previous ones, the type is fixed;
80
+ * - Anything else, it is considered default.
81
+ * @param {IDTimezoneOffset} offset a given offset
82
+ * @returns {IDTimezoneType} the right timezone type for the offset
83
+ */
51
84
  function getTypeByOffset(offset) {
52
85
  if (offset === "+00:00") {
53
86
  return TIMEZONE_TYPE.DEFAULT;
@@ -60,6 +93,11 @@ function getTypeByOffset(offset) {
60
93
  }
61
94
  return TIMEZONE_TYPE.DEFAULT;
62
95
  }
96
+ /**
97
+ * Gets the UTC string by the timezone object
98
+ * @param {IDTimezone} timezone the timezone object
99
+ * @returns {string} the label of the UTC value
100
+ */
63
101
  function getUTC(timezone) {
64
102
  return getUTCFormatByOffset(timezone);
65
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.10.0-4",
3
+ "version": "1.10.0-5",
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",