test-entity-library-asm 1.7.6 → 1.7.7
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,7 +1,5 @@
|
|
|
1
1
|
import { ValueTransformer } from 'typeorm';
|
|
2
2
|
export declare class DateTransformer implements ValueTransformer {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
to(value: Date): Date;
|
|
6
|
-
from(value: Date): string;
|
|
3
|
+
to(value: string): string;
|
|
4
|
+
from(value: string): string;
|
|
7
5
|
}
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DateTransformer = void 0;
|
|
4
|
-
var
|
|
5
|
-
var __1 = require("..");
|
|
4
|
+
var moment = require("moment-timezone");
|
|
6
5
|
var DateTransformer = /** @class */ (function () {
|
|
7
|
-
function DateTransformer(
|
|
8
|
-
if (format === void 0) { format = 'yyyy-MM-dd HH:mm:ss'; }
|
|
9
|
-
this.format = format;
|
|
6
|
+
function DateTransformer() {
|
|
10
7
|
}
|
|
11
8
|
DateTransformer.prototype.to = function (value) {
|
|
12
|
-
|
|
13
|
-
console.log("Converted date: ".concat((0, date_fns_tz_1.toDate)(value), " TEST TO"));
|
|
14
|
-
return (0, date_fns_tz_1.toDate)(value); // Assuming the input is already in UTC
|
|
9
|
+
return value; // Deja la fecha en UTC al guardar en la base de datos
|
|
15
10
|
};
|
|
16
11
|
DateTransformer.prototype.from = function (value) {
|
|
17
|
-
|
|
18
|
-
console.log("Converting ".concat(value, " from UTC to ").concat(timeZone));
|
|
19
|
-
var zonedDate = (0, date_fns_tz_1.toZonedTime)(value, timeZone);
|
|
20
|
-
console.log("Converted date: ".concat(zonedDate));
|
|
21
|
-
var formattedDate = (0, date_fns_tz_1.format)(zonedDate, this.format, { timeZone: timeZone });
|
|
22
|
-
console.log("Formatted date to return: ".concat(formattedDate));
|
|
23
|
-
return formattedDate;
|
|
12
|
+
return moment.utc(value).tz('America/Bogota').format('YYYY-MM-DD HH:mm:ss'); // Convierte de UTC a la zona horaria local al recuperar de la base de datos
|
|
24
13
|
};
|
|
25
14
|
return DateTransformer;
|
|
26
15
|
}());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-entity-library-asm",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"description": "Entidades de ejemplo para una base de datos",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"date-fns-tz": "^3.1.3",
|
|
16
16
|
"dotenv": "^16.4.5",
|
|
17
17
|
"express": "^4.19.2",
|
|
18
|
+
"moment-timezone": "^0.5.45",
|
|
18
19
|
"typeorm": "^0.3.20"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
// dateTransformer.ts
|
|
2
1
|
import { ValueTransformer } from 'typeorm'
|
|
3
|
-
import
|
|
4
|
-
import { getTimeZone } from '..'
|
|
2
|
+
import * as moment from 'moment-timezone'
|
|
5
3
|
|
|
6
4
|
export class DateTransformer implements ValueTransformer {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(format: string = 'yyyy-MM-dd HH:mm:ss') {
|
|
10
|
-
this.format = format
|
|
5
|
+
to(value: string): string {
|
|
6
|
+
return value // Deja la fecha en UTC al guardar en la base de datos
|
|
11
7
|
}
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
console.log(`Converted date: ${toDate(value)} TEST TO`)
|
|
16
|
-
|
|
17
|
-
return toDate(value) // Assuming the input is already in UTC
|
|
18
|
-
}
|
|
19
|
-
from(value: Date): string {
|
|
20
|
-
const timeZone = getTimeZone()
|
|
21
|
-
console.log(`Converting ${value} from UTC to ${timeZone}`)
|
|
22
|
-
const zonedDate = toZonedTime(value, timeZone)
|
|
23
|
-
console.log(`Converted date: ${zonedDate}`)
|
|
24
|
-
const formattedDate = format(zonedDate, this.format, { timeZone })
|
|
25
|
-
console.log(`Formatted date to return: ${formattedDate}`)
|
|
26
|
-
return formattedDate
|
|
9
|
+
from(value: string): string {
|
|
10
|
+
return moment.utc(value).tz('America/Bogota').format('YYYY-MM-DD HH:mm:ss') // Convierte de UTC a la zona horaria local al recuperar de la base de datos
|
|
27
11
|
}
|
|
28
12
|
}
|