@zauru-sdk/common 1.0.75 → 1.0.80
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 +16 -0
- package/dist/cjs/common.js +31 -1
- package/dist/common.d.ts +5 -0
- package/dist/esm/common.js +31 -1
- package/package.json +3 -3
- package/src/common.ts +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.80](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.79...v1.0.80) (2024-07-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @zauru-sdk/common
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.0.76](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.75...v1.0.76) (2024-07-02)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @zauru-sdk/common
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [1.0.75](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.74...v1.0.75) (2024-06-19)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @zauru-sdk/common
|
package/dist/cjs/common.js
CHANGED
|
@@ -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.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.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.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;
|
|
7
7
|
const moment_1 = __importDefault(require("moment"));
|
|
8
8
|
require("moment-timezone");
|
|
9
9
|
const types_1 = require("@zauru-sdk/types");
|
|
@@ -331,6 +331,21 @@ function formatDateToUTC(dateString) {
|
|
|
331
331
|
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
332
332
|
}
|
|
333
333
|
exports.formatDateToUTC = formatDateToUTC;
|
|
334
|
+
// Función para obtener la fecha formateada en español
|
|
335
|
+
const getFormattedDate = (dateString) => {
|
|
336
|
+
const now = dateString ? new Date(dateString) : new Date();
|
|
337
|
+
const options = {
|
|
338
|
+
weekday: "long",
|
|
339
|
+
day: "numeric",
|
|
340
|
+
month: "long",
|
|
341
|
+
year: "numeric",
|
|
342
|
+
hour: "numeric",
|
|
343
|
+
minute: "numeric",
|
|
344
|
+
hour12: false,
|
|
345
|
+
};
|
|
346
|
+
return new Intl.DateTimeFormat("es-ES", options).format(now);
|
|
347
|
+
};
|
|
348
|
+
exports.getFormattedDate = getFormattedDate;
|
|
334
349
|
const formatDateToDatePicker = (date) => {
|
|
335
350
|
const year = date.getFullYear();
|
|
336
351
|
const month = `0${date.getMonth() + 1}`.slice(-2); // Los meses van de 0 a 11, así que le sumamos 1
|
|
@@ -549,3 +564,18 @@ const parsedObject = (obj) => {
|
|
|
549
564
|
}
|
|
550
565
|
};
|
|
551
566
|
exports.parsedObject = parsedObject;
|
|
567
|
+
function calculateTimeDifference(timestamp) {
|
|
568
|
+
const currentTime = (0, moment_1.default)();
|
|
569
|
+
const inputTime = (0, moment_1.default)(timestamp, "YYYY-MM-DD HH:mm:ss");
|
|
570
|
+
if (!inputTime.isValid()) {
|
|
571
|
+
throw new Error("Invalid timestamp format");
|
|
572
|
+
}
|
|
573
|
+
const duration = moment_1.default.duration(currentTime.diff(inputTime));
|
|
574
|
+
const hours = Math.floor(duration.asHours());
|
|
575
|
+
const minutes = Math.floor(duration.asMinutes()) % 60;
|
|
576
|
+
return {
|
|
577
|
+
hours: hours,
|
|
578
|
+
minutes: minutes,
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
exports.calculateTimeDifference = calculateTimeDifference;
|
package/dist/common.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ export declare function extractIdFromForm(s: string): number | null;
|
|
|
94
94
|
* @returns
|
|
95
95
|
*/
|
|
96
96
|
export declare function formatDateToUTC(dateString: string): string;
|
|
97
|
+
export declare const getFormattedDate: (dateString?: string) => string;
|
|
97
98
|
export declare const formatDateToDatePicker: (date: Date) => string;
|
|
98
99
|
export declare const formatTimeToTimePicker: (timeString: string) => Date;
|
|
99
100
|
export declare const toFixedIfNeeded: (value: number) => string;
|
|
@@ -154,3 +155,7 @@ export declare function handlePossibleAxiosErrors<T>(action: () => Promise<T>):
|
|
|
154
155
|
*/
|
|
155
156
|
export declare function createPostgresUrl(host?: any, port?: any, dbName?: any, user?: any, password?: any, schema?: any): string;
|
|
156
157
|
export declare const parsedObject: (obj: any) => any;
|
|
158
|
+
export declare function calculateTimeDifference(timestamp: string): {
|
|
159
|
+
hours: number;
|
|
160
|
+
minutes: number;
|
|
161
|
+
};
|
package/dist/esm/common.js
CHANGED
|
@@ -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.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.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.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;
|
|
7
7
|
const moment_1 = __importDefault(require("moment"));
|
|
8
8
|
require("moment-timezone");
|
|
9
9
|
const types_1 = require("@zauru-sdk/types");
|
|
@@ -331,6 +331,21 @@ function formatDateToUTC(dateString) {
|
|
|
331
331
|
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
332
332
|
}
|
|
333
333
|
exports.formatDateToUTC = formatDateToUTC;
|
|
334
|
+
// Función para obtener la fecha formateada en español
|
|
335
|
+
const getFormattedDate = (dateString) => {
|
|
336
|
+
const now = dateString ? new Date(dateString) : new Date();
|
|
337
|
+
const options = {
|
|
338
|
+
weekday: "long",
|
|
339
|
+
day: "numeric",
|
|
340
|
+
month: "long",
|
|
341
|
+
year: "numeric",
|
|
342
|
+
hour: "numeric",
|
|
343
|
+
minute: "numeric",
|
|
344
|
+
hour12: false,
|
|
345
|
+
};
|
|
346
|
+
return new Intl.DateTimeFormat("es-ES", options).format(now);
|
|
347
|
+
};
|
|
348
|
+
exports.getFormattedDate = getFormattedDate;
|
|
334
349
|
const formatDateToDatePicker = (date) => {
|
|
335
350
|
const year = date.getFullYear();
|
|
336
351
|
const month = `0${date.getMonth() + 1}`.slice(-2); // Los meses van de 0 a 11, así que le sumamos 1
|
|
@@ -549,3 +564,18 @@ const parsedObject = (obj) => {
|
|
|
549
564
|
}
|
|
550
565
|
};
|
|
551
566
|
exports.parsedObject = parsedObject;
|
|
567
|
+
function calculateTimeDifference(timestamp) {
|
|
568
|
+
const currentTime = (0, moment_1.default)();
|
|
569
|
+
const inputTime = (0, moment_1.default)(timestamp, "YYYY-MM-DD HH:mm:ss");
|
|
570
|
+
if (!inputTime.isValid()) {
|
|
571
|
+
throw new Error("Invalid timestamp format");
|
|
572
|
+
}
|
|
573
|
+
const duration = moment_1.default.duration(currentTime.diff(inputTime));
|
|
574
|
+
const hours = Math.floor(duration.asHours());
|
|
575
|
+
const minutes = Math.floor(duration.asMinutes()) % 60;
|
|
576
|
+
return {
|
|
577
|
+
hours: hours,
|
|
578
|
+
minutes: minutes,
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
exports.calculateTimeDifference = calculateTimeDifference;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.80",
|
|
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",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@remix-run/node": "^2.8.1",
|
|
24
|
-
"@zauru-sdk/types": "^1.0.
|
|
24
|
+
"@zauru-sdk/types": "^1.0.76",
|
|
25
25
|
"moment": "^2.30.1",
|
|
26
26
|
"moment-timezone": "^0.5.45"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "3da2a589e254d04992e8c76924142f4b5f7c54b6"
|
|
29
29
|
}
|
package/src/common.ts
CHANGED
|
@@ -382,6 +382,22 @@ export function formatDateToUTC(dateString: string): string {
|
|
|
382
382
|
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
+
// Función para obtener la fecha formateada en español
|
|
386
|
+
export const getFormattedDate = (dateString?: string) => {
|
|
387
|
+
const now = dateString ? new Date(dateString) : new Date();
|
|
388
|
+
const options = {
|
|
389
|
+
weekday: "long",
|
|
390
|
+
day: "numeric",
|
|
391
|
+
month: "long",
|
|
392
|
+
year: "numeric",
|
|
393
|
+
hour: "numeric",
|
|
394
|
+
minute: "numeric",
|
|
395
|
+
hour12: false,
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
return new Intl.DateTimeFormat("es-ES", options as any).format(now);
|
|
399
|
+
};
|
|
400
|
+
|
|
385
401
|
export const formatDateToDatePicker = (date: Date) => {
|
|
386
402
|
const year = date.getFullYear();
|
|
387
403
|
const month = `0${date.getMonth() + 1}`.slice(-2); // Los meses van de 0 a 11, así que le sumamos 1
|
|
@@ -630,3 +646,24 @@ export const parsedObject = (obj: any): any => {
|
|
|
630
646
|
return obj;
|
|
631
647
|
}
|
|
632
648
|
};
|
|
649
|
+
|
|
650
|
+
export function calculateTimeDifference(timestamp: string): {
|
|
651
|
+
hours: number;
|
|
652
|
+
minutes: number;
|
|
653
|
+
} {
|
|
654
|
+
const currentTime = moment();
|
|
655
|
+
const inputTime = moment(timestamp, "YYYY-MM-DD HH:mm:ss");
|
|
656
|
+
|
|
657
|
+
if (!inputTime.isValid()) {
|
|
658
|
+
throw new Error("Invalid timestamp format");
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const duration = moment.duration(currentTime.diff(inputTime));
|
|
662
|
+
const hours = Math.floor(duration.asHours());
|
|
663
|
+
const minutes = Math.floor(duration.asMinutes()) % 60;
|
|
664
|
+
|
|
665
|
+
return {
|
|
666
|
+
hours: hours,
|
|
667
|
+
minutes: minutes,
|
|
668
|
+
};
|
|
669
|
+
}
|