@qrvey/utils 1.4.7 → 1.4.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 (48) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/dates/adapters/dateToMdyDate.js +1 -1
  3. package/dist/cjs/dates/constants/DATE_FORMAT.js +2 -2
  4. package/dist/cjs/dates/helpers/adjustTimezone.d.ts +6 -0
  5. package/dist/cjs/dates/helpers/adjustTimezone.js +19 -0
  6. package/dist/cjs/dates/helpers/getFormattedDateByFormat.d.ts +1 -0
  7. package/dist/cjs/dates/helpers/getFormattedDateByFormat.js +18 -17
  8. package/dist/cjs/dates/helpers/index.d.ts +2 -0
  9. package/dist/cjs/dates/helpers/index.js +2 -0
  10. package/dist/cjs/dates/helpers/isValidPotentialDate.d.ts +6 -0
  11. package/dist/cjs/dates/helpers/isValidPotentialDate.js +18 -0
  12. package/dist/cjs/dates/relative/constants/RELATIVE_DATE_TIME_UNIT_INFO_LIST.d.ts +5 -0
  13. package/dist/cjs/dates/relative/constants/RELATIVE_DATE_TIME_UNIT_INFO_LIST.js +12 -0
  14. package/dist/cjs/dates/relative/constants/RELATIVE_DATE_UNIT_INFO_LIST.d.ts +5 -0
  15. package/dist/cjs/dates/relative/constants/{RELATIVE_UNIT_INFO_LIST.js → RELATIVE_DATE_UNIT_INFO_LIST.js} +3 -3
  16. package/dist/cjs/dates/relative/constants/RELATIVE_UNIT_INFO.js +25 -0
  17. package/dist/cjs/dates/relative/constants/index.d.ts +2 -1
  18. package/dist/cjs/dates/relative/constants/index.js +2 -1
  19. package/dist/cjs/dates/relative/interfaces/IRelativeUnit.d.ts +2 -1
  20. package/dist/cjs/globalization/interfaces/common/II18nUnits.d.ts +3 -0
  21. package/dist/cjs/globalization/interfaces/filters/II18nRelativeContainer.d.ts +1 -0
  22. package/dist/cjs/globalization/labels/common/I18N_COMMON.js +3 -0
  23. package/dist/cjs/globalization/labels/filters/I18N_RELATIVE_CONTAINER.js +1 -0
  24. package/dist/dates/adapters/dateToMdyDate.js +1 -1
  25. package/dist/dates/constants/DATE_FORMAT.js +2 -2
  26. package/dist/dates/helpers/adjustTimezone.d.ts +6 -0
  27. package/dist/dates/helpers/adjustTimezone.js +15 -0
  28. package/dist/dates/helpers/getFormattedDateByFormat.d.ts +1 -0
  29. package/dist/dates/helpers/getFormattedDateByFormat.js +18 -17
  30. package/dist/dates/helpers/index.d.ts +2 -0
  31. package/dist/dates/helpers/index.js +2 -0
  32. package/dist/dates/helpers/isValidPotentialDate.d.ts +6 -0
  33. package/dist/dates/helpers/isValidPotentialDate.js +14 -0
  34. package/dist/dates/relative/constants/RELATIVE_DATE_TIME_UNIT_INFO_LIST.d.ts +5 -0
  35. package/dist/dates/relative/constants/RELATIVE_DATE_TIME_UNIT_INFO_LIST.js +9 -0
  36. package/dist/dates/relative/constants/RELATIVE_DATE_UNIT_INFO_LIST.d.ts +5 -0
  37. package/dist/dates/relative/constants/{RELATIVE_UNIT_INFO_LIST.js → RELATIVE_DATE_UNIT_INFO_LIST.js} +2 -2
  38. package/dist/dates/relative/constants/RELATIVE_UNIT_INFO.js +25 -0
  39. package/dist/dates/relative/constants/index.d.ts +2 -1
  40. package/dist/dates/relative/constants/index.js +2 -1
  41. package/dist/dates/relative/interfaces/IRelativeUnit.d.ts +2 -1
  42. package/dist/globalization/interfaces/common/II18nUnits.d.ts +3 -0
  43. package/dist/globalization/interfaces/filters/II18nRelativeContainer.d.ts +1 -0
  44. package/dist/globalization/labels/common/I18N_COMMON.js +3 -0
  45. package/dist/globalization/labels/filters/I18N_RELATIVE_CONTAINER.js +1 -0
  46. package/package.json +2 -1
  47. package/dist/cjs/dates/relative/constants/RELATIVE_UNIT_INFO_LIST.d.ts +0 -5
  48. package/dist/dates/relative/constants/RELATIVE_UNIT_INFO_LIST.d.ts +0 -5
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [@qrvey/utils](https://bitbucket.org/qrvey/qrvey_utils/wiki/Home) *1.4.7*
1
+ # [@qrvey/utils](https://bitbucket.org/qrvey/qrvey_utils/wiki/Home) *1.4.9*
2
2
 
3
3
  > Helper, Utils for all Qrvey Projects
4
4
 
@@ -10,7 +10,7 @@ const dateToHms_1 = require("./dateToHms");
10
10
  * @param date String, object or millisencond number of the date
11
11
  * @returns string of [mm/dd/yyyy] date format
12
12
  */
13
- function dateToMdyDate(date, includeTime) {
13
+ function dateToMdyDate(date, includeTime = false) {
14
14
  if ((0, isEmpty_1.isEmpty)(date) || (0, isTokenLabel_1.isTokenLabel)(date))
15
15
  return date;
16
16
  const dt = new Date(date.valueOf());
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DATE_FORMAT = void 0;
4
- const YEAR = "yyyy";
5
- const DAY = "mm/dd/yyyy";
4
+ const YEAR = "YYYY";
5
+ const DAY = "MM/DD/YYYY";
6
6
  const DAY_TIME = "HH:mm:ss";
7
7
  const MONTH_DAY = "dd";
8
8
  const YEAR_MONTH = "M";
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,19 @@
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 +1,7 @@
1
1
  import { IDateFormat } from "../interfaces/IDateFormat";
2
2
  /**
3
3
  * A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
4
+ * - Some strings are valid
4
5
  * @param date String with a formatted date
5
6
  * @param format The date format
6
7
  * @returns a formmatted date or the same value if format does not match
@@ -9,28 +9,29 @@ const dateToYear_1 = require("../adapters/dateToYear");
9
9
  const DATE_FORMAT_1 = require("../constants/DATE_FORMAT");
10
10
  /**
11
11
  * A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
12
+ * - Some strings are valid
12
13
  * @param date String with a formatted date
13
14
  * @param format The date format
14
15
  * @returns a formmatted date or the same value if format does not match
15
16
  */
16
17
  function getFormattedDateByFormat(date, format) {
17
- if (format === DATE_FORMAT_1.DATE_FORMAT.QUARTER) {
18
- return (0, dateToQuarterYear_1.dateToQuarterYear)(date);
19
- }
20
- else if (format === DATE_FORMAT_1.DATE_FORMAT.MONTH) {
21
- return (0, dateToMonthYear_1.dateToMonthYear)(date);
22
- }
23
- else if (format === DATE_FORMAT_1.DATE_FORMAT.YEAR) {
24
- return (0, dateToYear_1.dateToYear)(date);
25
- }
26
- else if (format === DATE_FORMAT_1.DATE_FORMAT.WEEK) {
27
- return (0, dateToWeekYear_1.dateToWeekYear)(date);
28
- }
29
- else if (format === DATE_FORMAT_1.DATE_FORMAT.DAY) {
30
- return (0, dateToMdyDate_1.dateToMdyDate)(date);
31
- }
32
- else {
33
- return date;
18
+ switch (format) {
19
+ case DATE_FORMAT_1.DATE_FORMAT.YEAR:
20
+ return (0, dateToYear_1.dateToYear)(date);
21
+ case DATE_FORMAT_1.DATE_FORMAT.MONTH:
22
+ return (0, dateToMonthYear_1.dateToMonthYear)(date);
23
+ case DATE_FORMAT_1.DATE_FORMAT.QUARTER:
24
+ return (0, dateToQuarterYear_1.dateToQuarterYear)(date);
25
+ case DATE_FORMAT_1.DATE_FORMAT.WEEK:
26
+ return (0, dateToWeekYear_1.dateToWeekYear)(date);
27
+ case DATE_FORMAT_1.DATE_FORMAT.DAY:
28
+ return (0, dateToMdyDate_1.dateToMdyDate)(date);
29
+ case DATE_FORMAT_1.DATE_FORMAT.HOUR:
30
+ case DATE_FORMAT_1.DATE_FORMAT.MINUTE:
31
+ case DATE_FORMAT_1.DATE_FORMAT.SECOND:
32
+ return (0, dateToMdyDate_1.dateToMdyDate)(date, true);
33
+ default:
34
+ return date;
34
35
  }
35
36
  }
36
37
  exports.getFormattedDateByFormat = getFormattedDateByFormat;
@@ -1,3 +1,4 @@
1
+ export * from "./adjustTimezone";
1
2
  export * from "./getDateByDateFormat";
2
3
  export * from "./getDateFormatByProperty";
3
4
  export * from "./getDateFormatRegularExpressionInArray";
@@ -6,4 +7,5 @@ export * from "./getFormattedDateByFormat";
6
7
  export * from "./getSeparatorByDateFormat";
7
8
  export * from "./includeDateTokens";
8
9
  export * from "./getWeek";
10
+ export * from "./isValidPotentialDate";
9
11
  export * from "./validateDate";
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./adjustTimezone"), exports);
17
18
  __exportStar(require("./getDateByDateFormat"), exports);
18
19
  __exportStar(require("./getDateFormatByProperty"), exports);
19
20
  __exportStar(require("./getDateFormatRegularExpressionInArray"), exports);
@@ -22,4 +23,5 @@ __exportStar(require("./getFormattedDateByFormat"), exports);
22
23
  __exportStar(require("./getSeparatorByDateFormat"), exports);
23
24
  __exportStar(require("./includeDateTokens"), exports);
24
25
  __exportStar(require("./getWeek"), exports);
26
+ __exportStar(require("./isValidPotentialDate"), exports);
25
27
  __exportStar(require("./validateDate"), exports);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Checks if the given date is allowed to continue the process for adapting dates
3
+ * @param {string | Date | number} date String, object or millisencond number of the date
4
+ * @returns true: the date is valid.
5
+ */
6
+ export declare function isValidPotentialDate(date: string | Date | number): boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidPotentialDate = void 0;
4
+ const isEmpty_1 = require("../../general/mix/isEmpty");
5
+ const isTokenLabel_1 = require("../../tokens/isTokenLabel");
6
+ /**
7
+ * Checks if the given date is allowed to continue the process for adapting dates
8
+ * @param {string | Date | number} date String, object or millisencond number of the date
9
+ * @returns true: the date is valid.
10
+ */
11
+ function isValidPotentialDate(date) {
12
+ return (!(0, isEmpty_1.isEmpty)(date) &&
13
+ !(0, isTokenLabel_1.isTokenLabel)(date) &&
14
+ ((date instanceof Date && !isNaN(date)) ||
15
+ typeof date === "string" ||
16
+ typeof date === "number"));
17
+ }
18
+ exports.isValidPotentialDate = isValidPotentialDate;
@@ -0,0 +1,5 @@
1
+ import { IRelativeUnitInfo } from "../interfaces/IRelativeUnitInfo";
2
+ /**
3
+ * @description Key/array of compound relative unit info of date-time
4
+ */
5
+ export declare const RELATIVE_DATE_TIME_UNIT_INFO_LIST: IRelativeUnitInfo[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RELATIVE_DATE_TIME_UNIT_INFO_LIST = void 0;
4
+ const RELATIVE_UNIT_INFO_1 = require("./RELATIVE_UNIT_INFO");
5
+ /**
6
+ * @description Key/array of compound relative unit info of date-time
7
+ */
8
+ exports.RELATIVE_DATE_TIME_UNIT_INFO_LIST = [
9
+ RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.HOUR,
10
+ RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.MINUTE,
11
+ RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.SECOND,
12
+ ];
@@ -0,0 +1,5 @@
1
+ import { IRelativeUnitInfo } from "../interfaces/IRelativeUnitInfo";
2
+ /**
3
+ * @description Key/array of compound relative unit info of dates
4
+ */
5
+ export declare const RELATIVE_DATE_UNIT_INFO_LIST: IRelativeUnitInfo[];
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RELATIVE_UNIT_INFO_LIST = void 0;
3
+ exports.RELATIVE_DATE_UNIT_INFO_LIST = void 0;
4
4
  const RELATIVE_UNIT_INFO_1 = require("./RELATIVE_UNIT_INFO");
5
5
  /**
6
- * @description Key/array of compound relative cursor info
6
+ * @description Key/array of compound relative unit info of dates
7
7
  */
8
- exports.RELATIVE_UNIT_INFO_LIST = [
8
+ exports.RELATIVE_DATE_UNIT_INFO_LIST = [
9
9
  RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO["YEAR"],
10
10
  RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO["QUARTER"],
11
11
  RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO["MONTH"],
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RELATIVE_UNIT_INFO = void 0;
4
4
  const DATE_GROUPING_PROPERTY_1 = require("../../constants/DATE_GROUPING_PROPERTY");
5
+ const DATE_GROUPING_TIME_PROPERTY_1 = require("../../constants/DATE_GROUPING_TIME_PROPERTY");
5
6
  exports.RELATIVE_UNIT_INFO = {
6
7
  DAY: {
7
8
  abbrLabel: "Day",
@@ -43,4 +44,28 @@ exports.RELATIVE_UNIT_INFO = {
43
44
  displayed: true,
44
45
  i18nLabelPath: "common.units.year",
45
46
  },
47
+ HOUR: {
48
+ abbrLabel: "Hour",
49
+ shortLabel: "Hour",
50
+ label: "Hour",
51
+ value: DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.HOUR,
52
+ displayed: true,
53
+ i18nLabelPath: "common.units.hour",
54
+ },
55
+ MINUTE: {
56
+ abbrLabel: "Minute",
57
+ shortLabel: "Minute",
58
+ label: "Minute",
59
+ value: DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.MINUTE,
60
+ displayed: false,
61
+ i18nLabelPath: "common.units.minute",
62
+ },
63
+ SECOND: {
64
+ abbrLabel: "Second",
65
+ shortLabel: "Second",
66
+ label: "Second",
67
+ value: DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.SECOND,
68
+ displayed: false,
69
+ i18nLabelPath: "common.units.second",
70
+ },
46
71
  };
@@ -4,6 +4,7 @@ export * from "./RELATIVE_CURSOR";
4
4
  export * from "./RELATIVE_CURSOR_INFO_LIST";
5
5
  export * from "./RELATIVE_CURSOR_INFO";
6
6
  export * from "./RELATIVE_CURSOR_LABEL";
7
- export * from "./RELATIVE_UNIT_INFO_LIST";
7
+ export * from "./RELATIVE_DATE_TIME_UNIT_INFO_LIST";
8
+ export * from "./RELATIVE_DATE_UNIT_INFO_LIST";
8
9
  export * from "./RELATIVE_UNIT_INFO";
9
10
  export * from "./ui/index";
@@ -20,6 +20,7 @@ __exportStar(require("./RELATIVE_CURSOR"), exports);
20
20
  __exportStar(require("./RELATIVE_CURSOR_INFO_LIST"), exports);
21
21
  __exportStar(require("./RELATIVE_CURSOR_INFO"), exports);
22
22
  __exportStar(require("./RELATIVE_CURSOR_LABEL"), exports);
23
- __exportStar(require("./RELATIVE_UNIT_INFO_LIST"), exports);
23
+ __exportStar(require("./RELATIVE_DATE_TIME_UNIT_INFO_LIST"), exports);
24
+ __exportStar(require("./RELATIVE_DATE_UNIT_INFO_LIST"), exports);
24
25
  __exportStar(require("./RELATIVE_UNIT_INFO"), exports);
25
26
  __exportStar(require("./ui/index"), exports);
@@ -1,2 +1,3 @@
1
+ import { DATE_GROUPING_TIME_PROPERTY } from "../../constants/DATE_GROUPING_TIME_PROPERTY";
1
2
  import { DATE_GROUPING_PROPERTY } from "../../constants/DATE_GROUPING_PROPERTY";
2
- export declare type IRelativeUnit = keyof typeof DATE_GROUPING_PROPERTY;
3
+ export declare type IRelativeUnit = keyof typeof DATE_GROUPING_PROPERTY | keyof typeof DATE_GROUPING_TIME_PROPERTY;
@@ -1,7 +1,10 @@
1
1
  export interface II18nUnits {
2
2
  day: string;
3
+ hour: string;
4
+ minute: string;
3
5
  month: string;
4
6
  quarter: string;
7
+ second: string;
5
8
  week: string;
6
9
  year: string;
7
10
  }
@@ -10,4 +10,5 @@ export interface II18nRelativeContainer {
10
10
  starting_date_tooltip: string;
11
11
  starting_from: string;
12
12
  set_current_date: string;
13
+ utc_tooltip: string;
13
14
  }
@@ -25,8 +25,11 @@ exports.I18N_COMMON = {
25
25
  search: "Search",
26
26
  units: {
27
27
  day: RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.DAY.label,
28
+ hour: RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.HOUR.label,
29
+ minute: RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.MINUTE.label,
28
30
  month: RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.MONTH.label,
29
31
  quarter: RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.QUARTER.label,
32
+ second: RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.SECOND.label,
30
33
  week: RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.WEEK.label,
31
34
  year: RELATIVE_UNIT_INFO_1.RELATIVE_UNIT_INFO.YEAR.label,
32
35
  },
@@ -13,4 +13,5 @@ exports.I18N_RELATIVE_CONTAINER = {
13
13
  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.",
14
14
  starting_from: "Starting From",
15
15
  set_current_date: "Set to current date",
16
+ utc_tooltip: "The times displayed are in UTC-0",
16
17
  };
@@ -7,7 +7,7 @@ import { dateToHms } from "./dateToHms";
7
7
  * @param date String, object or millisencond number of the date
8
8
  * @returns string of [mm/dd/yyyy] date format
9
9
  */
10
- export function dateToMdyDate(date, includeTime) {
10
+ export function dateToMdyDate(date, includeTime = false) {
11
11
  if (isEmpty(date) || isTokenLabel(date))
12
12
  return date;
13
13
  const dt = new Date(date.valueOf());
@@ -1,5 +1,5 @@
1
- const YEAR = "yyyy";
2
- const DAY = "mm/dd/yyyy";
1
+ const YEAR = "YYYY";
2
+ const DAY = "MM/DD/YYYY";
3
3
  const DAY_TIME = "HH:mm:ss";
4
4
  const MONTH_DAY = "dd";
5
5
  const YEAR_MONTH = "M";
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,15 @@
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
+ }
@@ -1,6 +1,7 @@
1
1
  import { IDateFormat } from "../interfaces/IDateFormat";
2
2
  /**
3
3
  * A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
4
+ * - Some strings are valid
4
5
  * @param date String with a formatted date
5
6
  * @param format The date format
6
7
  * @returns a formmatted date or the same value if format does not match
@@ -6,27 +6,28 @@ import { dateToYear } from "../adapters/dateToYear";
6
6
  import { DATE_FORMAT } from "../constants/DATE_FORMAT";
7
7
  /**
8
8
  * A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
9
+ * - Some strings are valid
9
10
  * @param date String with a formatted date
10
11
  * @param format The date format
11
12
  * @returns a formmatted date or the same value if format does not match
12
13
  */
13
14
  export function getFormattedDateByFormat(date, format) {
14
- if (format === DATE_FORMAT.QUARTER) {
15
- return dateToQuarterYear(date);
16
- }
17
- else if (format === DATE_FORMAT.MONTH) {
18
- return dateToMonthYear(date);
19
- }
20
- else if (format === DATE_FORMAT.YEAR) {
21
- return dateToYear(date);
22
- }
23
- else if (format === DATE_FORMAT.WEEK) {
24
- return dateToWeekYear(date);
25
- }
26
- else if (format === DATE_FORMAT.DAY) {
27
- return dateToMdyDate(date);
28
- }
29
- else {
30
- return date;
15
+ switch (format) {
16
+ case DATE_FORMAT.YEAR:
17
+ return dateToYear(date);
18
+ case DATE_FORMAT.MONTH:
19
+ return dateToMonthYear(date);
20
+ case DATE_FORMAT.QUARTER:
21
+ return dateToQuarterYear(date);
22
+ case DATE_FORMAT.WEEK:
23
+ return dateToWeekYear(date);
24
+ case DATE_FORMAT.DAY:
25
+ return dateToMdyDate(date);
26
+ case DATE_FORMAT.HOUR:
27
+ case DATE_FORMAT.MINUTE:
28
+ case DATE_FORMAT.SECOND:
29
+ return dateToMdyDate(date, true);
30
+ default:
31
+ return date;
31
32
  }
32
33
  }
@@ -1,3 +1,4 @@
1
+ export * from "./adjustTimezone";
1
2
  export * from "./getDateByDateFormat";
2
3
  export * from "./getDateFormatByProperty";
3
4
  export * from "./getDateFormatRegularExpressionInArray";
@@ -6,4 +7,5 @@ export * from "./getFormattedDateByFormat";
6
7
  export * from "./getSeparatorByDateFormat";
7
8
  export * from "./includeDateTokens";
8
9
  export * from "./getWeek";
10
+ export * from "./isValidPotentialDate";
9
11
  export * from "./validateDate";
@@ -1,3 +1,4 @@
1
+ export * from "./adjustTimezone";
1
2
  export * from "./getDateByDateFormat";
2
3
  export * from "./getDateFormatByProperty";
3
4
  export * from "./getDateFormatRegularExpressionInArray";
@@ -6,4 +7,5 @@ export * from "./getFormattedDateByFormat";
6
7
  export * from "./getSeparatorByDateFormat";
7
8
  export * from "./includeDateTokens";
8
9
  export * from "./getWeek";
10
+ export * from "./isValidPotentialDate";
9
11
  export * from "./validateDate";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Checks if the given date is allowed to continue the process for adapting dates
3
+ * @param {string | Date | number} date String, object or millisencond number of the date
4
+ * @returns true: the date is valid.
5
+ */
6
+ export declare function isValidPotentialDate(date: string | Date | number): boolean;
@@ -0,0 +1,14 @@
1
+ import { isEmpty } from "../../general/mix/isEmpty";
2
+ import { isTokenLabel } from "../../tokens/isTokenLabel";
3
+ /**
4
+ * Checks if the given date is allowed to continue the process for adapting dates
5
+ * @param {string | Date | number} date String, object or millisencond number of the date
6
+ * @returns true: the date is valid.
7
+ */
8
+ export function isValidPotentialDate(date) {
9
+ return (!isEmpty(date) &&
10
+ !isTokenLabel(date) &&
11
+ ((date instanceof Date && !isNaN(date)) ||
12
+ typeof date === "string" ||
13
+ typeof date === "number"));
14
+ }
@@ -0,0 +1,5 @@
1
+ import { IRelativeUnitInfo } from "../interfaces/IRelativeUnitInfo";
2
+ /**
3
+ * @description Key/array of compound relative unit info of date-time
4
+ */
5
+ export declare const RELATIVE_DATE_TIME_UNIT_INFO_LIST: IRelativeUnitInfo[];
@@ -0,0 +1,9 @@
1
+ import { RELATIVE_UNIT_INFO } from "./RELATIVE_UNIT_INFO";
2
+ /**
3
+ * @description Key/array of compound relative unit info of date-time
4
+ */
5
+ export const RELATIVE_DATE_TIME_UNIT_INFO_LIST = [
6
+ RELATIVE_UNIT_INFO.HOUR,
7
+ RELATIVE_UNIT_INFO.MINUTE,
8
+ RELATIVE_UNIT_INFO.SECOND,
9
+ ];
@@ -0,0 +1,5 @@
1
+ import { IRelativeUnitInfo } from "../interfaces/IRelativeUnitInfo";
2
+ /**
3
+ * @description Key/array of compound relative unit info of dates
4
+ */
5
+ export declare const RELATIVE_DATE_UNIT_INFO_LIST: IRelativeUnitInfo[];
@@ -1,8 +1,8 @@
1
1
  import { RELATIVE_UNIT_INFO } from "./RELATIVE_UNIT_INFO";
2
2
  /**
3
- * @description Key/array of compound relative cursor info
3
+ * @description Key/array of compound relative unit info of dates
4
4
  */
5
- export const RELATIVE_UNIT_INFO_LIST = [
5
+ export const RELATIVE_DATE_UNIT_INFO_LIST = [
6
6
  RELATIVE_UNIT_INFO["YEAR"],
7
7
  RELATIVE_UNIT_INFO["QUARTER"],
8
8
  RELATIVE_UNIT_INFO["MONTH"],
@@ -1,4 +1,5 @@
1
1
  import { DATE_GROUPING_PROPERTY } from "../../constants/DATE_GROUPING_PROPERTY";
2
+ import { DATE_GROUPING_TIME_PROPERTY } from "../../constants/DATE_GROUPING_TIME_PROPERTY";
2
3
  export const RELATIVE_UNIT_INFO = {
3
4
  DAY: {
4
5
  abbrLabel: "Day",
@@ -40,4 +41,28 @@ export const RELATIVE_UNIT_INFO = {
40
41
  displayed: true,
41
42
  i18nLabelPath: "common.units.year",
42
43
  },
44
+ HOUR: {
45
+ abbrLabel: "Hour",
46
+ shortLabel: "Hour",
47
+ label: "Hour",
48
+ value: DATE_GROUPING_TIME_PROPERTY.HOUR,
49
+ displayed: true,
50
+ i18nLabelPath: "common.units.hour",
51
+ },
52
+ MINUTE: {
53
+ abbrLabel: "Minute",
54
+ shortLabel: "Minute",
55
+ label: "Minute",
56
+ value: DATE_GROUPING_TIME_PROPERTY.MINUTE,
57
+ displayed: false,
58
+ i18nLabelPath: "common.units.minute",
59
+ },
60
+ SECOND: {
61
+ abbrLabel: "Second",
62
+ shortLabel: "Second",
63
+ label: "Second",
64
+ value: DATE_GROUPING_TIME_PROPERTY.SECOND,
65
+ displayed: false,
66
+ i18nLabelPath: "common.units.second",
67
+ },
43
68
  };
@@ -4,6 +4,7 @@ export * from "./RELATIVE_CURSOR";
4
4
  export * from "./RELATIVE_CURSOR_INFO_LIST";
5
5
  export * from "./RELATIVE_CURSOR_INFO";
6
6
  export * from "./RELATIVE_CURSOR_LABEL";
7
- export * from "./RELATIVE_UNIT_INFO_LIST";
7
+ export * from "./RELATIVE_DATE_TIME_UNIT_INFO_LIST";
8
+ export * from "./RELATIVE_DATE_UNIT_INFO_LIST";
8
9
  export * from "./RELATIVE_UNIT_INFO";
9
10
  export * from "./ui/index";
@@ -4,6 +4,7 @@ export * from "./RELATIVE_CURSOR";
4
4
  export * from "./RELATIVE_CURSOR_INFO_LIST";
5
5
  export * from "./RELATIVE_CURSOR_INFO";
6
6
  export * from "./RELATIVE_CURSOR_LABEL";
7
- export * from "./RELATIVE_UNIT_INFO_LIST";
7
+ export * from "./RELATIVE_DATE_TIME_UNIT_INFO_LIST";
8
+ export * from "./RELATIVE_DATE_UNIT_INFO_LIST";
8
9
  export * from "./RELATIVE_UNIT_INFO";
9
10
  export * from "./ui/index";
@@ -1,2 +1,3 @@
1
+ import { DATE_GROUPING_TIME_PROPERTY } from "../../constants/DATE_GROUPING_TIME_PROPERTY";
1
2
  import { DATE_GROUPING_PROPERTY } from "../../constants/DATE_GROUPING_PROPERTY";
2
- export declare type IRelativeUnit = keyof typeof DATE_GROUPING_PROPERTY;
3
+ export declare type IRelativeUnit = keyof typeof DATE_GROUPING_PROPERTY | keyof typeof DATE_GROUPING_TIME_PROPERTY;
@@ -1,7 +1,10 @@
1
1
  export interface II18nUnits {
2
2
  day: string;
3
+ hour: string;
4
+ minute: string;
3
5
  month: string;
4
6
  quarter: string;
7
+ second: string;
5
8
  week: string;
6
9
  year: string;
7
10
  }
@@ -10,4 +10,5 @@ export interface II18nRelativeContainer {
10
10
  starting_date_tooltip: string;
11
11
  starting_from: string;
12
12
  set_current_date: string;
13
+ utc_tooltip: string;
13
14
  }
@@ -22,8 +22,11 @@ export const I18N_COMMON = {
22
22
  search: "Search",
23
23
  units: {
24
24
  day: RELATIVE_UNIT_INFO.DAY.label,
25
+ hour: RELATIVE_UNIT_INFO.HOUR.label,
26
+ minute: RELATIVE_UNIT_INFO.MINUTE.label,
25
27
  month: RELATIVE_UNIT_INFO.MONTH.label,
26
28
  quarter: RELATIVE_UNIT_INFO.QUARTER.label,
29
+ second: RELATIVE_UNIT_INFO.SECOND.label,
27
30
  week: RELATIVE_UNIT_INFO.WEEK.label,
28
31
  year: RELATIVE_UNIT_INFO.YEAR.label,
29
32
  },
@@ -10,4 +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
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
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,6 +24,7 @@
24
24
  "devDependencies": {
25
25
  "@compodoc/compodoc": "1.1.19",
26
26
  "@types/jest": "27.5.1",
27
+ "@types/responselike": "1.0.0",
27
28
  "@typescript-eslint/eslint-plugin": "5.26.0",
28
29
  "@typescript-eslint/parser": "5.26.0",
29
30
  "eslint": "8.16.0",
@@ -1,5 +0,0 @@
1
- import { IRelativeUnitInfo } from "../interfaces/IRelativeUnitInfo";
2
- /**
3
- * @description Key/array of compound relative cursor info
4
- */
5
- export declare const RELATIVE_UNIT_INFO_LIST: IRelativeUnitInfo[];
@@ -1,5 +0,0 @@
1
- import { IRelativeUnitInfo } from "../interfaces/IRelativeUnitInfo";
2
- /**
3
- * @description Key/array of compound relative cursor info
4
- */
5
- export declare const RELATIVE_UNIT_INFO_LIST: IRelativeUnitInfo[];