@qrvey/utils 1.6.0-4 → 1.6.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.
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.adjustTimezone = void 0;
4
+ const constants_1 = require("../constants");
5
+ const isValidPotentialDate_1 = require("./isValidPotentialDate");
6
+ const validateDate_1 = require("./validateDate");
4
7
  /**
5
8
  * Adjusts a Date with the UTC-0 Timezone.
6
9
  * @param date String, object or millisencond number of the date
7
10
  * @returns updated Date object
8
11
  */
9
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;
10
16
  const dt = new Date(date.valueOf());
11
17
  return new Date(+dt + dt.getTimezoneOffset() * 1000 * 60);
12
18
  }
@@ -11,7 +11,7 @@ const isTokenLabel_1 = require("../../tokens/isTokenLabel");
11
11
  function isValidPotentialDate(date) {
12
12
  return (!(0, isEmpty_1.isEmpty)(date) &&
13
13
  !(0, isTokenLabel_1.isTokenLabel)(date) &&
14
- (date instanceof Date ||
14
+ ((date instanceof Date && !isNaN(date)) ||
15
15
  typeof date === "string" ||
16
16
  typeof date === "number"));
17
17
  }
@@ -1,9 +1,15 @@
1
+ import { DATE_FORMAT } from "../constants";
2
+ import { isValidPotentialDate } from "./isValidPotentialDate";
3
+ import { validateDate } from "./validateDate";
1
4
  /**
2
5
  * Adjusts a Date with the UTC-0 Timezone.
3
6
  * @param date String, object or millisencond number of the date
4
7
  * @returns updated Date object
5
8
  */
6
9
  export function adjustTimezone(date) {
10
+ if (!isValidPotentialDate(date) ||
11
+ (typeof date === "string" && !validateDate(date, DATE_FORMAT.DAY)))
12
+ return date;
7
13
  const dt = new Date(date.valueOf());
8
14
  return new Date(+dt + dt.getTimezoneOffset() * 1000 * 60);
9
15
  }
@@ -8,7 +8,7 @@ import { isTokenLabel } from "../../tokens/isTokenLabel";
8
8
  export function isValidPotentialDate(date) {
9
9
  return (!isEmpty(date) &&
10
10
  !isTokenLabel(date) &&
11
- (date instanceof Date ||
11
+ ((date instanceof Date && !isNaN(date)) ||
12
12
  typeof date === "string" ||
13
13
  typeof date === "number"));
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.6.0-4",
3
+ "version": "1.6.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",