test-entity-library-asm 3.9.13 → 3.9.15
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.
|
@@ -7,15 +7,19 @@ exports.DateTransformer = void 0;
|
|
|
7
7
|
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
8
8
|
const __1 = require("..");
|
|
9
9
|
class DateTransformer {
|
|
10
|
+
// Cuando guardamos en DB
|
|
10
11
|
to(value) {
|
|
11
|
-
|
|
12
|
-
return
|
|
12
|
+
// Guardamos en UTC puro
|
|
13
|
+
return (0, moment_timezone_1.default)(value).utc().format("YYYY-MM-DD HH:mm:ss");
|
|
13
14
|
}
|
|
15
|
+
// Cuando leemos de DB
|
|
14
16
|
from(value) {
|
|
15
|
-
if (value
|
|
17
|
+
if (!value)
|
|
16
18
|
return null;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
+
const tz = (0, __1.getTimeZone)(); // Ej: "America/Bogota"
|
|
20
|
+
// Interpretamos el valor como UTC y luego lo convertimos a tz del usuario
|
|
21
|
+
const m = moment_timezone_1.default.tz(value, "YYYY-MM-DD HH:mm:ss", "UTC").tz(tz, true);
|
|
22
|
+
return m.toDate();
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
exports.DateTransformer = DateTransformer;
|
package/package.json
CHANGED
|
@@ -3,15 +3,19 @@ import moment from "moment-timezone";
|
|
|
3
3
|
import { getTimeZone } from "..";
|
|
4
4
|
|
|
5
5
|
export class DateTransformer implements ValueTransformer {
|
|
6
|
+
// Cuando guardamos en DB
|
|
6
7
|
to(value: Date | string): string {
|
|
7
|
-
|
|
8
|
-
return
|
|
8
|
+
// Guardamos en UTC puro
|
|
9
|
+
return moment(value).utc().format("YYYY-MM-DD HH:mm:ss");
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
// Cuando leemos de DB
|
|
13
|
+
from(value: string): Date | null {
|
|
14
|
+
if (!value) return null;
|
|
13
15
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
+
const tz = getTimeZone(); // Ej: "America/Bogota"
|
|
17
|
+
// Interpretamos el valor como UTC y luego lo convertimos a tz del usuario
|
|
18
|
+
const m = moment.tz(value, "YYYY-MM-DD HH:mm:ss", "UTC").tz(tz, true);
|
|
19
|
+
return m.toDate();
|
|
16
20
|
}
|
|
17
21
|
}
|