@qrvey/utils 1.10.0-7 → 1.10.0-9

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 (89) hide show
  1. package/dist/cjs/columns/constants/COLUMN_PROPERTIES.d.ts +1 -1
  2. package/dist/cjs/dates/adapters/dateToHms.js +8 -10
  3. package/dist/cjs/dates/adapters/dateToMdyDate.d.ts +2 -1
  4. package/dist/cjs/dates/adapters/dateToMdyDate.js +9 -3
  5. package/dist/cjs/dates/adapters/dateToMonthYear.d.ts +2 -1
  6. package/dist/cjs/dates/adapters/dateToMonthYear.js +7 -3
  7. package/dist/cjs/dates/adapters/dateToQuarterYear.d.ts +2 -1
  8. package/dist/cjs/dates/adapters/dateToQuarterYear.js +8 -4
  9. package/dist/cjs/dates/adapters/dateToWeekYear.d.ts +2 -1
  10. package/dist/cjs/dates/adapters/dateToWeekYear.js +6 -2
  11. package/dist/cjs/dates/adapters/dateToYear.d.ts +2 -1
  12. package/dist/cjs/dates/adapters/dateToYear.js +7 -3
  13. package/dist/cjs/dates/adapters/hmsToDate.d.ts +2 -1
  14. package/dist/cjs/dates/adapters/hmsToDate.js +6 -2
  15. package/dist/cjs/dates/adapters/mdyDateToDate.d.ts +2 -1
  16. package/dist/cjs/dates/adapters/mdyDateToDate.js +7 -2
  17. package/dist/cjs/dates/adapters/monthYearToDate.d.ts +2 -1
  18. package/dist/cjs/dates/adapters/monthYearToDate.js +6 -2
  19. package/dist/cjs/dates/adapters/quarterYearToDate.d.ts +2 -1
  20. package/dist/cjs/dates/adapters/quarterYearToDate.js +6 -2
  21. package/dist/cjs/dates/adapters/weekYearToDate.d.ts +2 -1
  22. package/dist/cjs/dates/adapters/weekYearToDate.js +10 -6
  23. package/dist/cjs/dates/adapters/yearToDate.d.ts +2 -1
  24. package/dist/cjs/dates/adapters/yearToDate.js +6 -2
  25. package/dist/cjs/dates/helpers/getDateByDateFormat.d.ts +2 -1
  26. package/dist/cjs/dates/helpers/getDateByDateFormat.js +6 -6
  27. package/dist/cjs/dates/helpers/getDateByTimezone.d.ts +3 -3
  28. package/dist/cjs/dates/helpers/getDateByTimezone.js +12 -29
  29. package/dist/cjs/dates/helpers/getDateByTimezoneOffset.d.ts +1 -1
  30. package/dist/cjs/dates/helpers/getDateByTimezoneOffset.js +13 -2
  31. package/dist/cjs/dates/helpers/getDefaultDateSettings.d.ts +7 -0
  32. package/dist/cjs/dates/helpers/getDefaultDateSettings.js +17 -0
  33. package/dist/cjs/dates/helpers/getFormattedDateByFormat.d.ts +2 -1
  34. package/dist/cjs/dates/helpers/getFormattedDateByFormat.js +7 -7
  35. package/dist/cjs/dates/helpers/getWeek.js +6 -6
  36. package/dist/cjs/dates/interfaces/IDFDateToHmsSettings.d.ts +2 -1
  37. package/dist/cjs/dates/interfaces/IDateSettings.d.ts +5 -0
  38. package/dist/cjs/dates/interfaces/index.d.ts +1 -1
  39. package/dist/cjs/dates/interfaces/index.js +1 -1
  40. package/dist/cjs/format/format.js +6 -0
  41. package/dist/cjs/general/object/applyTimezoneDeep.js +1 -5
  42. package/dist/cjs/qrvey/helpers/transformValue.js +1 -4
  43. package/dist/columns/constants/COLUMN_PROPERTIES.d.ts +1 -1
  44. package/dist/dates/adapters/dateToHms.js +8 -10
  45. package/dist/dates/adapters/dateToMdyDate.d.ts +2 -1
  46. package/dist/dates/adapters/dateToMdyDate.js +9 -3
  47. package/dist/dates/adapters/dateToMonthYear.d.ts +2 -1
  48. package/dist/dates/adapters/dateToMonthYear.js +7 -3
  49. package/dist/dates/adapters/dateToQuarterYear.d.ts +2 -1
  50. package/dist/dates/adapters/dateToQuarterYear.js +8 -4
  51. package/dist/dates/adapters/dateToWeekYear.d.ts +2 -1
  52. package/dist/dates/adapters/dateToWeekYear.js +6 -2
  53. package/dist/dates/adapters/dateToYear.d.ts +2 -1
  54. package/dist/dates/adapters/dateToYear.js +7 -3
  55. package/dist/dates/adapters/hmsToDate.d.ts +2 -1
  56. package/dist/dates/adapters/hmsToDate.js +6 -2
  57. package/dist/dates/adapters/mdyDateToDate.d.ts +2 -1
  58. package/dist/dates/adapters/mdyDateToDate.js +7 -2
  59. package/dist/dates/adapters/monthYearToDate.d.ts +2 -1
  60. package/dist/dates/adapters/monthYearToDate.js +6 -2
  61. package/dist/dates/adapters/quarterYearToDate.d.ts +2 -1
  62. package/dist/dates/adapters/quarterYearToDate.js +6 -2
  63. package/dist/dates/adapters/weekYearToDate.d.ts +2 -1
  64. package/dist/dates/adapters/weekYearToDate.js +10 -6
  65. package/dist/dates/adapters/yearToDate.d.ts +2 -1
  66. package/dist/dates/adapters/yearToDate.js +6 -2
  67. package/dist/dates/helpers/getDateByDateFormat.d.ts +2 -1
  68. package/dist/dates/helpers/getDateByDateFormat.js +6 -6
  69. package/dist/dates/helpers/getDateByTimezone.d.ts +3 -3
  70. package/dist/dates/helpers/getDateByTimezone.js +12 -29
  71. package/dist/dates/helpers/getDateByTimezoneOffset.d.ts +1 -1
  72. package/dist/dates/helpers/getDateByTimezoneOffset.js +10 -2
  73. package/dist/dates/helpers/getDefaultDateSettings.d.ts +7 -0
  74. package/dist/dates/helpers/getDefaultDateSettings.js +13 -0
  75. package/dist/dates/helpers/getFormattedDateByFormat.d.ts +2 -1
  76. package/dist/dates/helpers/getFormattedDateByFormat.js +7 -7
  77. package/dist/dates/helpers/getWeek.js +6 -6
  78. package/dist/dates/interfaces/IDFDateToHmsSettings.d.ts +2 -1
  79. package/dist/dates/interfaces/IDateSettings.d.ts +5 -0
  80. package/dist/dates/interfaces/index.d.ts +1 -1
  81. package/dist/dates/interfaces/index.js +1 -1
  82. package/dist/format/format.js +6 -0
  83. package/dist/general/object/applyTimezoneDeep.js +1 -5
  84. package/dist/qrvey/helpers/transformValue.js +1 -4
  85. package/package.json +1 -1
  86. package/dist/cjs/dates/interfaces/IGetDateByTimezoneSettings.d.ts +0 -6
  87. package/dist/dates/interfaces/IGetDateByTimezoneSettings.d.ts +0 -6
  88. /package/dist/cjs/dates/interfaces/{IGetDateByTimezoneSettings.js → IDateSettings.js} +0 -0
  89. /package/dist/dates/interfaces/{IGetDateByTimezoneSettings.js → IDateSettings.js} +0 -0
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getDateByTimezoneOffset = void 0;
7
+ const dayjs_1 = __importDefault(require("dayjs"));
4
8
  const ISOToNumericOffset_1 = require("../adapters/ISOToNumericOffset");
5
9
  const DATE_FORMAT_1 = require("../constants/DATE_FORMAT");
6
10
  const isValidPotentialDate_1 = require("./isValidPotentialDate");
@@ -13,10 +17,17 @@ const validateDate_1 = require("./validateDate");
13
17
  */
14
18
  function getDateByTimezoneOffset(date, offset) {
15
19
  if (!(0, isValidPotentialDate_1.isValidPotentialDate)(date) ||
16
- (typeof date === "string" && !(0, validateDate_1.validateDate)(date, DATE_FORMAT_1.DATE_FORMAT.DAY)))
20
+ (typeof date === "string" && !(0, validateDate_1.validateDate)(date, DATE_FORMAT_1.DATE_FORMAT.SECOND)))
17
21
  return date;
18
22
  const dt = new Date(date.valueOf());
19
23
  const newOffset = (0, ISOToNumericOffset_1.ISOToNumericOffset)(offset);
20
- return new Date(+dt + newOffset * 1000 * 60);
24
+ const timezonedDate = new Date(+dt + newOffset * 1000 * 60);
25
+ if (typeof date === "string") {
26
+ return (0, dayjs_1.default)(timezonedDate).format(DATE_FORMAT_1.DATE_FORMAT.SECOND);
27
+ }
28
+ else if (typeof date === "number") {
29
+ return +timezonedDate;
30
+ }
31
+ return timezonedDate;
21
32
  }
22
33
  exports.getDateByTimezoneOffset = getDateByTimezoneOffset;
@@ -0,0 +1,7 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
2
+ /**
3
+ * Gets the default properties for Date Settings object
4
+ * @param settings the date settings
5
+ * @returns a new object with the date settings.
6
+ */
7
+ export declare function getDefaultDateSettings(settings: IDateSettings): IDateSettings;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultDateSettings = void 0;
4
+ const getTimezoneObject_1 = require("./getTimezoneObject");
5
+ /**
6
+ * Gets the default properties for Date Settings object
7
+ * @param settings the date settings
8
+ * @returns a new object with the date settings.
9
+ */
10
+ function getDefaultDateSettings(settings) {
11
+ var _a;
12
+ return {
13
+ convertMiliseconds: (_a = settings === null || settings === void 0 ? void 0 : settings.convertMiliseconds) !== null && _a !== void 0 ? _a : false,
14
+ timezone: (0, getTimezoneObject_1.getTimezoneObject)(settings === null || settings === void 0 ? void 0 : settings.timezone),
15
+ };
16
+ }
17
+ exports.getDefaultDateSettings = getDefaultDateSettings;
@@ -1,4 +1,5 @@
1
1
  import { IDateFormat } from "../interfaces/IDateFormat";
2
+ import { IDateSettings } from "../interfaces/IDateSettings";
2
3
  /**
3
4
  * A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
4
5
  * - Some strings are valid
@@ -6,4 +7,4 @@ import { IDateFormat } from "../interfaces/IDateFormat";
6
7
  * @param format The date format
7
8
  * @returns a formmatted date or the same value if format does not match
8
9
  */
9
- export declare function getFormattedDateByFormat(date: string | Date | number, format: IDateFormat): string | Date | number;
10
+ export declare function getFormattedDateByFormat(date: string | Date | number, format: IDateFormat, settings?: IDateSettings): string | Date | number;
@@ -14,22 +14,22 @@ const DATE_FORMAT_1 = require("../constants/DATE_FORMAT");
14
14
  * @param format The date format
15
15
  * @returns a formmatted date or the same value if format does not match
16
16
  */
17
- function getFormattedDateByFormat(date, format) {
17
+ function getFormattedDateByFormat(date, format, settings) {
18
18
  switch (format) {
19
19
  case DATE_FORMAT_1.DATE_FORMAT.YEAR:
20
- return (0, dateToYear_1.dateToYear)(date);
20
+ return (0, dateToYear_1.dateToYear)(date, settings);
21
21
  case DATE_FORMAT_1.DATE_FORMAT.MONTH:
22
- return (0, dateToMonthYear_1.dateToMonthYear)(date);
22
+ return (0, dateToMonthYear_1.dateToMonthYear)(date, settings);
23
23
  case DATE_FORMAT_1.DATE_FORMAT.QUARTER:
24
- return (0, dateToQuarterYear_1.dateToQuarterYear)(date);
24
+ return (0, dateToQuarterYear_1.dateToQuarterYear)(date, settings);
25
25
  case DATE_FORMAT_1.DATE_FORMAT.WEEK:
26
- return (0, dateToWeekYear_1.dateToWeekYear)(date);
26
+ return (0, dateToWeekYear_1.dateToWeekYear)(date, settings);
27
27
  case DATE_FORMAT_1.DATE_FORMAT.DAY:
28
- return (0, dateToMdyDate_1.dateToMdyDate)(date);
28
+ return (0, dateToMdyDate_1.dateToMdyDate)(date, settings);
29
29
  case DATE_FORMAT_1.DATE_FORMAT.HOUR:
30
30
  case DATE_FORMAT_1.DATE_FORMAT.MINUTE:
31
31
  case DATE_FORMAT_1.DATE_FORMAT.SECOND:
32
- return (0, dateToMdyDate_1.dateToMdyDate)(date, true);
32
+ return (0, dateToMdyDate_1.dateToMdyDate)(date, Object.assign(Object.assign({}, settings), { convertMiliseconds: true }));
33
33
  default:
34
34
  return date;
35
35
  }
@@ -12,17 +12,17 @@ function getWeek(date) {
12
12
  if (!(0, isValidDateObject_1.isValidDateObject)(date))
13
13
  return;
14
14
  const target = new Date(date.valueOf());
15
- const dayNr = (date.getDay() + 6) % 7;
16
- target.setDate(target.getDate() - dayNr + 3);
15
+ const dayNr = (date.getUTCDay() + 6) % 7;
16
+ target.setDate(target.getUTCDate() - dayNr + 3);
17
17
  const firstThursday = target.valueOf();
18
18
  target.setMonth(0, 1);
19
- if (target.getDay() !== 4) {
20
- target.setMonth(0, 1 + ((4 - target.getDay() + 7) % 7));
19
+ if (target.getUTCDay() !== 4) {
20
+ target.setMonth(0, 1 + ((4 - target.getUTCDay() + 7) % 7));
21
21
  }
22
22
  return {
23
23
  week: 1 + Math.ceil((firstThursday - +target) / 604800000),
24
- month: date.getMonth() + 1,
25
- year: target.getFullYear(),
24
+ month: date.getUTCMonth() + 1,
25
+ year: target.getUTCFullYear(),
26
26
  };
27
27
  }
28
28
  exports.getWeek = getWeek;
@@ -1,4 +1,5 @@
1
- export interface IDFDateToHmsSettings {
1
+ import { IDateSettings } from "./IDateSettings";
2
+ export interface IDFDateToHmsSettings extends IDateSettings {
2
3
  omitHour?: boolean;
3
4
  omitMinute?: boolean;
4
5
  omitSecond?: boolean;
@@ -0,0 +1,5 @@
1
+ import { IDTimezone } from "./IDTimezone";
2
+ export interface IDateSettings {
3
+ timezone?: IDTimezone;
4
+ convertMiliseconds?: boolean;
5
+ }
@@ -2,8 +2,8 @@ export * from "./IBTimezone";
2
2
  export * from "./IBTimezoneType";
3
3
  export * from "./IDateFormat";
4
4
  export * from "./IDateGroupingProperty";
5
+ export * from "./IDateSettings";
5
6
  export * from "./IDFDateToHmsSettings";
6
7
  export * from "./IDTimezone";
7
8
  export * from "./IDTimezoneOffset";
8
9
  export * from "./IDTimezoneType";
9
- export * from "./IGetDateByTimezoneSettings";
@@ -18,8 +18,8 @@ __exportStar(require("./IBTimezone"), exports);
18
18
  __exportStar(require("./IBTimezoneType"), exports);
19
19
  __exportStar(require("./IDateFormat"), exports);
20
20
  __exportStar(require("./IDateGroupingProperty"), exports);
21
+ __exportStar(require("./IDateSettings"), exports);
21
22
  __exportStar(require("./IDFDateToHmsSettings"), exports);
22
23
  __exportStar(require("./IDTimezone"), exports);
23
24
  __exportStar(require("./IDTimezoneOffset"), exports);
24
25
  __exportStar(require("./IDTimezoneType"), exports);
25
- __exportStar(require("./IGetDateByTimezoneSettings"), exports);
@@ -7,9 +7,13 @@ exports.defineFormat = exports.validateColumnType = exports.parseFormulaType = e
7
7
  const d3_format_1 = require("d3-format");
8
8
  const dayjs_1 = __importDefault(require("dayjs"));
9
9
  const definition_1 = require("./definition");
10
+ //* *dayjs plugins */
10
11
  const isoWeek_1 = __importDefault(require("dayjs/plugin/isoWeek"));
11
12
  const advancedFormat_1 = __importDefault(require("dayjs/plugin/advancedFormat"));
12
13
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
14
+ const weekYear_1 = __importDefault(require("dayjs/plugin/weekYear"));
15
+ const weekOfYear_1 = __importDefault(require("dayjs/plugin/weekOfYear"));
16
+ //* * end dayjs plugin imports */
13
17
  const isEmpty_1 = require("../general/mix/isEmpty");
14
18
  const get_1 = require("../general/object/get");
15
19
  const COLUMN_1 = require("../columns/constants/COLUMN");
@@ -21,6 +25,8 @@ const cloneDeep_1 = require("../general/object/cloneDeep");
21
25
  dayjs_1.default.extend(isoWeek_1.default); // Add support for iso week format https://github.com/iamkun/dayjs/issues/1328
22
26
  dayjs_1.default.extend(advancedFormat_1.default); // Add support to advanced formats https://day.js.org/docs/en/plugin/advanced-format
23
27
  dayjs_1.default.extend(utc_1.default);
28
+ dayjs_1.default.extend(weekYear_1.default);
29
+ dayjs_1.default.extend(weekOfYear_1.default);
24
30
  /**
25
31
  * Apply to the given date format to a date value
26
32
  * @param bytes type number
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyTimezoneDeep = void 0;
4
4
  const DATE_FORMAT_1 = require("../../dates/constants/DATE_FORMAT");
5
- const DATE_GROUPING_TIME_PROPERTY_1 = require("../../dates/constants/DATE_GROUPING_TIME_PROPERTY");
6
5
  const getDateByTimezone_1 = require("../../dates/helpers/getDateByTimezone");
7
6
  const validateDate_1 = require("../../dates/helpers/validateDate");
8
7
  const isEmpty_1 = require("../mix/isEmpty");
@@ -30,10 +29,7 @@ function applyTimezoneDeep(obj, timezone) {
30
29
  }
31
30
  else if (obj[i] instanceof Date ||
32
31
  (0, validateDate_1.validateDate)(obj[i], DATE_FORMAT_1.DATE_FORMAT.HOUR)) {
33
- result[i] = (0, getDateByTimezone_1.getDateByTimezone)(obj[i], {
34
- property: DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.HOUR,
35
- timezone,
36
- });
32
+ result[i] = (0, getDateByTimezone_1.getDateByTimezone)(obj[i], timezone);
37
33
  }
38
34
  else {
39
35
  result[i] = obj[i];
@@ -23,10 +23,7 @@ function transformValue(value, settings) {
23
23
  const defaultSettings = getDefaultSettings(settings);
24
24
  let timezonedValue = value;
25
25
  if (!defaultSettings.noTimezone) {
26
- timezonedValue = (0, getDateByTimezone_1.getDateByTimezone)(value, {
27
- property: defaultSettings.property,
28
- timezone: defaultSettings.timezone,
29
- });
26
+ timezonedValue = (0, getDateByTimezone_1.getDateByTimezone)(value, defaultSettings.timezone);
30
27
  }
31
28
  let valueWithI18n = timezonedValue;
32
29
  if (!defaultSettings.noTranslate) {
@@ -2,4 +2,4 @@ import { COLUMN_PROPERTY } from "./COLUMN_PROPERTY";
2
2
  /**
3
3
  * @description Collection of column properties
4
4
  */
5
- export declare const COLUMN_PROPERTIES: (import("../..").DATE_DISTINCT_PROPERTY | import("../..").DATE_DISTINCT_TIME_PROPERTY | import("./COMPOUND_COLUMN_PROPERTY").COMPOUND_COLUMN_PROPERTY | import("../..").DATE_GROUPING_PROPERTY | import("../..").DATE_GROUPING_TIME_PROPERTY | import("./COMPLEX_COLUMN_PROPERTY").COMPLEX_COLUMN_PROPERTY | COLUMN_PROPERTY)[];
5
+ export declare const COLUMN_PROPERTIES: (import("./COMPOUND_COLUMN_PROPERTY").COMPOUND_COLUMN_PROPERTY | import("../..").DATE_GROUPING_PROPERTY | import("../..").DATE_GROUPING_TIME_PROPERTY | import("../..").DATE_DISTINCT_PROPERTY | import("../..").DATE_DISTINCT_TIME_PROPERTY | import("./COMPLEX_COLUMN_PROPERTY").COMPLEX_COLUMN_PROPERTY | COLUMN_PROPERTY)[];
@@ -1,4 +1,5 @@
1
1
  import { padLeadingZeros } from "../../general/string/padLeadingZeros";
2
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
2
3
  import { isValidDateObject } from "../helpers/isValidDateObject";
3
4
  import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
4
5
  /**
@@ -10,10 +11,11 @@ import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
10
11
  export function dateToHms(date, settings) {
11
12
  if (!isValidPotentialDate(date))
12
13
  return date;
13
- const dt = new Date(date.valueOf());
14
+ const defaultSettings = getDefaultSettings(settings);
15
+ const timezonedDate = getDateByTimezone(date, defaultSettings.timezone);
16
+ const dt = new Date(timezonedDate.valueOf());
14
17
  if (!isValidDateObject(dt))
15
18
  return date;
16
- const defaultSettings = getDefaultSettings(settings);
17
19
  const hours = getHours(dt, defaultSettings);
18
20
  const minutes = getMinutes(dt, defaultSettings);
19
21
  const seconds = getSeconds(dt, defaultSettings);
@@ -26,11 +28,7 @@ export function dateToHms(date, settings) {
26
28
  */
27
29
  function getDefaultSettings(settings) {
28
30
  var _a, _b, _c;
29
- return {
30
- omitHour: (_a = settings === null || settings === void 0 ? void 0 : settings.omitHour) !== null && _a !== void 0 ? _a : false,
31
- omitMinute: (_b = settings === null || settings === void 0 ? void 0 : settings.omitMinute) !== null && _b !== void 0 ? _b : false,
32
- omitSecond: (_c = settings === null || settings === void 0 ? void 0 : settings.omitSecond) !== null && _c !== void 0 ? _c : false,
33
- };
31
+ return Object.assign(Object.assign({}, settings), { omitHour: (_a = settings === null || settings === void 0 ? void 0 : settings.omitHour) !== null && _a !== void 0 ? _a : false, omitMinute: (_b = settings === null || settings === void 0 ? void 0 : settings.omitMinute) !== null && _b !== void 0 ? _b : false, omitSecond: (_c = settings === null || settings === void 0 ? void 0 : settings.omitSecond) !== null && _c !== void 0 ? _c : false });
34
32
  }
35
33
  /**
36
34
  * Gets the Hours
@@ -39,7 +37,7 @@ function getDefaultSettings(settings) {
39
37
  * @returns the hour string
40
38
  */
41
39
  function getHours(date, settings) {
42
- return padLeadingZeros(settings.omitHour ? "0" : date.getHours(), 2).slice(-2);
40
+ return padLeadingZeros(settings.omitHour ? "0" : date.getUTCHours(), 2).slice(-2);
43
41
  }
44
42
  /**
45
43
  * Gets the Minutes
@@ -48,7 +46,7 @@ function getHours(date, settings) {
48
46
  * @returns the minute string
49
47
  */
50
48
  function getMinutes(date, settings) {
51
- return padLeadingZeros(settings.omitMinute ? "0" : date.getMinutes(), 2).slice(-2);
49
+ return padLeadingZeros(settings.omitMinute ? "0" : date.getUTCMinutes(), 2).slice(-2);
52
50
  }
53
51
  /**
54
52
  * Gets the Seconds
@@ -57,5 +55,5 @@ function getMinutes(date, settings) {
57
55
  * @returns the seconds string
58
56
  */
59
57
  function getSeconds(date, settings) {
60
- return padLeadingZeros(settings.omitSecond ? "0" : date.getSeconds(), 2).slice(-2);
58
+ return padLeadingZeros(settings.omitSecond ? "0" : date.getUTCSeconds(), 2).slice(-2);
61
59
  }
@@ -1,6 +1,7 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transform a Date to [mm/dd/yyyy] date format.
3
4
  * @param date String, object or millisencond number of the date
4
5
  * @returns string of [mm/dd/yyyy] date format
5
6
  */
6
- export declare function dateToMdyDate(date: string | Date | number, includeTime?: boolean): string;
7
+ export declare function dateToMdyDate(date: string | Date | number, settings?: IDateSettings): string;
@@ -1,4 +1,6 @@
1
1
  import { padLeadingZeros } from "../../general/string/padLeadingZeros";
2
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
3
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
2
4
  import { isValidDateObject } from "../helpers/isValidDateObject";
3
5
  import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
4
6
  import { dateToHms } from "./dateToHms";
@@ -7,11 +9,15 @@ import { dateToHms } from "./dateToHms";
7
9
  * @param date String, object or millisencond number of the date
8
10
  * @returns string of [mm/dd/yyyy] date format
9
11
  */
10
- export function dateToMdyDate(date, includeTime = false) {
12
+ export function dateToMdyDate(date, settings) {
11
13
  if (!isValidPotentialDate(date))
12
14
  return date;
13
- const dt = new Date(date.valueOf());
15
+ const defaultSettings = getDefaultDateSettings(settings);
16
+ const timezonedDate = getDateByTimezone(date, defaultSettings.timezone);
17
+ const dt = new Date(timezonedDate.valueOf());
14
18
  if (!isValidDateObject(dt))
15
19
  return date;
16
- return `${padLeadingZeros(dt.getMonth() + 1, 2).slice(-2)}/${padLeadingZeros(dt.getDate(), 2).slice(-2)}/${padLeadingZeros(dt.getFullYear(), 4)}${includeTime ? ` ${dateToHms(date)}` : ""}`;
20
+ return `${padLeadingZeros(dt.getUTCMonth() + 1, 2).slice(-2)}/${padLeadingZeros(dt.getUTCDate(), 2).slice(-2)}/${padLeadingZeros(dt.getUTCFullYear(), 4)}${defaultSettings.convertMiliseconds
21
+ ? ` ${dateToHms(date, defaultSettings)}`
22
+ : ""}`;
17
23
  }
@@ -1,6 +1,7 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transform a Date to [Month Year] date format.
3
4
  * @param date String, object or millisencond number of the date
4
5
  * @returns string of [Month Year] date format
5
6
  */
6
- export declare function dateToMonthYear(date: string | Date | number): string;
7
+ export declare function dateToMonthYear(date: string | Date | number, settings?: IDateSettings): string;
@@ -1,4 +1,6 @@
1
1
  import { DATE_YEAR_MONTHS } from "../constants/DATE_YEAR_MONTHS";
2
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
3
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
2
4
  import { isValidDateObject } from "../helpers/isValidDateObject";
3
5
  import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
4
6
  /**
@@ -6,11 +8,13 @@ import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
6
8
  * @param date String, object or millisencond number of the date
7
9
  * @returns string of [Month Year] date format
8
10
  */
9
- export function dateToMonthYear(date) {
11
+ export function dateToMonthYear(date, settings) {
10
12
  if (!isValidPotentialDate(date))
11
13
  return date;
12
- const dt = new Date(date.valueOf());
14
+ const defaultSettings = getDefaultDateSettings(settings);
15
+ const timezonedDate = getDateByTimezone(date, defaultSettings.timezone);
16
+ const dt = new Date(timezonedDate.valueOf());
13
17
  if (!isValidDateObject(dt))
14
18
  return date;
15
- return `${DATE_YEAR_MONTHS[dt.getMonth()]} ${dt.getFullYear()}`;
19
+ return `${DATE_YEAR_MONTHS[dt.getUTCMonth()]} ${dt.getUTCFullYear()}`;
16
20
  }
@@ -1,6 +1,7 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transform a valid Date to [Quarter Year] date format.
3
4
  * @param date String of a valid date, date object or millisencond number of the date
4
5
  * @returns string of [Quarter Year] date format
5
6
  */
6
- export declare function dateToQuarterYear(date: string | Date | number): string;
7
+ export declare function dateToQuarterYear(date: string | Date | number, settings?: IDateSettings): string;
@@ -1,4 +1,6 @@
1
1
  import { DATE_YEAR_QUARTERS } from "../constants/DATE_YEAR_QUARTERS";
2
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
3
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
2
4
  import { isValidDateObject } from "../helpers/isValidDateObject";
3
5
  import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
4
6
  /**
@@ -6,12 +8,14 @@ import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
6
8
  * @param date String of a valid date, date object or millisencond number of the date
7
9
  * @returns string of [Quarter Year] date format
8
10
  */
9
- export function dateToQuarterYear(date) {
11
+ export function dateToQuarterYear(date, settings) {
10
12
  if (!isValidPotentialDate(date))
11
13
  return date;
12
- const dt = new Date(date.valueOf());
14
+ const defaultSettings = getDefaultDateSettings(settings);
15
+ const timezonedDate = getDateByTimezone(date, defaultSettings.timezone);
16
+ const dt = new Date(timezonedDate.valueOf());
13
17
  if (!isValidDateObject(dt))
14
18
  return date;
15
- const quarter = Math.ceil((dt.getMonth() + 1) / 3);
16
- return `${DATE_YEAR_QUARTERS[quarter - 1]} ${dt.getFullYear()}`;
19
+ const quarter = Math.ceil((dt.getUTCMonth() + 1) / 3);
20
+ return `${DATE_YEAR_QUARTERS[quarter - 1]} ${dt.getUTCFullYear()}`;
17
21
  }
@@ -1,6 +1,7 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transform a Date to [W# Year] date format.
3
4
  * @param date String, object or millisencond number of the date
4
5
  * @returns string of [W# Year] date format
5
6
  */
6
- export declare function dateToWeekYear(date: string | Date | number): string;
7
+ export declare function dateToWeekYear(date: string | Date | number, settings?: IDateSettings): string;
@@ -1,3 +1,5 @@
1
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
2
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
1
3
  import { getWeek } from "../helpers/getWeek";
2
4
  import { isValidDateObject } from "../helpers/isValidDateObject";
3
5
  import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
@@ -6,10 +8,12 @@ import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
6
8
  * @param date String, object or millisencond number of the date
7
9
  * @returns string of [W# Year] date format
8
10
  */
9
- export function dateToWeekYear(date) {
11
+ export function dateToWeekYear(date, settings) {
10
12
  if (!isValidPotentialDate(date))
11
13
  return date;
12
- const dt = new Date(date.valueOf());
14
+ const defaultSettings = getDefaultDateSettings(settings);
15
+ const timezonedDate = getDateByTimezone(date, defaultSettings.timezone);
16
+ const dt = new Date(timezonedDate.valueOf());
13
17
  if (!isValidDateObject(dt))
14
18
  return date;
15
19
  const weekObj = getWeek(dt);
@@ -1,6 +1,7 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transform a Date to [Year] date format.
3
4
  * @param {string | Date | number} date String, object or millisencond number of the date
4
5
  * @returns string of [Year] date format
5
6
  */
6
- export declare function dateToYear(date: string | Date | number): string;
7
+ export declare function dateToYear(date: string | Date | number, settings?: IDateSettings): string;
@@ -1,3 +1,5 @@
1
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
2
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
1
3
  import { isValidDateObject } from "../helpers/isValidDateObject";
2
4
  import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
3
5
  /**
@@ -5,11 +7,13 @@ import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
5
7
  * @param {string | Date | number} date String, object or millisencond number of the date
6
8
  * @returns string of [Year] date format
7
9
  */
8
- export function dateToYear(date) {
10
+ export function dateToYear(date, settings) {
9
11
  if (!isValidPotentialDate(date))
10
12
  return date;
11
- const dt = new Date(date.valueOf());
13
+ const defaultSettings = getDefaultDateSettings(settings);
14
+ const timezonedDate = getDateByTimezone(date, defaultSettings.timezone);
15
+ const dt = new Date(timezonedDate.valueOf());
12
16
  if (!isValidDateObject(dt))
13
17
  return date;
14
- return String(dt.getFullYear());
18
+ return String(dt.getUTCFullYear());
15
19
  }
@@ -1,7 +1,8 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transforms String time from a [H:m:s] format to Date object.
3
4
  * @param monthYearDate String of [H:m:s] time
4
5
  * @param time Flag to parse the object date to milliseconds.
5
6
  * @returns The date object or the date in milliseconds. If the argument is an unexpected time, the function will return the same value
6
7
  */
7
- export declare function hmsToDate(hmsDate: string, time?: boolean): string | Date | number;
8
+ export declare function hmsToDate(hmsDate: string, settings?: IDateSettings): string | Date | number;
@@ -1,6 +1,8 @@
1
1
  import { isEmpty } from "../../general/mix/isEmpty";
2
2
  import { isTokenLabel } from "../../tokens/isTokenLabel";
3
3
  import { DATE_FORMAT } from "../constants/DATE_FORMAT";
4
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
5
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
4
6
  import { validateDate } from "../helpers/validateDate";
5
7
  /**
6
8
  * Transforms String time from a [H:m:s] format to Date object.
@@ -8,13 +10,15 @@ import { validateDate } from "../helpers/validateDate";
8
10
  * @param time Flag to parse the object date to milliseconds.
9
11
  * @returns The date object or the date in milliseconds. If the argument is an unexpected time, the function will return the same value
10
12
  */
11
- export function hmsToDate(hmsDate, time = false) {
13
+ export function hmsToDate(hmsDate, settings) {
12
14
  if (isEmpty(hmsDate) ||
13
15
  isTokenLabel(hmsDate) ||
14
16
  typeof hmsDate !== "string" ||
15
17
  !validateDate(hmsDate, DATE_FORMAT.DAY_TIME))
16
18
  return hmsDate;
19
+ const defaultSettings = getDefaultDateSettings(settings);
17
20
  const [hour, minute, second] = hmsDate.split(":");
18
21
  const start = new Date(0, 0, 0, +hour, +minute, +second);
19
- return time ? +start : start;
22
+ const timezonedDate = getDateByTimezone(start, defaultSettings.timezone);
23
+ return defaultSettings.convertMiliseconds ? +timezonedDate : timezonedDate;
20
24
  }
@@ -1,7 +1,8 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transforms String Date from a [mm/dd/yyyy] format to Date object.
3
4
  * @param monthYearDate String of [mm/dd/yyyy] date
4
5
  * @param time Flag to parse the object date to milliseconds.
5
6
  * @returns The date object or the date in milliseconds. If the argument is an unexpected date, the function will return the same value
6
7
  */
7
- export declare function mdyDateToDate(date: string, time?: boolean): string | Date | number;
8
+ export declare function mdyDateToDate(date: string, settings?: IDateSettings): string | Date | number;
@@ -1,6 +1,8 @@
1
1
  import { isEmpty } from "../../general/mix/isEmpty";
2
2
  import { isTokenLabel } from "../../tokens/isTokenLabel";
3
3
  import { DATE_FORMAT } from "../constants/DATE_FORMAT";
4
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
5
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
4
6
  import { validateDate } from "../helpers/validateDate";
5
7
  /**
6
8
  * Transforms String Date from a [mm/dd/yyyy] format to Date object.
@@ -8,13 +10,16 @@ import { validateDate } from "../helpers/validateDate";
8
10
  * @param time Flag to parse the object date to milliseconds.
9
11
  * @returns The date object or the date in milliseconds. If the argument is an unexpected date, the function will return the same value
10
12
  */
11
- export function mdyDateToDate(date, time = false) {
13
+ export function mdyDateToDate(date, settings) {
12
14
  if (isEmpty(date) ||
13
15
  isTokenLabel(date) ||
14
16
  typeof date !== "string" ||
15
17
  !validatingDate(date))
16
18
  return date;
17
- return time ? +new Date(date) : new Date(date);
19
+ const defaultSettings = getDefaultDateSettings(settings);
20
+ const dateObject = new Date(date);
21
+ const timezonedDate = getDateByTimezone(dateObject, defaultSettings.timezone);
22
+ return defaultSettings.convertMiliseconds ? +timezonedDate : timezonedDate;
18
23
  }
19
24
  function validatingDate(date) {
20
25
  return (validateDate(date, DATE_FORMAT.DAY) ||
@@ -1,7 +1,8 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transforms String Date from a [Month Year] format to Date object.
3
4
  * @param monthYearDate String of [Month Year] date
4
5
  * @param time Flag to parse the object date to milliseconds.
5
6
  * @returns The date object or the date in milliseconds. If the argument is an unexpected date, the function will return the same value
6
7
  */
7
- export declare function monthYearToDate(monthYearDate: string, time?: boolean): string | Date | number;
8
+ export declare function monthYearToDate(monthYearDate: string, settings?: IDateSettings): string | Date | number;
@@ -2,6 +2,8 @@ import { isEmpty } from "../../general/mix/isEmpty";
2
2
  import { isTokenLabel } from "../../tokens/isTokenLabel";
3
3
  import { DATE_FORMAT } from "../constants/DATE_FORMAT";
4
4
  import { DATE_YEAR_MONTHS } from "../constants/DATE_YEAR_MONTHS";
5
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
6
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
5
7
  import { validateDate } from "../helpers/validateDate";
6
8
  /**
7
9
  * Transforms String Date from a [Month Year] format to Date object.
@@ -9,13 +11,15 @@ import { validateDate } from "../helpers/validateDate";
9
11
  * @param time Flag to parse the object date to milliseconds.
10
12
  * @returns The date object or the date in milliseconds. If the argument is an unexpected date, the function will return the same value
11
13
  */
12
- export function monthYearToDate(monthYearDate, time = false) {
14
+ export function monthYearToDate(monthYearDate, settings) {
13
15
  if (isEmpty(monthYearDate) ||
14
16
  isTokenLabel(monthYearDate) ||
15
17
  typeof monthYearDate !== "string" ||
16
18
  !validateDate(monthYearDate, DATE_FORMAT.MONTH))
17
19
  return monthYearDate;
20
+ const defaultSettings = getDefaultDateSettings(settings);
18
21
  const [month, year] = monthYearDate.split(" ");
19
22
  const start = new Date(+year, DATE_YEAR_MONTHS.indexOf(month), 1);
20
- return time ? +start : start;
23
+ const timezonedDate = getDateByTimezone(start, defaultSettings.timezone);
24
+ return (defaultSettings === null || defaultSettings === void 0 ? void 0 : defaultSettings.convertMiliseconds) ? +timezonedDate : timezonedDate;
21
25
  }
@@ -1,7 +1,8 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transforms String Date from a [Quarter Year] format to Date object.
3
4
  * @param quarterYearDate String of [Quarter Year] date
4
5
  * @param time Flag to parse the object date to milliseconds.
5
6
  * @returns The date object or the date in milliseconds. If the argument is an unexpected date, the function will return the same value.
6
7
  */
7
- export declare function quarterYearToDate(quarterYearDate: string, time?: boolean): string | Date | number;
8
+ export declare function quarterYearToDate(quarterYearDate: string, settings?: IDateSettings): string | Date | number;
@@ -2,6 +2,8 @@ import { isEmpty } from "../../general/mix/isEmpty";
2
2
  import { isTokenLabel } from "../../tokens/isTokenLabel";
3
3
  import { DATE_FORMAT } from "../constants/DATE_FORMAT";
4
4
  import { DATE_YEAR_QUARTERS_RANGE } from "../constants/DATE_YEAR_QUARTERS_RANGE";
5
+ import { getDateByTimezone } from "../helpers/getDateByTimezone";
6
+ import { getDefaultDateSettings } from "../helpers/getDefaultDateSettings";
5
7
  import { validateDate } from "../helpers/validateDate";
6
8
  /**
7
9
  * Transforms String Date from a [Quarter Year] format to Date object.
@@ -9,13 +11,15 @@ import { validateDate } from "../helpers/validateDate";
9
11
  * @param time Flag to parse the object date to milliseconds.
10
12
  * @returns The date object or the date in milliseconds. If the argument is an unexpected date, the function will return the same value.
11
13
  */
12
- export function quarterYearToDate(quarterYearDate, time = false) {
14
+ export function quarterYearToDate(quarterYearDate, settings) {
13
15
  if (isEmpty(quarterYearDate) ||
14
16
  isTokenLabel(quarterYearDate) ||
15
17
  typeof quarterYearDate !== "string" ||
16
18
  !validateDate(quarterYearDate, DATE_FORMAT.QUARTER))
17
19
  return quarterYearDate;
20
+ const defaultSettings = getDefaultDateSettings(settings);
18
21
  const [quarter, year] = quarterYearDate.split(" ");
19
22
  const start = new Date(+year, DATE_YEAR_QUARTERS_RANGE[quarter].initial, 1);
20
- return time ? +start : start;
23
+ const timezonedDate = getDateByTimezone(start, defaultSettings.timezone);
24
+ return (defaultSettings === null || defaultSettings === void 0 ? void 0 : defaultSettings.convertMiliseconds) ? +timezonedDate : timezonedDate;
21
25
  }
@@ -1,7 +1,8 @@
1
+ import { IDateSettings } from "../interfaces/IDateSettings";
1
2
  /**
2
3
  * Transforms String Date from a [Week Year] format to Date object.
3
4
  * @param date String of [Week Year] date
4
5
  * @param time Flag to parse the object date to milliseconds.
5
6
  * @returns The date object or the date in milliseconds. If the argument is an unexpected date, the function will return the same value.
6
7
  */
7
- export declare function weekYearToDate(weekYear: string, time?: boolean): string | Date | number;
8
+ export declare function weekYearToDate(weekYear: string, settings?: IDateSettings): string | Date | number;