plac-micro-common 1.3.55 → 1.3.56

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.
@@ -14,6 +14,8 @@ exports.formatAmount = formatAmount;
14
14
  exports.roundAmount = roundAmount;
15
15
  exports.calculateAge = calculateAge;
16
16
  const dayjs_1 = __importDefault(require("dayjs"));
17
+ const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
18
+ dayjs_1.default.extend(customParseFormat_1.default);
17
19
  const constants_1 = require("../../constants");
18
20
  function delay(ms) {
19
21
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -50,7 +52,27 @@ function formatDateTime(value, format = constants_1.DISPLAY_DATE_TIME_FORMAT) {
50
52
  function formatServerDate(value) {
51
53
  if (!value)
52
54
  return null;
53
- const date = (0, dayjs_1.default)(value);
55
+ const INPUT_FORMATS = [
56
+ "YYYY-MM-DD",
57
+ "DD/MM/YYYY",
58
+ "MM/DD/YYYY",
59
+ "YYYY/MM/DD",
60
+ "DD-MM-YYYY",
61
+ "YYYY-MM-DDTHH:mm:ss",
62
+ ];
63
+ let date;
64
+ if (value instanceof Date || typeof value === "number") {
65
+ date = (0, dayjs_1.default)(value);
66
+ }
67
+ else if (typeof value === "string") {
68
+ date = (0, dayjs_1.default)(value, INPUT_FORMATS, true);
69
+ if (!date.isValid()) {
70
+ date = (0, dayjs_1.default)(value);
71
+ }
72
+ }
73
+ else {
74
+ return null;
75
+ }
54
76
  if (!date.isValid())
55
77
  return null;
56
78
  return date.format(constants_1.SERVER_DATE_FORMAT);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plac-micro-common",
3
- "version": "1.3.55",
3
+ "version": "1.3.56",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {