@carlosdiazz/lottodiz-shared 1.9.2 → 1.9.3

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,10 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../utils");
4
3
  const main = async () => {
5
4
  //const date = new Date("2025-10-22");
6
5
  //validateDate(date, ["test"]);
7
- //console.log(date);
8
- console.log((0, utils_1.getDelayFromTime)("19:00:45"));
6
+ //console.log(date);America/Santo_Domingo America/New_York
7
+ //console.log(
8
+ // convertTimeZone("14:30:00", "America/New_York", "America/Santo_Domingo")
9
+ //);
10
+ //
11
+ //console.log(
12
+ // convertTimeZone("23:30:00", "America/New_York", "America/Santo_Domingo")
13
+ //);
14
+ //
15
+ //console.log(
16
+ // convertTimeZone("00:00:00", "America/Santo_Domingo", "America/New_York")
17
+ //);
9
18
  };
10
19
  main();
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Convierte una hora entre zonas horarias con soporte DST y límites entre 00:00:00 y 23:59:00
3
+ * @param time - Hora base en formato "HH:mm:ss"
4
+ * @param timeZone - Zona horaria original (ej: "America/Santo_Domingo")
5
+ * @param timeZoneChange - Zona horaria destino (ej: "America/New_York")
6
+ * @returns Nueva hora en formato "HH:mm:ss"
7
+ */
8
+ export declare function convertTimeZone(time: string, timeZone: string, timeZoneChange: string): string;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertTimeZone = convertTimeZone;
4
+ const luxon_1 = require("luxon");
5
+ /**
6
+ * Convierte una hora entre zonas horarias con soporte DST y límites entre 00:00:00 y 23:59:00
7
+ * @param time - Hora base en formato "HH:mm:ss"
8
+ * @param timeZone - Zona horaria original (ej: "America/Santo_Domingo")
9
+ * @param timeZoneChange - Zona horaria destino (ej: "America/New_York")
10
+ * @returns Nueva hora en formato "HH:mm:ss"
11
+ */
12
+ function convertTimeZone(time, timeZone, timeZoneChange) {
13
+ // Si las zonas son iguales, retornamos la misma hora
14
+ if (timeZone === timeZoneChange)
15
+ return time;
16
+ // Parseamos la hora base
17
+ const [hours, minutes, seconds] = time.split(":").map(Number);
18
+ // Fecha base (hoy)
19
+ const base = luxon_1.DateTime.now()
20
+ .setZone(timeZone)
21
+ .set({ hour: hours, minute: minutes, second: seconds, millisecond: 0 });
22
+ // Convertimos a la nueva zona horaria
23
+ const converted = base.setZone(timeZoneChange);
24
+ // Si el cambio de zona altera el día (por ejemplo pasa de 23:30 a 00:30 del día siguiente)
25
+ // entonces ajustamos a los límites
26
+ if (converted.day > base.day) {
27
+ // Se pasó al día siguiente → límite superior
28
+ return "23:59:00";
29
+ }
30
+ if (converted.day < base.day) {
31
+ // Retrocedió al día anterior → límite inferior
32
+ return "00:00:00";
33
+ }
34
+ // Si el día no cambió, devolvemos la hora real convertida
35
+ const hh = converted.hour;
36
+ const mm = converted.minute;
37
+ const ss = converted.second;
38
+ const pad = (n) => n.toString().padStart(2, "0");
39
+ return `${pad(hh)}:${pad(mm)}:${pad(ss)}`;
40
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./convert-date-to-string";
2
+ export * from "./convert-time-zone";
2
3
  export * from "./convert-to-number-array";
3
4
  export * from "./create-interval-array";
4
5
  export * from "./deep-partial";
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./convert-date-to-string"), exports);
18
+ __exportStar(require("./convert-time-zone"), exports);
18
19
  __exportStar(require("./convert-to-number-array"), exports);
19
20
  __exportStar(require("./create-interval-array"), exports);
20
21
  __exportStar(require("./deep-partial"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carlosdiazz/lottodiz-shared",
3
- "version": "1.9.2",
3
+ "version": "1.9.3",
4
4
  "description": "Shared Dtos, models, constants and utils",
5
5
  "main": "dist/index.js",
6
6
  "private": false,
@@ -14,9 +14,11 @@
14
14
  },
15
15
  "license": "MIT",
16
16
  "devDependencies": {
17
+ "@types/luxon": "^3.7.1",
17
18
  "typescript": "^5.9.3"
18
19
  },
19
20
  "dependencies": {
20
- "dayjs": "^1.11.18"
21
+ "dayjs": "^1.11.18",
22
+ "luxon": "^3.7.2"
21
23
  }
22
24
  }