@zauru-sdk/common 1.0.98 → 1.0.99

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.99](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.98...v1.0.99) (2024-09-13)
7
+
8
+ **Note:** Version bump only for package @zauru-sdk/common
9
+
10
+
11
+
12
+
13
+
6
14
  ## [1.0.98](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.97...v1.0.98) (2024-09-11)
7
15
 
8
16
  **Note:** Version bump only for package @zauru-sdk/common
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.calculateTimeDifference = exports.parsedObject = exports.createPostgresUrl = exports.handlePossibleAxiosErrors = exports.sortByProperty = exports.capitalLetter = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.reduceAdd = exports.ZAURU_REGEX = exports.convertToFormData = exports.arrayToObject = exports.getParsedIdFromString = exports.incrementString = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.formatDateToUTC = exports.extractIdFromForm = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.getDatePickerCurrentDate = exports.isToday = exports.todayLongString = exports.zauruDateToLongString = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.truncateText = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.isJsonArray = exports.extractValueBetweenTags = exports.generateClientUUID = exports.getBasketsSchema = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
6
+ exports.calculateTimeDifference = exports.parsedObject = exports.createPostgresUrl = exports.handlePossibleAxiosErrors = exports.sortByProperty = exports.capitalLetter = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.reduceAdd = exports.ZAURU_REGEX = exports.convertToFormData = exports.arrayToObject = exports.getParsedIdFromString = exports.incrementString = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.formatDateToUTC = exports.extractIdFromForm = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.getDatePickerCurrentDate = exports.isToday = exports.todayLongString = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.truncateText = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.isJsonArray = exports.extractValueBetweenTags = exports.generateClientUUID = exports.getBasketsSchema = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
7
7
  const moment_1 = __importDefault(require("moment"));
8
8
  require("moment-timezone");
9
9
  const types_1 = require("@zauru-sdk/types");
@@ -192,28 +192,6 @@ const stringDateToParsedUTCDate = (date) => {
192
192
  return issueDate;
193
193
  };
194
194
  exports.stringDateToParsedUTCDate = stringDateToParsedUTCDate;
195
- /**
196
- * zauruDateToLongString
197
- * @param date
198
- * @returns
199
- */
200
- function zauruDateToLongString(date, hours = false, utc = true) {
201
- if (!date) {
202
- return "invalid date:zauruDateToLongString";
203
- }
204
- // Asume que la fecha de entrada está en UTC y la convierte a la zona horaria local del navegador
205
- let issueDate = moment_1.default.utc(date).local();
206
- if (!utc) {
207
- issueDate = moment_1.default.utc(date).local(true);
208
- }
209
- let formatString = "dddd, D [de] MMMM [de] YYYY";
210
- if (hours) {
211
- formatString += ", HH:mm a"; // Añade la hora en formato de 12 horas con AM/PM
212
- }
213
- // Formatea la fecha en el locale español
214
- return issueDate.locale("es").format(formatString);
215
- }
216
- exports.zauruDateToLongString = zauruDateToLongString;
217
195
  /**
218
196
  * todayLongString
219
197
  * @param date
@@ -331,22 +309,60 @@ function formatDateToUTC(dateString) {
331
309
  return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`;
332
310
  }
333
311
  exports.formatDateToUTC = formatDateToUTC;
334
- // Función para obtener la fecha formateada en español
335
- const getFormattedDate = (dateString, utc = false) => {
336
- const now = dateString ? new Date(dateString) : new Date();
312
+ /**
313
+ * IMPORTANTE: Esta función está diseñada para funcionar solo en el lado del cliente.
314
+ * Para renderizado del lado del servidor, utilice una función alternativa.
315
+ *
316
+ * Función para obtener la fecha formateada en español
317
+ * @param dateString - Cadena de fecha opcional
318
+ * @param withHours - Indica si se debe incluir la hora en el formato
319
+ * @returns Fecha formateada en español
320
+ */
321
+ const getFormattedDate = (dateString, withHours = true) => {
322
+ let date;
323
+ if (dateString) {
324
+ // Detectar el formato de la fecha
325
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(dateString)) {
326
+ // Formato ISO (UTC)
327
+ date = new Date(dateString);
328
+ // Ajustar a la hora local
329
+ date = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
330
+ }
331
+ else if (/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
332
+ // Formato YYYY-MM-DD
333
+ date = new Date(`${dateString}T00:00:00`); // Hora local
334
+ }
335
+ else if (/^\d{2}-\d{2}-\d{4}$/.test(dateString)) {
336
+ // Formato DD-MM-YYYY
337
+ const [day, month, year] = dateString.split("-");
338
+ date = new Date(`${year}-${month}-${day}T00:00:00`); // Hora local
339
+ }
340
+ else if (/^\d{2}\/\d{2}\/\d{4}$/.test(dateString)) {
341
+ // Formato DD/MM/YYYY
342
+ const [day, month, year] = dateString.split("/");
343
+ date = new Date(`${year}-${month}-${day}T00:00:00`); // Hora local
344
+ }
345
+ else {
346
+ throw new Error("Formato de fecha no reconocido");
347
+ }
348
+ }
349
+ else {
350
+ date = new Date(); // Fecha actual en hora local
351
+ }
337
352
  const options = {
338
353
  weekday: "long",
339
354
  day: "numeric",
340
355
  month: "long",
341
356
  year: "numeric",
342
- hour: "numeric",
343
- minute: "numeric",
344
- hour12: false,
357
+ timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, // Obtiene la zona horaria del usuario
345
358
  };
346
- if (utc) {
347
- options["timeZone"] = "UTC";
359
+ if (withHours) {
360
+ options.hour = "numeric";
361
+ options.minute = "numeric";
362
+ options.second = "numeric";
363
+ options.hour12 = false;
348
364
  }
349
- return new Intl.DateTimeFormat("es-ES", options).format(now);
365
+ return new Intl.DateTimeFormat("es-ES", options).format(date);
350
366
  };
351
367
  exports.getFormattedDate = getFormattedDate;
352
368
  const formatDateToDatePicker = (date) => {
package/dist/common.d.ts CHANGED
@@ -60,12 +60,6 @@ export declare const getStringFullDate: (date: Date) => string;
60
60
  */
61
61
  export declare const localDateToUSDate: (dateStr: string) => string;
62
62
  export declare const stringDateToParsedUTCDate: (date: string) => Date;
63
- /**
64
- * zauruDateToLongString
65
- * @param date
66
- * @returns
67
- */
68
- export declare function zauruDateToLongString(date: string, hours?: boolean, utc?: boolean): string;
69
63
  /**
70
64
  * todayLongString
71
65
  * @param date
@@ -94,7 +88,16 @@ export declare function extractIdFromForm(s: string): number | null;
94
88
  * @returns
95
89
  */
96
90
  export declare function formatDateToUTC(dateString: string): string;
97
- export declare const getFormattedDate: (dateString?: string, utc?: boolean) => string;
91
+ /**
92
+ * IMPORTANTE: Esta función está diseñada para funcionar solo en el lado del cliente.
93
+ * Para renderizado del lado del servidor, utilice una función alternativa.
94
+ *
95
+ * Función para obtener la fecha formateada en español
96
+ * @param dateString - Cadena de fecha opcional
97
+ * @param withHours - Indica si se debe incluir la hora en el formato
98
+ * @returns Fecha formateada en español
99
+ */
100
+ export declare const getFormattedDate: (dateString?: string, withHours?: boolean) => string;
98
101
  export declare const formatDateToDatePicker: (date: Date) => string;
99
102
  export declare const formatTimeToTimePicker: (timeString: string) => Date;
100
103
  export declare const toFixedIfNeeded: (value: number) => string;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.calculateTimeDifference = exports.parsedObject = exports.createPostgresUrl = exports.handlePossibleAxiosErrors = exports.sortByProperty = exports.capitalLetter = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.reduceAdd = exports.ZAURU_REGEX = exports.convertToFormData = exports.arrayToObject = exports.getParsedIdFromString = exports.incrementString = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.formatDateToUTC = exports.extractIdFromForm = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.getDatePickerCurrentDate = exports.isToday = exports.todayLongString = exports.zauruDateToLongString = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.truncateText = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.isJsonArray = exports.extractValueBetweenTags = exports.generateClientUUID = exports.getBasketsSchema = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
6
+ exports.calculateTimeDifference = exports.parsedObject = exports.createPostgresUrl = exports.handlePossibleAxiosErrors = exports.sortByProperty = exports.capitalLetter = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.reduceAdd = exports.ZAURU_REGEX = exports.convertToFormData = exports.arrayToObject = exports.getParsedIdFromString = exports.incrementString = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.formatDateToUTC = exports.extractIdFromForm = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.getDatePickerCurrentDate = exports.isToday = exports.todayLongString = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.truncateText = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.isJsonArray = exports.extractValueBetweenTags = exports.generateClientUUID = exports.getBasketsSchema = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
7
7
  const moment_1 = __importDefault(require("moment"));
8
8
  require("moment-timezone");
9
9
  const types_1 = require("@zauru-sdk/types");
@@ -192,28 +192,6 @@ const stringDateToParsedUTCDate = (date) => {
192
192
  return issueDate;
193
193
  };
194
194
  exports.stringDateToParsedUTCDate = stringDateToParsedUTCDate;
195
- /**
196
- * zauruDateToLongString
197
- * @param date
198
- * @returns
199
- */
200
- function zauruDateToLongString(date, hours = false, utc = true) {
201
- if (!date) {
202
- return "invalid date:zauruDateToLongString";
203
- }
204
- // Asume que la fecha de entrada está en UTC y la convierte a la zona horaria local del navegador
205
- let issueDate = moment_1.default.utc(date).local();
206
- if (!utc) {
207
- issueDate = moment_1.default.utc(date).local(true);
208
- }
209
- let formatString = "dddd, D [de] MMMM [de] YYYY";
210
- if (hours) {
211
- formatString += ", HH:mm a"; // Añade la hora en formato de 12 horas con AM/PM
212
- }
213
- // Formatea la fecha en el locale español
214
- return issueDate.locale("es").format(formatString);
215
- }
216
- exports.zauruDateToLongString = zauruDateToLongString;
217
195
  /**
218
196
  * todayLongString
219
197
  * @param date
@@ -331,22 +309,60 @@ function formatDateToUTC(dateString) {
331
309
  return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`;
332
310
  }
333
311
  exports.formatDateToUTC = formatDateToUTC;
334
- // Función para obtener la fecha formateada en español
335
- const getFormattedDate = (dateString, utc = false) => {
336
- const now = dateString ? new Date(dateString) : new Date();
312
+ /**
313
+ * IMPORTANTE: Esta función está diseñada para funcionar solo en el lado del cliente.
314
+ * Para renderizado del lado del servidor, utilice una función alternativa.
315
+ *
316
+ * Función para obtener la fecha formateada en español
317
+ * @param dateString - Cadena de fecha opcional
318
+ * @param withHours - Indica si se debe incluir la hora en el formato
319
+ * @returns Fecha formateada en español
320
+ */
321
+ const getFormattedDate = (dateString, withHours = true) => {
322
+ let date;
323
+ if (dateString) {
324
+ // Detectar el formato de la fecha
325
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(dateString)) {
326
+ // Formato ISO (UTC)
327
+ date = new Date(dateString);
328
+ // Ajustar a la hora local
329
+ date = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
330
+ }
331
+ else if (/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
332
+ // Formato YYYY-MM-DD
333
+ date = new Date(`${dateString}T00:00:00`); // Hora local
334
+ }
335
+ else if (/^\d{2}-\d{2}-\d{4}$/.test(dateString)) {
336
+ // Formato DD-MM-YYYY
337
+ const [day, month, year] = dateString.split("-");
338
+ date = new Date(`${year}-${month}-${day}T00:00:00`); // Hora local
339
+ }
340
+ else if (/^\d{2}\/\d{2}\/\d{4}$/.test(dateString)) {
341
+ // Formato DD/MM/YYYY
342
+ const [day, month, year] = dateString.split("/");
343
+ date = new Date(`${year}-${month}-${day}T00:00:00`); // Hora local
344
+ }
345
+ else {
346
+ throw new Error("Formato de fecha no reconocido");
347
+ }
348
+ }
349
+ else {
350
+ date = new Date(); // Fecha actual en hora local
351
+ }
337
352
  const options = {
338
353
  weekday: "long",
339
354
  day: "numeric",
340
355
  month: "long",
341
356
  year: "numeric",
342
- hour: "numeric",
343
- minute: "numeric",
344
- hour12: false,
357
+ timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, // Obtiene la zona horaria del usuario
345
358
  };
346
- if (utc) {
347
- options["timeZone"] = "UTC";
359
+ if (withHours) {
360
+ options.hour = "numeric";
361
+ options.minute = "numeric";
362
+ options.second = "numeric";
363
+ options.hour12 = false;
348
364
  }
349
- return new Intl.DateTimeFormat("es-ES", options).format(now);
365
+ return new Intl.DateTimeFormat("es-ES", options).format(date);
350
366
  };
351
367
  exports.getFormattedDate = getFormattedDate;
352
368
  const formatDateToDatePicker = (date) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/common",
3
- "version": "1.0.98",
3
+ "version": "1.0.99",
4
4
  "description": "Funciones de uso común en el desarrollo de webapps en Zauru",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -25,5 +25,5 @@
25
25
  "moment": "^2.30.1",
26
26
  "moment-timezone": "^0.5.45"
27
27
  },
28
- "gitHead": "e3b92fe4d2aea4be988540f6b233f0a27eb72a40"
28
+ "gitHead": "ad07b6fa1ffed108a45c2ae3e043e2168664dfb5"
29
29
  }
package/src/common.ts CHANGED
@@ -213,36 +213,6 @@ export const stringDateToParsedUTCDate = (date: string): Date => {
213
213
  return issueDate;
214
214
  };
215
215
 
216
- /**
217
- * zauruDateToLongString
218
- * @param date
219
- * @returns
220
- */
221
- export function zauruDateToLongString(
222
- date: string,
223
- hours: boolean = false,
224
- utc: boolean = true
225
- ) {
226
- if (!date) {
227
- return "invalid date:zauruDateToLongString";
228
- }
229
-
230
- // Asume que la fecha de entrada está en UTC y la convierte a la zona horaria local del navegador
231
- let issueDate = moment.utc(date).local();
232
-
233
- if (!utc) {
234
- issueDate = moment.utc(date).local(true);
235
- }
236
-
237
- let formatString = "dddd, D [de] MMMM [de] YYYY";
238
- if (hours) {
239
- formatString += ", HH:mm a"; // Añade la hora en formato de 12 horas con AM/PM
240
- }
241
-
242
- // Formatea la fecha en el locale español
243
- return issueDate.locale("es").format(formatString);
244
- }
245
-
246
216
  /**
247
217
  * todayLongString
248
218
  * @param date
@@ -382,24 +352,62 @@ export function formatDateToUTC(dateString: string): string {
382
352
  return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`;
383
353
  }
384
354
 
385
- // Función para obtener la fecha formateada en español
386
- export const getFormattedDate = (dateString?: string, utc: boolean = false) => {
387
- const now = dateString ? new Date(dateString) : new Date();
388
- const options = {
355
+ /**
356
+ * IMPORTANTE: Esta función está diseñada para funcionar solo en el lado del cliente.
357
+ * Para renderizado del lado del servidor, utilice una función alternativa.
358
+ *
359
+ * Función para obtener la fecha formateada en español
360
+ * @param dateString - Cadena de fecha opcional
361
+ * @param withHours - Indica si se debe incluir la hora en el formato
362
+ * @returns Fecha formateada en español
363
+ */
364
+ export const getFormattedDate = (
365
+ dateString?: string,
366
+ withHours: boolean = true
367
+ ) => {
368
+ let date: Date;
369
+
370
+ if (dateString) {
371
+ // Detectar el formato de la fecha
372
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(dateString)) {
373
+ // Formato ISO (UTC)
374
+ date = new Date(dateString);
375
+ // Ajustar a la hora local
376
+ date = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
377
+ } else if (/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
378
+ // Formato YYYY-MM-DD
379
+ date = new Date(`${dateString}T00:00:00`); // Hora local
380
+ } else if (/^\d{2}-\d{2}-\d{4}$/.test(dateString)) {
381
+ // Formato DD-MM-YYYY
382
+ const [day, month, year] = dateString.split("-");
383
+ date = new Date(`${year}-${month}-${day}T00:00:00`); // Hora local
384
+ } else if (/^\d{2}\/\d{2}\/\d{4}$/.test(dateString)) {
385
+ // Formato DD/MM/YYYY
386
+ const [day, month, year] = dateString.split("/");
387
+ date = new Date(`${year}-${month}-${day}T00:00:00`); // Hora local
388
+ } else {
389
+ throw new Error("Formato de fecha no reconocido");
390
+ }
391
+ } else {
392
+ date = new Date(); // Fecha actual en hora local
393
+ }
394
+
395
+ const options: Intl.DateTimeFormatOptions = {
389
396
  weekday: "long",
390
397
  day: "numeric",
391
398
  month: "long",
392
399
  year: "numeric",
393
- hour: "numeric",
394
- minute: "numeric",
395
- hour12: false,
396
- } as any;
400
+ timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, // Obtiene la zona horaria del usuario
401
+ };
397
402
 
398
- if (utc) {
399
- options["timeZone"] = "UTC";
403
+ if (withHours) {
404
+ options.hour = "numeric";
405
+ options.minute = "numeric";
406
+ options.second = "numeric";
407
+ options.hour12 = false;
400
408
  }
401
409
 
402
- return new Intl.DateTimeFormat("es-ES", options as any).format(now);
410
+ return new Intl.DateTimeFormat("es-ES", options).format(date);
403
411
  };
404
412
 
405
413
  export const formatDateToDatePicker = (date: Date) => {