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.
@@ -1,5 +1,5 @@
1
1
  import { ValueTransformer } from "typeorm";
2
2
  export declare class DateTransformer implements ValueTransformer {
3
3
  to(value: Date | string): string;
4
- from(value: string): Date | null | string;
4
+ from(value: string): Date | null;
5
5
  }
@@ -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
- const result = (0, moment_timezone_1.default)(value).format("YYYY-MM-DD HH:mm:ss");
12
- return result;
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 === null)
17
+ if (!value)
16
18
  return null;
17
- const result = moment_timezone_1.default.utc(value).tz((0, __1.getTimeZone)()).toDate();
18
- return result;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "3.9.13",
3
+ "version": "3.9.15",
4
4
  "description": "Entidades de ejemplo para una base de datos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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
- const result = moment(value).format("YYYY-MM-DD HH:mm:ss");
8
- return result;
8
+ // Guardamos en UTC puro
9
+ return moment(value).utc().format("YYYY-MM-DD HH:mm:ss");
9
10
  }
10
11
 
11
- from(value: string): Date | null | string {
12
- if (value === null) return null;
12
+ // Cuando leemos de DB
13
+ from(value: string): Date | null {
14
+ if (!value) return null;
13
15
 
14
- const result = moment.utc(value).tz(getTimeZone()).toDate();
15
- return result;
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
  }